Support oauth2 scopes in Security annotation

This commit is contained in:
Paul des Garets 2021-01-26 19:05:27 +01:00
parent 306aba97a4
commit eeb0b4efba
4 changed files with 9 additions and 1 deletions

View File

@ -21,6 +21,7 @@ class Security extends AbstractAnnotation
/** {@inheritdoc} */ /** {@inheritdoc} */
public static $_types = [ public static $_types = [
'name' => 'string', 'name' => 'string',
'scopes' => '[string]',
]; ];
public static $_required = ['name']; public static $_required = ['name'];
@ -29,4 +30,9 @@ class Security extends AbstractAnnotation
* @var string * @var string
*/ */
public $name; public $name;
/**
* @var string[]
*/
public $scopes = [];
} }

View File

@ -102,7 +102,7 @@ final class OpenApiPhpDescriber
if ($annotation instanceof Security) { if ($annotation instanceof Security) {
$annotation->validate(); $annotation->validate();
$mergeProperties->security[] = [$annotation->name => []]; $mergeProperties->security[] = [$annotation->name => $annotation->scopes];
continue; continue;
} }

View File

@ -160,6 +160,7 @@ class ApiController
* @OA\Response(response="201", description="") * @OA\Response(response="201", description="")
* @Security(name="api_key") * @Security(name="api_key")
* @Security(name="basic") * @Security(name="basic")
* @Security(name="oauth2", scopes={"scope_1"})
*/ */
public function securityAction() public function securityAction()
{ {

View File

@ -338,6 +338,7 @@ class FunctionalTest extends WebTestCase
$expected = [ $expected = [
['api_key' => []], ['api_key' => []],
['basic' => []], ['basic' => []],
['oauth2' => ['scope_1']],
]; ];
$this->assertEquals($expected, $operation->security); $this->assertEquals($expected, $operation->security);
} }