Skip to content

Commit

Permalink
fix(symfony): fix swagger config to support Symfony ConfigBuilders (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
alexndlm committed Dec 27, 2022
1 parent 471185d commit 3a845f1
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 2 deletions.
22 changes: 22 additions & 0 deletions features/openapi/docs.feature
Expand Up @@ -16,6 +16,28 @@ Feature: Documentation support
And the JSON node "info.title" should be equal to "My Dummy API"
And the JSON node "info.description" should contain "This is a test API."
And the JSON node "info.description" should contain "Made with love"
# Security Schemes
And the JSON node "components.securitySchemes" should be equal to:
"""
{
"oauth": {
"type": "oauth2",
"description": "OAuth 2.0 implicit Grant",
"flows": {
"implicit": {
"authorizationUrl": "http://my-custom-server/openid-connect/auth",
"scopes": {}
}
}
},
"Some Authorization Name": {
"type": "apiKey",
"description": "Value for the Authorization header parameter.",
"name": "Authorization",
"in": "header"
}
}
"""
# Supported classes
And the OpenAPI class "AbstractDummy" exists
And the OpenAPI class "CircularReference" exists
Expand Down
2 changes: 2 additions & 0 deletions phpstan.neon.dist
Expand Up @@ -16,6 +16,8 @@ parameters:
- src/Symfony/Bundle/Test/Constraint/ArraySubset.php
- tests/Fixtures/app/AppKernel.php
excludePaths:
# Symfony config
- tests/Fixtures/app/config/config_swagger.php
# Symfony cache
- tests/Fixtures/app/var/
- tests/Fixtures/Symfony/Maker
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bundle/DependencyInjection/Configuration.php
Expand Up @@ -278,6 +278,7 @@ private function addSwaggerSection(ArrayNodeDefinition $rootNode): void
->prototype('scalar')->end()
->end()
->arrayNode('api_keys')
->useAttributeAsKey('key')
->prototype('array')
->children()
->scalarNode('name')
Expand Down
2 changes: 2 additions & 0 deletions tests/Fixtures/app/AppKernel.php
Expand Up @@ -238,6 +238,8 @@ class_exists(NativePasswordHasher::class) ? 'password_hashers' : 'encoders' => [
],
]);

$loader->load(__DIR__.'/config/config_swagger.php');

if ('mongodb' === $this->environment) {
$c->prependExtensionConfig('api_platform', [
'mapping' => [
Expand Down
22 changes: 22 additions & 0 deletions tests/Fixtures/app/config/config_swagger.php
@@ -0,0 +1,22 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Config\ApiPlatformConfig;

return static function (ApiPlatformConfig $apiPlatformConfig): void {
$apiPlatformConfig->swagger()->apiKeys('Some Authorization Name')
->name('Authorization')
->type('header');
};
Expand Up @@ -288,13 +288,13 @@ public function testApiKeysConfig(): void
$config = $this->processor->processConfiguration($this->configuration, [
'api_platform' => [
'swagger' => [
'api_keys' => [$exampleConfig],
'api_keys' => ['Some Authorization name, like JWT' => $exampleConfig],
],
],
]);

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

/**
Expand Down

0 comments on commit 3a845f1

Please sign in to comment.