Добрый день,
У меня есть проект API Symfony с FOSRestBundle и NelmioApiDocBundle .
Я не знаю, как добавить аннотацию безопасности с FOS Rest.
Я использую OAuth v2, поэтому моя безопасность основана на следующем:
apiKey: accessToken, refreshToken .
Это моя конфигурация пакета nelmio api в app / config :
nelmio_api_doc:
areas:
path_patterns: # an array of regexps
- ^/api/v1(?!/doc$)
documentation:
info:
title: Ads api documentation
description: Swagger api documentation
version: 1.0.0
securityDefinitions:
api_key:
type: apiKey
description: "Your Json Web Token, dont forget to preprend 'Bearer'"
name: Authorization
in: header
security:
api_key: []
И пример маршрута в одном из моих контроллеров:
/**
* @Rest\View(statusCode=200, serializerGroups={"rentAdList", "time"})
* @Rest\Get("", name="api_v1_user_ad_list")
*
* @SWG\Tag(name="user_ad")
* @SWG\Response(
* response=200,
* description="Display ad",
* @SWG\Schema(
* @Model(type=AdBundle\Entity\RentAd::class, groups={"rentAdList", "time"})
* )
* )
*
* @return RentAd[]
*/
public function listAction()
{
$user = $this->get('security.token_storage')->getToken()->getUser();
$rentAdDataProvider = $this->get('ad.data_provider.rent_ad_data_provider');
$rentAds = $rentAdDataProvider->getRentAdsByUser($user);
return $rentAds;
}
Поэтому мой вопрос заключается в том, как использовать аннотацию безопасности Swagger с api_key с ролью USER_ROLE
Я пытался добавить:
/**
* @Rest\View(statusCode=200, serializerGroups={"rentAdList", "time"})
* @Rest\Get("", name="api_v1_user_ad_list")
*
* @SWG\Tag(name="user_ad")
* @SWG\Response(
* response=200,
* description="Display ad",
* @SWG\Schema(
* @Model(type=AdBundle\Entity\RentAd::class, groups={"rentAdList", "time"})
* )
* )
* @SWG\SecurityScheme(name="apiKey")
*
* @return RentAd[]
*/
Булочка в этом случае у меня есть исключение:
Использование аннотации "Swagger \ Annotations \ SecurityScheme" в качестве корневой аннотации в "ApiBundle \ Controller \ Api \ V1 \ UserRentAdController :: listAction ()" не допускается.
Пожалуйста, помогите мне.