Skip to content

Commit

Permalink
chore: only support swagger.versions 3 in configuration (#4870)
Browse files Browse the repository at this point in the history
  • Loading branch information
alanpoulain authored Aug 4, 2022
1 parent 28f690e commit 7daef8e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 31 deletions.
14 changes: 0 additions & 14 deletions src/Symfony/Bundle/Command/OpenApiCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use ApiPlatform\OpenApi\Factory\OpenApiFactoryInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -52,19 +51,6 @@ protected function configure(): void
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
// Backwards compatibility
if (2 === $specVersion = (int) $input->getOption('spec-version')) {
$command = $this->getApplication()->find('api:swagger:export');

return $command->run(new ArrayInput([
'command' => 'api:swagger:export',
'--spec-version' => $specVersion,
'--yaml' => $input->getOption('yaml'),
'--output' => $input->getOption('output'),
'--api-gateway' => $input->getOption('api-gateway'),
]), $output);
}

$filesystem = new Filesystem();
$io = new SymfonyStyle($input, $output);
$data = $this->normalizer->normalize($this->openApiFactory->__invoke(), 'json');
Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,16 +248,16 @@ private function addGraphQlSection(ArrayNodeDefinition $rootNode): void

private function addSwaggerSection(ArrayNodeDefinition $rootNode): void
{
$defaultVersions = [2, 3];
$supportedVersions = [3];

$rootNode
->children()
->arrayNode('swagger')
->addDefaultsIfNotSet()
->children()
->arrayNode('versions')
->info('The active versions of Open API to be exported or used in the swagger_ui. The first value is the default.')
->defaultValue($defaultVersions)
->info('The active versions of OpenAPI to be exported or used in Swagger UI. The first value is the default.')
->defaultValue($supportedVersions)
->beforeNormalization()
->always(static function ($v): array {
if (!\is_array($v)) {
Expand All @@ -272,8 +272,8 @@ private function addSwaggerSection(ArrayNodeDefinition $rootNode): void
})
->end()
->validate()
->ifTrue(static fn($v): bool => $v !== array_intersect($v, $defaultVersions))
->thenInvalid(sprintf('Only the versions %s are supported. Got %s.', implode(' and ', $defaultVersions), '%s'))
->ifTrue(static fn($v): bool => $v !== array_intersect($v, $supportedVersions))
->thenInvalid(sprintf('Only the versions %s are supported. Got %s.', implode(' and ', $supportedVersions), '%s'))
->end()
->prototype('scalar')->end()
->end()
Expand Down
13 changes: 1 addition & 12 deletions tests/Symfony/Bundle/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private function runDefaultConfigTests(array $doctrineIntegrationsToLoad = ['orm
'pkce' => false,
],
'swagger' => [
'versions' => [2, 3],
'versions' => [3],
'api_keys' => [],
'swagger_ui_extra_configuration' => [],
],
Expand Down Expand Up @@ -330,17 +330,6 @@ public function testSwaggerVersionConfig(): void
$this->assertArrayHasKey('versions', $config['swagger']);
$this->assertEquals([3], $config['swagger']['versions']);

$config = $this->processor->processConfiguration($this->configuration, [
'api_platform' => [
'swagger' => [
'versions' => 2,
],
],
]);

$this->assertArrayHasKey('versions', $config['swagger']);
$this->assertEquals([2], $config['swagger']['versions']);

$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessageMatches('/Only the versions .+ are supported. Got .+./');

Expand Down

0 comments on commit 7daef8e

Please sign in to comment.