From eeb0b4efba1ee7d541891fdfbceccfb071647b28 Mon Sep 17 00:00:00 2001 From: Paul des Garets Date: Tue, 26 Jan 2021 19:05:27 +0100 Subject: [PATCH] Support oauth2 scopes in Security annotation --- Annotation/Security.php | 6 ++++++ Describer/OpenApiPhpDescriber.php | 2 +- Tests/Functional/Controller/ApiController.php | 1 + Tests/Functional/FunctionalTest.php | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Annotation/Security.php b/Annotation/Security.php index fad83bc..95bbc4b 100644 --- a/Annotation/Security.php +++ b/Annotation/Security.php @@ -21,6 +21,7 @@ class Security extends AbstractAnnotation /** {@inheritdoc} */ public static $_types = [ 'name' => 'string', + 'scopes' => '[string]', ]; public static $_required = ['name']; @@ -29,4 +30,9 @@ class Security extends AbstractAnnotation * @var string */ public $name; + + /** + * @var string[] + */ + public $scopes = []; } diff --git a/Describer/OpenApiPhpDescriber.php b/Describer/OpenApiPhpDescriber.php index 3cf0348..4f03918 100644 --- a/Describer/OpenApiPhpDescriber.php +++ b/Describer/OpenApiPhpDescriber.php @@ -102,7 +102,7 @@ final class OpenApiPhpDescriber if ($annotation instanceof Security) { $annotation->validate(); - $mergeProperties->security[] = [$annotation->name => []]; + $mergeProperties->security[] = [$annotation->name => $annotation->scopes]; continue; } diff --git a/Tests/Functional/Controller/ApiController.php b/Tests/Functional/Controller/ApiController.php index 4988efd..9018102 100644 --- a/Tests/Functional/Controller/ApiController.php +++ b/Tests/Functional/Controller/ApiController.php @@ -160,6 +160,7 @@ class ApiController * @OA\Response(response="201", description="") * @Security(name="api_key") * @Security(name="basic") + * @Security(name="oauth2", scopes={"scope_1"}) */ public function securityAction() { diff --git a/Tests/Functional/FunctionalTest.php b/Tests/Functional/FunctionalTest.php index 914a032..10ef30d 100644 --- a/Tests/Functional/FunctionalTest.php +++ b/Tests/Functional/FunctionalTest.php @@ -338,6 +338,7 @@ class FunctionalTest extends WebTestCase $expected = [ ['api_key' => []], ['basic' => []], + ['oauth2' => ['scope_1']], ]; $this->assertEquals($expected, $operation->security); }