Skip to content

Commit 3a845f1

Browse files
authored
fix(symfony): fix swagger config to support Symfony ConfigBuilders (#4691)
* - add attribute as key * -update CHANGELOG.md * -fix tests * -update test * -add Behat tests * -fix CI * -update changelog * -fix MongoDB Behat tests * -rollback changelog
1 parent 471185d commit 3a845f1

File tree

6 files changed

+51
-2
lines changed

6 files changed

+51
-2
lines changed

features/openapi/docs.feature

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,28 @@ Feature: Documentation support
1616
And the JSON node "info.title" should be equal to "My Dummy API"
1717
And the JSON node "info.description" should contain "This is a test API."
1818
And the JSON node "info.description" should contain "Made with love"
19+
# Security Schemes
20+
And the JSON node "components.securitySchemes" should be equal to:
21+
"""
22+
{
23+
"oauth": {
24+
"type": "oauth2",
25+
"description": "OAuth 2.0 implicit Grant",
26+
"flows": {
27+
"implicit": {
28+
"authorizationUrl": "http://my-custom-server/openid-connect/auth",
29+
"scopes": {}
30+
}
31+
}
32+
},
33+
"Some Authorization Name": {
34+
"type": "apiKey",
35+
"description": "Value for the Authorization header parameter.",
36+
"name": "Authorization",
37+
"in": "header"
38+
}
39+
}
40+
"""
1941
# Supported classes
2042
And the OpenAPI class "AbstractDummy" exists
2143
And the OpenAPI class "CircularReference" exists

phpstan.neon.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ parameters:
1616
- src/Symfony/Bundle/Test/Constraint/ArraySubset.php
1717
- tests/Fixtures/app/AppKernel.php
1818
excludePaths:
19+
# Symfony config
20+
- tests/Fixtures/app/config/config_swagger.php
1921
# Symfony cache
2022
- tests/Fixtures/app/var/
2123
- tests/Fixtures/Symfony/Maker

src/Symfony/Bundle/DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ private function addSwaggerSection(ArrayNodeDefinition $rootNode): void
278278
->prototype('scalar')->end()
279279
->end()
280280
->arrayNode('api_keys')
281+
->useAttributeAsKey('key')
281282
->prototype('array')
282283
->children()
283284
->scalarNode('name')

tests/Fixtures/app/AppKernel.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ class_exists(NativePasswordHasher::class) ? 'password_hashers' : 'encoders' => [
238238
],
239239
]);
240240

241+
$loader->load(__DIR__.'/config/config_swagger.php');
242+
241243
if ('mongodb' === $this->environment) {
242244
$c->prependExtensionConfig('api_platform', [
243245
'mapping' => [
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
15+
16+
use Symfony\Config\ApiPlatformConfig;
17+
18+
return static function (ApiPlatformConfig $apiPlatformConfig): void {
19+
$apiPlatformConfig->swagger()->apiKeys('Some Authorization Name')
20+
->name('Authorization')
21+
->type('header');
22+
};

tests/Symfony/Bundle/DependencyInjection/ConfigurationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,13 @@ public function testApiKeysConfig(): void
288288
$config = $this->processor->processConfiguration($this->configuration, [
289289
'api_platform' => [
290290
'swagger' => [
291-
'api_keys' => [$exampleConfig],
291+
'api_keys' => ['Some Authorization name, like JWT' => $exampleConfig],
292292
],
293293
],
294294
]);
295295

296296
$this->assertArrayHasKey('api_keys', $config['swagger']);
297-
$this->assertSame($exampleConfig, $config['swagger']['api_keys'][0]);
297+
$this->assertSame($exampleConfig, $config['swagger']['api_keys']['Some Authorization name, like JWT']);
298298
}
299299

300300
/**

0 commit comments

Comments
 (0)