Skip to content

Commit 24fa80c

Browse files
authored
Merge pull request #3333 from Jibbarth/fix/oauth-security-definition-openapi
[OpenApi] [Oauth] Fix render oauth when using OpenApi v3
2 parents 14ed547 + 8dccfa3 commit 24fa80c

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

src/Swagger/Serializer/DocumentationNormalizer.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -631,15 +631,29 @@ private function computeDoc(bool $v3, Documentation $documentation, \ArrayObject
631631
$security = [];
632632

633633
if ($this->oauthEnabled) {
634-
$securityDefinitions['oauth'] = [
635-
'type' => $this->oauthType,
636-
'description' => 'OAuth client_credentials Grant',
637-
'flow' => $this->oauthFlow,
634+
$oauthAttributes = [
638635
'tokenUrl' => $this->oauthTokenUrl,
639636
'authorizationUrl' => $this->oauthAuthorizationUrl,
640637
'scopes' => $this->oauthScopes,
641638
];
642639

640+
$securityDefinitions['oauth'] = [
641+
'type' => $this->oauthType,
642+
'description' => sprintf(
643+
'OAuth 2.0 %s Grant',
644+
strtolower(preg_replace('/[A-Z]/', ' \\0', lcfirst($this->oauthFlow)))
645+
),
646+
];
647+
648+
if ($v3) {
649+
$securityDefinitions['oauth']['flows'] = [
650+
$this->oauthFlow => $oauthAttributes,
651+
];
652+
} else {
653+
$securityDefinitions['oauth']['flow'] = $this->oauthFlow;
654+
$securityDefinitions['oauth'] = array_merge($securityDefinitions['oauth'], $oauthAttributes);
655+
}
656+
643657
$security[] = ['oauth' => []];
644658
}
645659

tests/Swagger/Serializer/DocumentationNormalizerV2Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ interface_exists(AdvancedNameConverterInterface::class)
492492
'securityDefinitions' => [
493493
'oauth' => [
494494
'type' => 'oauth2',
495-
'description' => 'OAuth client_credentials Grant',
495+
'description' => 'OAuth 2.0 application Grant',
496496
'flow' => 'application',
497497
'tokenUrl' => '/oauth/v2/token',
498498
'authorizationUrl' => '/oauth/v2/auth',

tests/Swagger/Serializer/DocumentationNormalizerV3Test.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ private function doTestNormalizeWithNameConverter(bool $legacy = false): void
483483
$legacy ? $nameConverter : null,
484484
true,
485485
'oauth2',
486-
'application',
486+
'authorizationCode',
487487
'/oauth/v2/token',
488488
'/oauth/v2/auth',
489489
['scope param'],
@@ -554,11 +554,14 @@ private function doTestNormalizeWithNameConverter(bool $legacy = false): void
554554
'securitySchemes' => [
555555
'oauth' => [
556556
'type' => 'oauth2',
557-
'description' => 'OAuth client_credentials Grant',
558-
'flow' => 'application',
559-
'tokenUrl' => '/oauth/v2/token',
560-
'authorizationUrl' => '/oauth/v2/auth',
561-
'scopes' => ['scope param'],
557+
'description' => 'OAuth 2.0 authorization code Grant',
558+
'flows' => [
559+
'authorizationCode' => [
560+
'tokenUrl' => '/oauth/v2/token',
561+
'authorizationUrl' => '/oauth/v2/auth',
562+
'scopes' => ['scope param'],
563+
],
564+
],
562565
],
563566
],
564567
],

0 commit comments

Comments
 (0)