現在認証されているユーザーについての情報(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;
}
}
ドキュメンテーション?
時々リンクが壊れて変わり、答えは不完全になり、ここでのリンクの重要な部分を表示します – calexandre