Skip to content

Commit

Permalink
fix(openapi): deprecate api_keys names not compatible with 3.1 (#5490)
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Mar 23, 2023
1 parent 2be8b4f commit 4c87a97
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion features/openapi/docs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Feature: Documentation support
}
}
},
"Some Authorization Name": {
"Some_Authorization_Name": {
"type": "apiKey",
"description": "Value for the Authorization header parameter.",
"name": "Authorization",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,12 @@ private function registerOAuthConfiguration(ContainerBuilder $container, array $
*/
private function registerSwaggerConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void
{
foreach (array_keys($config['swagger']['api_keys']) as $keyName) {
if (!preg_match('/^[a-zA-Z0-9._-]+$/', $keyName)) {
trigger_deprecation('api-platform/core', '3.1', sprintf('The swagger api_keys key "%s" is not valid with OpenAPI 3.1 it should match "^[a-zA-Z0-9._-]+$"', $keyName));
}
}

$container->setParameter('api_platform.swagger.versions', $config['swagger']['versions']);

if (!$config['enable_swagger'] && $config['enable_swagger_ui']) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/app/config/config_swagger.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Symfony\Config\ApiPlatformConfig;

return static function (ApiPlatformConfig $apiPlatformConfig): void {
$apiPlatformConfig->swagger()->apiKeys('Some Authorization Name')
$apiPlatformConfig->swagger()->apiKeys('Some_Authorization_Name')
->name('Authorization')
->type('header');
};
Original file line number Diff line number Diff line change
Expand Up @@ -1247,4 +1247,16 @@ public function testHttpCacheBanConfiguration(): void
$this->assertCount(1, $service->getArguments());
$this->assertEquals('api_platform.http_cache.http_client', $service->getArgument(0)->getTag());
}

/**
* @group legacy
*/
public function testLegacyOpenApiApiKeysConfiguration(): void
{
$this->expectDeprecation('Since api-platform/core 3.1: The swagger api_keys key "Some Authorization Name" is not valid with OpenAPI 3.1 it should match "^[a-zA-Z0-9._-]+$"');
$config = self::DEFAULT_CONFIG;
$config['api_platform']['swagger']['api_keys']['Some Authorization Name'] = ['name' => 'a', 'type' => 'header'];

(new ApiPlatformExtension())->load($config, $this->container);
}
}

0 comments on commit 4c87a97

Please sign in to comment.