2017-07-05 15 views
1

現在認証されているユーザーについての情報(Userオブジェクト)を返す/api/v1/meのようなエンティティエンドポイントとマッピングされていないものを作成し、それをドキュメントに追加したいとします。計画では、/api/v1/account/recover/api/v1/account/verify-emailのようなエンドポイントも追加したいと考えています。APIプラットフォームでカスタムエンドポイントを作成してドキュメントに追加するにはどうすればよいですか?

私はアクションがあります。

namespace AppBundle\Action\Me; 

use AppBundle\Entity\User; 
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; 
use Symfony\Component\Routing\Annotation\Route; 
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; 

class MeView 
{ 

    /** 
    * @var TokenStorageInterface 
    */ 
    private $tokenStorage; 

    public function __construct(TokenStorageInterface $tokenStorage) 
    { 
     $this->tokenStorage = $tokenStorage; 
    } 

    /** 
    * @Security("is_authenticated()") 
    * 
    * @Route(
    *  name="me_view", 
    *  path="/me", 
    *  methods={"GET"} 
    *) 
    * 
    * @return User 
    */ 
    public function __invoke() 
    { 
     return $this->tokenStorage->getToken()->getUser(); 
    } 
} 

をしかし、私はそれにアクセスしようとすると、それは例外を返します:

応答を(返す必要があり、コントローラオブジェクト(AppBundle \エンティティ\ユーザー)与えられた)。 (500内部サーバーエラー)

同じアクションが、エンティティにマッピングされたが、うまく機能:私は私のカスタムアクションを機能させるために行う必要がありますし、自動生成闊歩に追加する方法を何

namespace AppBundle\Action\City; 

use AppBundle\Entity\City; 
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; 
use Symfony\Component\Routing\Annotation\Route; 

class CityView 
{ 

    /** 
    * @Security("is_authenticated()") 
    * 
    * @Route(
    *  name="city_view", 
    *  path="/cities/{id}", 
    *  methods={"GET"}, 
    *  defaults={"_api_resource_class"=City::class, "_api_item_operation_name"="view"} 
    *) 
    * 
    * @param City $city 
    * @return City 
    */ 
    public function __invoke(City $city) 
    { 
     return $city; 
    } 
} 

ドキュメンテーション?

答えて

関連する問題