From aea39e6aa7555666f4068bcd628675afee34a77a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20H=C3=A9bert?= Date: Mon, 19 Aug 2019 20:20:24 +0200 Subject: [PATCH 01/13] Add swagger version configuration option --- .../DependencyInjection/Configuration.php | 38 ++++++++++-- .../DependencyInjection/ConfigurationTest.php | 60 +++++++++++++++++++ 2 files changed, 93 insertions(+), 5 deletions(-) diff --git a/src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php b/src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php index abd29df5635..a6704a0b94b 100644 --- a/src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php +++ b/src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php @@ -56,6 +56,16 @@ public function getConfigTreeBuilder() } $rootNode + ->beforeNormalization() + ->ifTrue(static function ($v) { + return isset($v['enable_swagger']) && false === $v['enable_swagger']; + }) + ->then(static function ($v){ + $v['swagger']['versions'] = []; + + return $v; + }) + ->end() ->children() ->scalarNode('title') ->info('The title of the API.') @@ -102,7 +112,11 @@ public function getConfigTreeBuilder() ->setDeprecated('Enabling the NelmioApiDocBundle integration has been deprecated in 2.2 and will be removed in 3.0. NelmioApiDocBundle 3 has native support for API Platform.') ->info('Enable the NelmioApiDocBundle integration.') ->end() - ->booleanNode('enable_swagger')->defaultTrue()->info('Enable the Swagger documentation and export.')->end() + ->booleanNode('enable_swagger') + ->defaultTrue() + ->setDeprecated('The use of `enable_swagger` has been deprecated in 2.5 and will be removed in 3.0. use `api_platform.swagger.versions` instead.') + ->info('Enable the Swagger documentation and export.') + ->end() ->booleanNode('enable_swagger_ui')->defaultValue(class_exists(TwigBundle::class))->info('Enable Swagger UI')->end() ->booleanNode('enable_re_doc')->defaultValue(class_exists(TwigBundle::class))->info('Enable ReDoc')->end() ->booleanNode('enable_entrypoint')->defaultTrue()->info('Enable the entrypoint')->end() @@ -236,14 +250,28 @@ private function addGraphQlSection(ArrayNodeDefinition $rootNode): void private function addSwaggerSection(ArrayNodeDefinition $rootNode): void { + $defaultVersions = ['2.0.0', '3.0.2']; + $rootNode ->children() ->arrayNode('swagger') ->addDefaultsIfNotSet() ->children() - ->arrayNode('api_keys') - ->prototype('array') - ->children() + ->arrayNode('versions') + ->info('The active versions of OpenAPI to be exported or used in the swagger_ui') + ->defaultValue($defaultVersions) + ->beforeNormalization()->castToArray()->end() + ->validate() + ->ifTrue(function($v) use ($defaultVersions) { + return $v !== array_intersect($v, $defaultVersions); + }) + ->thenInvalid(sprintf('Only the versions %s are supported. Got %s.', implode(' and ', $defaultVersions), '%s')) + ->end() + ->prototype('scalar')->end() + ->end() + ->arrayNode('api_keys') + ->prototype('array') + ->children() ->scalarNode('name') ->info('The name of the header or query parameter containing the api key.') ->end() @@ -252,7 +280,7 @@ private function addSwaggerSection(ArrayNodeDefinition $rootNode): void ->values(['query', 'header']) ->end() ->end() - ->end() + ->end() ->end() ->end() ->end() diff --git a/tests/Bridge/Symfony/Bundle/DependencyInjection/ConfigurationTest.php b/tests/Bridge/Symfony/Bundle/DependencyInjection/ConfigurationTest.php index ad64920e01f..e0dc34a870d 100644 --- a/tests/Bridge/Symfony/Bundle/DependencyInjection/ConfigurationTest.php +++ b/tests/Bridge/Symfony/Bundle/DependencyInjection/ConfigurationTest.php @@ -141,6 +141,7 @@ private function runDefaultConfigTests(array $doctrineIntegrationsToLoad = ['orm 'scopes' => [], ], 'swagger' => [ + 'versions' => ['2.0.0', '3.0.2'], 'api_keys' => [], ], 'eager_loading' => [ @@ -315,6 +316,65 @@ public function testApiKeysConfig() $this->assertSame($exampleConfig, $config['swagger']['api_keys'][0]); } + /** + * Test config for disabled swagger versions. + * @group legacy + * @expectedDeprecation The use of `enable_swagger` has been deprecated in 2.5 and will be removed in 3.0. use `api_platform.swagger.versions` instead. + */ + public function testDisabledSwaggerVersionConfig() + { + $config = $this->processor->processConfiguration($this->configuration, [ + 'api_platform' => [ + 'enable_swagger' => false, + 'swagger' => [ + 'versions' => ['3.0.2'], + ], + ], + ]); + + $this->assertTrue(isset($config['swagger']['versions'])); + $this->assertSame([], $config['swagger']['versions']); + } + + /** + * Test config for swagger versions. + */ + public function testSwaggerVersionConfig() + { + $config = $this->processor->processConfiguration($this->configuration, [ + 'api_platform' => [ + 'swagger' => [ + 'versions' => ['3.0.2'], + ], + ], + ]); + + $this->assertTrue(isset($config['swagger']['versions'])); + $this->assertSame(['3.0.2'], $config['swagger']['versions']); + + $config = $this->processor->processConfiguration($this->configuration, [ + 'api_platform' => [ + 'swagger' => [ + 'versions' => '2.0.0', + ], + ], + ]); + + $this->assertTrue(isset($config['swagger']['versions'])); + $this->assertSame(['2.0.0'], $config['swagger']['versions']); + + $this->expectException(InvalidConfigurationException::class); + $this->expectExceptionMessageRegExp('/Only the versions .+ are supported. Got .+./'); + + $this->processor->processConfiguration($this->configuration, [ + 'api_platform' => [ + 'swagger' => [ + 'versions' => ['1.0.0'], + ], + ], + ]); + } + /** * Test config for empty title and description. */ From 83509ed2d62df23fef8b7453842bdac56fd35e81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20H=C3=A9bert?= Date: Mon, 19 Aug 2019 20:33:47 +0200 Subject: [PATCH 02/13] deprecate enable_swagger option in favour of swagger.versions option --- .../Bundle/DependencyInjection/ApiPlatformExtension.php | 5 +++++ .../Bundle/DependencyInjection/ApiPlatformExtensionTest.php | 1 + 2 files changed, 6 insertions(+) diff --git a/src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php b/src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php index 6f73c4cb259..238ccca99a7 100644 --- a/src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php +++ b/src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php @@ -308,6 +308,10 @@ private function registerOAuthConfiguration(ContainerBuilder $container, array $ private function registerSwaggerConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void { if (!$config['enable_swagger']) { + @trigger_error('The "api_platform.enable_swagger" parameter is deprecated since version 2.5 and will have no effect in 3.0. Please use "api_platform.swagger.versions" instead.', E_USER_DEPRECATED); + } + + if (empty($config['swagger']['versions'])) { return; } @@ -321,6 +325,7 @@ private function registerSwaggerConfiguration(ContainerBuilder $container, array } $container->setParameter('api_platform.enable_swagger', $config['enable_swagger']); + $container->setParameter('api_platform.swagger.versions', $config['swagger']['versions']); $container->setParameter('api_platform.swagger.api_keys', $config['swagger']['api_keys']); } diff --git a/tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php b/tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php index 6a579d1278f..4827bc114b7 100644 --- a/tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php +++ b/tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php @@ -1058,6 +1058,7 @@ private function getBaseContainerBuilderProphecy(array $doctrineIntegrationsToLo 'api_platform.oauth.tokenUrl' => '/oauth/v2/token', 'api_platform.oauth.authorizationUrl' => '/oauth/v2/auth', 'api_platform.oauth.scopes' => [], + 'api_platform.swagger.versions' => ['2.0.0', '3.0.2'], 'api_platform.swagger.api_keys' => [], 'api_platform.enable_swagger' => true, 'api_platform.enable_swagger_ui' => true, From 65c120c820ff9e7123b39d72d37fde893e96a927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20H=C3=A9bert?= Date: Mon, 19 Aug 2019 21:47:54 +0200 Subject: [PATCH 03/13] use first swagger version defined as default --- .../Symfony/Bundle/Action/SwaggerUiAction.php | 5 +++-- .../Symfony/Bundle/Command/SwaggerCommand.php | 12 +++++++----- .../DependencyInjection/ApiPlatformExtension.php | 1 - .../Bundle/DependencyInjection/Configuration.php | 4 ++-- src/Bridge/Symfony/Bundle/Resources/config/api.xml | 2 ++ .../Symfony/Bundle/Resources/config/swagger-ui.xml | 1 + .../Symfony/Bundle/Resources/config/swagger.xml | 3 +++ src/Documentation/Action/DocumentationAction.php | 7 ++++--- src/Swagger/Serializer/DocumentationNormalizer.php | 5 +++-- .../ApiPlatformExtensionTest.php | 8 +------- .../DependencyInjection/ConfigurationTest.php | 14 +++++++------- tests/Bridge/Symfony/Routing/ApiLoaderTest.php | 1 - 12 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php b/src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php index f81af1db165..afb1511c7ec 100644 --- a/src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php +++ b/src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php @@ -57,7 +57,7 @@ final class SwaggerUiAction private $graphiQlEnabled; private $graphQlPlaygroundEnabled; - public function __construct(ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, ResourceMetadataFactoryInterface $resourceMetadataFactory, NormalizerInterface $normalizer, TwigEnvironment $twig, UrlGeneratorInterface $urlGenerator, string $title = '', string $description = '', string $version = '', $formats = [], $oauthEnabled = false, $oauthClientId = '', $oauthClientSecret = '', $oauthType = '', $oauthFlow = '', $oauthTokenUrl = '', $oauthAuthorizationUrl = '', $oauthScopes = [], bool $showWebby = true, bool $swaggerUiEnabled = false, bool $reDocEnabled = false, bool $graphqlEnabled = false, bool $graphiQlEnabled = false, bool $graphQlPlaygroundEnabled = false) + public function __construct(ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, ResourceMetadataFactoryInterface $resourceMetadataFactory, NormalizerInterface $normalizer, TwigEnvironment $twig, UrlGeneratorInterface $urlGenerator, string $title = '', string $description = '', string $version = '', $formats = [], $oauthEnabled = false, $oauthClientId = '', $oauthClientSecret = '', $oauthType = '', $oauthFlow = '', $oauthTokenUrl = '', $oauthAuthorizationUrl = '', $oauthScopes = [], bool $showWebby = true, bool $swaggerUiEnabled = false, bool $reDocEnabled = false, bool $graphqlEnabled = false, bool $graphiQlEnabled = false, bool $graphQlPlaygroundEnabled = false, array $swaggerVersions = []) { $this->resourceNameCollectionFactory = $resourceNameCollectionFactory; $this->resourceMetadataFactory = $resourceMetadataFactory; @@ -81,6 +81,7 @@ public function __construct(ResourceNameCollectionFactoryInterface $resourceName $this->graphqlEnabled = $graphqlEnabled; $this->graphiQlEnabled = $graphiQlEnabled; $this->graphQlPlaygroundEnabled = $graphQlPlaygroundEnabled; + $this->swaggerVersions = $swaggerVersions; if (\is_array($formats)) { $this->formats = $formats; @@ -127,7 +128,7 @@ private function getContext(Request $request, Documentation $documentation): arr 'graphQlPlaygroundEnabled' => $this->graphQlPlaygroundEnabled, ]; - $swaggerContext = ['spec_version' => $request->query->getInt('spec_version', 2)]; + $swaggerContext = ['spec_version' => $request->query->getInt('spec_version', (int)($this->swaggerVersions[0] ?? 2))]; if ('' !== $baseUrl = $request->getBaseUrl()) { $swaggerContext['base_url'] = $baseUrl; } diff --git a/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php b/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php index 9bc2fe2143d..16403faf711 100644 --- a/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php +++ b/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php @@ -39,8 +39,9 @@ final class SwaggerCommand extends Command private $apiDescription; private $apiVersion; private $apiFormats; + private $swaggerVersions; - public function __construct(NormalizerInterface $normalizer, ResourceNameCollectionFactoryInterface $resourceNameCollection, string $apiTitle, string $apiDescription, string $apiVersion, array $apiFormats = null) + public function __construct(NormalizerInterface $normalizer, ResourceNameCollectionFactoryInterface $resourceNameCollection, string $apiTitle, string $apiDescription, string $apiVersion, array $apiFormats = null, array $swaggerVersions = []) { $this->normalizer = $normalizer; $this->resourceNameCollectionFactory = $resourceNameCollection; @@ -48,6 +49,7 @@ public function __construct(NormalizerInterface $normalizer, ResourceNameCollect $this->apiDescription = $apiDescription; $this->apiVersion = $apiVersion; $this->apiFormats = $apiFormats; + $this->swaggerVersions = $swaggerVersions; if (null !== $apiFormats) { @trigger_error(sprintf('Passing a 6th parameter to the constructor of "%s" is deprecated since API Platform 2.5', __CLASS__), E_USER_DEPRECATED); @@ -66,7 +68,7 @@ protected function configure() ->setAliases(['api:swagger:export']) ->setDescription('Dump the OpenAPI documentation') ->addOption('yaml', 'y', InputOption::VALUE_NONE, 'Dump the documentation in YAML') - ->addOption('spec-version', null, InputOption::VALUE_OPTIONAL, 'OpenAPI version to use ("2" or "3")', '2') + ->addOption('spec-version', null, InputOption::VALUE_OPTIONAL, sprintf('OpenAPI version to use (%s)', implode(' or ', $this->swaggerVersions)), $this->swaggerVersions[0] ?? '2') ->addOption('output', 'o', InputOption::VALUE_OPTIONAL, 'Write output to file') ->addOption('api-gateway', null, InputOption::VALUE_NONE, 'API Gateway compatibility'); } @@ -78,10 +80,10 @@ protected function execute(InputInterface $input, OutputInterface $output) { $io = new SymfonyStyle($input, $output); /** @var string $version */ - $version = $input->getOption('spec-version'); + $version = $input->getOption('spec-version')[0]; - if (!\in_array($version, ['2', '3'], true)) { - throw new InvalidOptionException(sprintf('This tool only supports version 2 and 3 of the OpenAPI specification ("%s" given).', $version)); + if (!\in_array($version, $this->swaggerVersions, true)) { + throw new InvalidOptionException(sprintf('This tool only supports version %s of the OpenAPI specification ("%s" given).', implode(', ', $this->swaggerVersions), $version)); } $documentation = new Documentation($this->resourceNameCollectionFactory->create(), $this->apiTitle, $this->apiDescription, $this->apiVersion, $this->apiFormats); diff --git a/src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php b/src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php index 238ccca99a7..0f409fe8410 100644 --- a/src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php +++ b/src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php @@ -324,7 +324,6 @@ private function registerSwaggerConfiguration(ContainerBuilder $container, array $container->setParameter('api_platform.enable_re_doc', $config['enable_re_doc']); } - $container->setParameter('api_platform.enable_swagger', $config['enable_swagger']); $container->setParameter('api_platform.swagger.versions', $config['swagger']['versions']); $container->setParameter('api_platform.swagger.api_keys', $config['swagger']['api_keys']); } diff --git a/src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php b/src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php index a6704a0b94b..575bfc03d52 100644 --- a/src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php +++ b/src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php @@ -250,7 +250,7 @@ private function addGraphQlSection(ArrayNodeDefinition $rootNode): void private function addSwaggerSection(ArrayNodeDefinition $rootNode): void { - $defaultVersions = ['2.0.0', '3.0.2']; + $defaultVersions = ['2', '3']; $rootNode ->children() @@ -258,7 +258,7 @@ private function addSwaggerSection(ArrayNodeDefinition $rootNode): void ->addDefaultsIfNotSet() ->children() ->arrayNode('versions') - ->info('The active versions of OpenAPI to be exported or used in the swagger_ui') + ->info('The active versions of OpenAPI to be exported or used in the swagger_ui. The first value is the default.') ->defaultValue($defaultVersions) ->beforeNormalization()->castToArray()->end() ->validate() diff --git a/src/Bridge/Symfony/Bundle/Resources/config/api.xml b/src/Bridge/Symfony/Bundle/Resources/config/api.xml index c951bfb6176..31356a4b837 100644 --- a/src/Bridge/Symfony/Bundle/Resources/config/api.xml +++ b/src/Bridge/Symfony/Bundle/Resources/config/api.xml @@ -240,6 +240,8 @@ %api_platform.title% %api_platform.description% %api_platform.version% + null + %api_platform.swagger.versions% diff --git a/src/Bridge/Symfony/Bundle/Resources/config/swagger-ui.xml b/src/Bridge/Symfony/Bundle/Resources/config/swagger-ui.xml index 17a7b18c496..2bcb783853c 100644 --- a/src/Bridge/Symfony/Bundle/Resources/config/swagger-ui.xml +++ b/src/Bridge/Symfony/Bundle/Resources/config/swagger-ui.xml @@ -34,6 +34,7 @@ %api_platform.graphql.enabled% %api_platform.graphql.graphiql.enabled% %api_platform.graphql.graphql_playground.enabled% + %api_platform.swagger.versions% diff --git a/src/Bridge/Symfony/Bundle/Resources/config/swagger.xml b/src/Bridge/Symfony/Bundle/Resources/config/swagger.xml index 1943068d449..5289d8d2a29 100644 --- a/src/Bridge/Symfony/Bundle/Resources/config/swagger.xml +++ b/src/Bridge/Symfony/Bundle/Resources/config/swagger.xml @@ -31,6 +31,7 @@ %api_platform.formats% %api_platform.collection.pagination.client_enabled% %api_platform.collection.pagination.enabled_parameter_name% + %api_platform.swagger.versions% @@ -45,6 +46,8 @@ %api_platform.title% %api_platform.description% %api_platform.version% + null + %api_platform.swagger.versions% diff --git a/src/Documentation/Action/DocumentationAction.php b/src/Documentation/Action/DocumentationAction.php index 9b6a91180d1..e001296b037 100644 --- a/src/Documentation/Action/DocumentationAction.php +++ b/src/Documentation/Action/DocumentationAction.php @@ -32,14 +32,15 @@ final class DocumentationAction private $version; private $formats; private $formatsProvider; - private $resourceMetadataFactory; + private $swaggerVersions; - public function __construct(ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, string $title = '', string $description = '', string $version = '', $formatsProvider = null) + public function __construct(ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, string $title = '', string $description = '', string $version = '', $formatsProvider = null, array $swaggerVersions = []) { $this->resourceNameCollectionFactory = $resourceNameCollectionFactory; $this->title = $title; $this->description = $description; $this->version = $version; + $this->swaggerVersions = $swaggerVersions; if (null === $formatsProvider) { return; @@ -57,7 +58,7 @@ public function __construct(ResourceNameCollectionFactoryInterface $resourceName public function __invoke(Request $request = null): Documentation { if (null !== $request) { - $context = ['base_url' => $request->getBaseUrl(), 'spec_version' => $request->query->getInt('spec_version', 2)]; + $context = ['base_url' => $request->getBaseUrl(), 'spec_version' => $request->query->getInt('spec_version', (int)($this->swaggerVersions[0] ?? 2))]; if ($request->query->getBoolean('api_gateway')) { $context['api_gateway'] = true; } diff --git a/src/Swagger/Serializer/DocumentationNormalizer.php b/src/Swagger/Serializer/DocumentationNormalizer.php index 29adb4007b8..d77795d9658 100644 --- a/src/Swagger/Serializer/DocumentationNormalizer.php +++ b/src/Swagger/Serializer/DocumentationNormalizer.php @@ -95,7 +95,6 @@ final class DocumentationNormalizer implements NormalizerInterface, CacheableSup private $jsonSchemaTypeFactory; private $defaultContext = [ self::BASE_URL => '/', - self::SPEC_VERSION => 2, ApiGatewayNormalizer::API_GATEWAY => false, ]; @@ -105,7 +104,7 @@ final class DocumentationNormalizer implements NormalizerInterface, CacheableSup * @param array|OperationAwareFormatsProviderInterface $formats * @param mixed|null $jsonSchemaTypeFactory */ - public function __construct(ResourceMetadataFactoryInterface $resourceMetadataFactory, PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, PropertyMetadataFactoryInterface $propertyMetadataFactory, $jsonSchemaFactory = null, $jsonSchemaTypeFactory = null, OperationPathResolverInterface $operationPathResolver, UrlGeneratorInterface $urlGenerator = null, $filterLocator = null, NameConverterInterface $nameConverter = null, bool $oauthEnabled = false, string $oauthType = '', string $oauthFlow = '', string $oauthTokenUrl = '', string $oauthAuthorizationUrl = '', array $oauthScopes = [], array $apiKeys = [], SubresourceOperationFactoryInterface $subresourceOperationFactory = null, bool $paginationEnabled = true, string $paginationPageParameterName = 'page', bool $clientItemsPerPage = false, string $itemsPerPageParameterName = 'itemsPerPage', $formats = [], bool $paginationClientEnabled = false, string $paginationClientEnabledParameterName = 'pagination', array $defaultContext = []) + public function __construct(ResourceMetadataFactoryInterface $resourceMetadataFactory, PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, PropertyMetadataFactoryInterface $propertyMetadataFactory, $jsonSchemaFactory = null, $jsonSchemaTypeFactory = null, OperationPathResolverInterface $operationPathResolver, UrlGeneratorInterface $urlGenerator = null, $filterLocator = null, NameConverterInterface $nameConverter = null, bool $oauthEnabled = false, string $oauthType = '', string $oauthFlow = '', string $oauthTokenUrl = '', string $oauthAuthorizationUrl = '', array $oauthScopes = [], array $apiKeys = [], SubresourceOperationFactoryInterface $subresourceOperationFactory = null, bool $paginationEnabled = true, string $paginationPageParameterName = 'page', bool $clientItemsPerPage = false, string $itemsPerPageParameterName = 'itemsPerPage', $formats = [], bool $paginationClientEnabled = false, string $paginationClientEnabledParameterName = 'pagination', array $defaultContext = [], array $versions = []) { if ($jsonSchemaTypeFactory instanceof OperationMethodResolverInterface) { @trigger_error(sprintf('Passing an instance of %s to %s() is deprecated since version 2.5 and will be removed in 3.0.', OperationMethodResolverInterface::class, __METHOD__), E_USER_DEPRECATED); @@ -163,6 +162,8 @@ public function __construct(ResourceMetadataFactoryInterface $resourceMetadataFa $this->paginationClientEnabled = $paginationClientEnabled; $this->paginationClientEnabledParameterName = $paginationClientEnabledParameterName; + $this->defaultContext[self::SPEC_VERSION] = (int) ($versions[0] ?? '2'); + $this->defaultContext = array_merge($this->defaultContext, $defaultContext); } diff --git a/tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php b/tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php index 4827bc114b7..833940e97b6 100644 --- a/tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php +++ b/tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php @@ -199,7 +199,6 @@ public function testPrepend() public function testLoadDefaultConfig() { $containerBuilderProphecy = $this->getBaseContainerBuilderProphecy(); - $containerBuilderProphecy->setParameter('api_platform.enable_swagger', '1')->shouldBeCalled(); $containerBuilderProphecy->hasParameter('kernel.debug')->willReturn(true); $containerBuilderProphecy->getParameter('kernel.debug')->willReturn(false); $containerBuilder = $containerBuilderProphecy->reveal(); @@ -213,7 +212,6 @@ public function testLoadDefaultConfig() public function testLoadDefaultConfigWithOdm() { $containerBuilderProphecy = $this->getBaseContainerBuilderProphecy(['odm']); - $containerBuilderProphecy->setParameter('api_platform.enable_swagger', '1')->shouldBeCalled(); $containerBuilderProphecy->hasParameter('kernel.debug')->willReturn(true); $containerBuilderProphecy->getParameter('kernel.debug')->willReturn(false); $containerBuilder = $containerBuilderProphecy->reveal(); @@ -232,7 +230,6 @@ public function testSetNameConverter() $containerBuilderProphecy->hasParameter('kernel.debug')->willReturn(true); $containerBuilderProphecy->getParameter('kernel.debug')->willReturn(false); $containerBuilderProphecy->setAlias('api_platform.name_converter', $nameConverterId)->shouldBeCalled(); - $containerBuilderProphecy->setParameter('api_platform.enable_swagger', '1')->shouldBeCalled(); $containerBuilder = $containerBuilderProphecy->reveal(); @@ -252,7 +249,6 @@ public function testEnableFosUser() 'FOSUserBundle' => FOSUserBundle::class, ])->shouldBeCalled(); $containerBuilderProphecy->setDefinition('api_platform.fos_user.event_listener', Argument::type(Definition::class))->shouldBeCalled(); - $containerBuilderProphecy->setParameter('api_platform.enable_swagger', '1')->shouldBeCalled(); $containerBuilder = $containerBuilderProphecy->reveal(); @@ -323,7 +319,6 @@ public function testEnableNelmioApiDoc() ])->shouldBeCalled(); $containerBuilderProphecy->setDefinition('api_platform.nelmio_api_doc.annotations_provider', Argument::type(Definition::class))->shouldBeCalled(); $containerBuilderProphecy->setDefinition('api_platform.nelmio_api_doc.parser', Argument::type(Definition::class))->shouldBeCalled(); - $containerBuilderProphecy->setParameter('api_platform.enable_swagger', '1')->shouldBeCalled(); $containerBuilder = $containerBuilderProphecy->reveal(); @@ -1058,9 +1053,8 @@ private function getBaseContainerBuilderProphecy(array $doctrineIntegrationsToLo 'api_platform.oauth.tokenUrl' => '/oauth/v2/token', 'api_platform.oauth.authorizationUrl' => '/oauth/v2/auth', 'api_platform.oauth.scopes' => [], - 'api_platform.swagger.versions' => ['2.0.0', '3.0.2'], + 'api_platform.swagger.versions' => ['2', '3'], 'api_platform.swagger.api_keys' => [], - 'api_platform.enable_swagger' => true, 'api_platform.enable_swagger_ui' => true, 'api_platform.enable_re_doc' => true, 'api_platform.graphql.enabled' => true, diff --git a/tests/Bridge/Symfony/Bundle/DependencyInjection/ConfigurationTest.php b/tests/Bridge/Symfony/Bundle/DependencyInjection/ConfigurationTest.php index e0dc34a870d..d0efcfdaace 100644 --- a/tests/Bridge/Symfony/Bundle/DependencyInjection/ConfigurationTest.php +++ b/tests/Bridge/Symfony/Bundle/DependencyInjection/ConfigurationTest.php @@ -141,7 +141,7 @@ private function runDefaultConfigTests(array $doctrineIntegrationsToLoad = ['orm 'scopes' => [], ], 'swagger' => [ - 'versions' => ['2.0.0', '3.0.2'], + 'versions' => ['2', '3'], 'api_keys' => [], ], 'eager_loading' => [ @@ -327,7 +327,7 @@ public function testDisabledSwaggerVersionConfig() 'api_platform' => [ 'enable_swagger' => false, 'swagger' => [ - 'versions' => ['3.0.2'], + 'versions' => ['3'], ], ], ]); @@ -344,24 +344,24 @@ public function testSwaggerVersionConfig() $config = $this->processor->processConfiguration($this->configuration, [ 'api_platform' => [ 'swagger' => [ - 'versions' => ['3.0.2'], + 'versions' => ['3'], ], ], ]); $this->assertTrue(isset($config['swagger']['versions'])); - $this->assertSame(['3.0.2'], $config['swagger']['versions']); + $this->assertSame(['3'], $config['swagger']['versions']); $config = $this->processor->processConfiguration($this->configuration, [ 'api_platform' => [ 'swagger' => [ - 'versions' => '2.0.0', + 'versions' => '2', ], ], ]); $this->assertTrue(isset($config['swagger']['versions'])); - $this->assertSame(['2.0.0'], $config['swagger']['versions']); + $this->assertSame(['2'], $config['swagger']['versions']); $this->expectException(InvalidConfigurationException::class); $this->expectExceptionMessageRegExp('/Only the versions .+ are supported. Got .+./'); @@ -369,7 +369,7 @@ public function testSwaggerVersionConfig() $this->processor->processConfiguration($this->configuration, [ 'api_platform' => [ 'swagger' => [ - 'versions' => ['1.0.0'], + 'versions' => ['1'], ], ], ]); diff --git a/tests/Bridge/Symfony/Routing/ApiLoaderTest.php b/tests/Bridge/Symfony/Routing/ApiLoaderTest.php index d1eebe28078..032b0cf2cbd 100644 --- a/tests/Bridge/Symfony/Routing/ApiLoaderTest.php +++ b/tests/Bridge/Symfony/Routing/ApiLoaderTest.php @@ -237,7 +237,6 @@ private function getApiLoaderWithResourceMetadata(ResourceMetadata $resourceMeta foreach ($possibleArguments as $possibleArgument) { $containerProphecy->has($possibleArgument)->willReturn(true); } - $containerProphecy->getParameter('api_platform.enable_swagger')->willReturn(true); $containerProphecy->has(Argument::type('string'))->willReturn(false); From 01d39ea3135e0fb0a58ac4687e72f91da5276e92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20H=C3=A9bert?= Date: Mon, 19 Aug 2019 21:56:18 +0200 Subject: [PATCH 04/13] fix optional parameter --- src/Bridge/Symfony/Bundle/Resources/config/api.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bridge/Symfony/Bundle/Resources/config/api.xml b/src/Bridge/Symfony/Bundle/Resources/config/api.xml index 31356a4b837..2d1b17d8918 100644 --- a/src/Bridge/Symfony/Bundle/Resources/config/api.xml +++ b/src/Bridge/Symfony/Bundle/Resources/config/api.xml @@ -241,7 +241,7 @@ %api_platform.description% %api_platform.version% null - %api_platform.swagger.versions% + container.hasParameter('api_platform.swagger.versions') ? parameter('api_platform.swagger.versions') : null From 167226e149759eda6e159a5b965c7bc9b2a0c6b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20H=C3=A9bert?= Date: Mon, 19 Aug 2019 22:01:48 +0200 Subject: [PATCH 05/13] Set nullable versions for DocumentationAction --- src/Documentation/Action/DocumentationAction.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Documentation/Action/DocumentationAction.php b/src/Documentation/Action/DocumentationAction.php index e001296b037..7f31005067e 100644 --- a/src/Documentation/Action/DocumentationAction.php +++ b/src/Documentation/Action/DocumentationAction.php @@ -34,7 +34,7 @@ final class DocumentationAction private $formatsProvider; private $swaggerVersions; - public function __construct(ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, string $title = '', string $description = '', string $version = '', $formatsProvider = null, array $swaggerVersions = []) + public function __construct(ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, string $title = '', string $description = '', string $version = '', $formatsProvider = null, ?array $swaggerVersions = []) { $this->resourceNameCollectionFactory = $resourceNameCollectionFactory; $this->title = $title; From de8862ef37cc98848d17c72098daec2e64cedc4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20H=C3=A9bert?= Date: Mon, 19 Aug 2019 22:08:29 +0200 Subject: [PATCH 06/13] fix phpstan review --- src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php | 1 + src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php b/src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php index afb1511c7ec..a76369e7d3b 100644 --- a/src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php +++ b/src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php @@ -56,6 +56,7 @@ final class SwaggerUiAction private $graphqlEnabled; private $graphiQlEnabled; private $graphQlPlaygroundEnabled; + private $swaggerVersions; public function __construct(ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, ResourceMetadataFactoryInterface $resourceMetadataFactory, NormalizerInterface $normalizer, TwigEnvironment $twig, UrlGeneratorInterface $urlGenerator, string $title = '', string $description = '', string $version = '', $formats = [], $oauthEnabled = false, $oauthClientId = '', $oauthClientSecret = '', $oauthType = '', $oauthFlow = '', $oauthTokenUrl = '', $oauthAuthorizationUrl = '', $oauthScopes = [], bool $showWebby = true, bool $swaggerUiEnabled = false, bool $reDocEnabled = false, bool $graphqlEnabled = false, bool $graphiQlEnabled = false, bool $graphQlPlaygroundEnabled = false, array $swaggerVersions = []) { diff --git a/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php b/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php index 16403faf711..82dd0d583fe 100644 --- a/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php +++ b/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php @@ -68,7 +68,7 @@ protected function configure() ->setAliases(['api:swagger:export']) ->setDescription('Dump the OpenAPI documentation') ->addOption('yaml', 'y', InputOption::VALUE_NONE, 'Dump the documentation in YAML') - ->addOption('spec-version', null, InputOption::VALUE_OPTIONAL, sprintf('OpenAPI version to use (%s)', implode(' or ', $this->swaggerVersions)), $this->swaggerVersions[0] ?? '2') + ->addOption('spec-version', null, InputOption::VALUE_OPTIONAL, sprintf('OpenAPI version to use (%s)', implode(' or ', $this->swaggerVersions)), (string) ($this->swaggerVersions[0] ?? '2')) ->addOption('output', 'o', InputOption::VALUE_OPTIONAL, 'Write output to file') ->addOption('api-gateway', null, InputOption::VALUE_NONE, 'API Gateway compatibility'); } From a55fa4e35d058711f62382307a67fe290232fe57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20H=C3=A9bert?= Date: Mon, 19 Aug 2019 22:10:25 +0200 Subject: [PATCH 07/13] fix php-cs-fixer review --- src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php | 2 +- .../Symfony/Bundle/DependencyInjection/Configuration.php | 4 ++-- src/Documentation/Action/DocumentationAction.php | 2 +- .../Symfony/Bundle/DependencyInjection/ConfigurationTest.php | 1 + 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php b/src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php index a76369e7d3b..53826e123f7 100644 --- a/src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php +++ b/src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php @@ -129,7 +129,7 @@ private function getContext(Request $request, Documentation $documentation): arr 'graphQlPlaygroundEnabled' => $this->graphQlPlaygroundEnabled, ]; - $swaggerContext = ['spec_version' => $request->query->getInt('spec_version', (int)($this->swaggerVersions[0] ?? 2))]; + $swaggerContext = ['spec_version' => $request->query->getInt('spec_version', (int) ($this->swaggerVersions[0] ?? 2))]; if ('' !== $baseUrl = $request->getBaseUrl()) { $swaggerContext['base_url'] = $baseUrl; } diff --git a/src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php b/src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php index 575bfc03d52..8a61a26d185 100644 --- a/src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php +++ b/src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php @@ -60,7 +60,7 @@ public function getConfigTreeBuilder() ->ifTrue(static function ($v) { return isset($v['enable_swagger']) && false === $v['enable_swagger']; }) - ->then(static function ($v){ + ->then(static function ($v) { $v['swagger']['versions'] = []; return $v; @@ -262,7 +262,7 @@ private function addSwaggerSection(ArrayNodeDefinition $rootNode): void ->defaultValue($defaultVersions) ->beforeNormalization()->castToArray()->end() ->validate() - ->ifTrue(function($v) use ($defaultVersions) { + ->ifTrue(function ($v) use ($defaultVersions) { return $v !== array_intersect($v, $defaultVersions); }) ->thenInvalid(sprintf('Only the versions %s are supported. Got %s.', implode(' and ', $defaultVersions), '%s')) diff --git a/src/Documentation/Action/DocumentationAction.php b/src/Documentation/Action/DocumentationAction.php index 7f31005067e..4574d935f2d 100644 --- a/src/Documentation/Action/DocumentationAction.php +++ b/src/Documentation/Action/DocumentationAction.php @@ -58,7 +58,7 @@ public function __construct(ResourceNameCollectionFactoryInterface $resourceName public function __invoke(Request $request = null): Documentation { if (null !== $request) { - $context = ['base_url' => $request->getBaseUrl(), 'spec_version' => $request->query->getInt('spec_version', (int)($this->swaggerVersions[0] ?? 2))]; + $context = ['base_url' => $request->getBaseUrl(), 'spec_version' => $request->query->getInt('spec_version', (int) ($this->swaggerVersions[0] ?? 2))]; if ($request->query->getBoolean('api_gateway')) { $context['api_gateway'] = true; } diff --git a/tests/Bridge/Symfony/Bundle/DependencyInjection/ConfigurationTest.php b/tests/Bridge/Symfony/Bundle/DependencyInjection/ConfigurationTest.php index d0efcfdaace..ec71d8b9ad5 100644 --- a/tests/Bridge/Symfony/Bundle/DependencyInjection/ConfigurationTest.php +++ b/tests/Bridge/Symfony/Bundle/DependencyInjection/ConfigurationTest.php @@ -318,6 +318,7 @@ public function testApiKeysConfig() /** * Test config for disabled swagger versions. + * * @group legacy * @expectedDeprecation The use of `enable_swagger` has been deprecated in 2.5 and will be removed in 3.0. use `api_platform.swagger.versions` instead. */ From 8aad499e889128b89eb235f88a4549bc04bd34b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20H=C3=A9bert?= Date: Tue, 20 Aug 2019 07:56:18 +0200 Subject: [PATCH 08/13] fix code review --- src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php | 5 ++--- src/Bridge/Symfony/Bundle/Resources/config/api.xml | 2 +- src/Swagger/Serializer/DocumentationNormalizer.php | 2 +- tests/Bridge/Symfony/Bundle/Command/SwaggerCommandTest.php | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php b/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php index 82dd0d583fe..0cad4419683 100644 --- a/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php +++ b/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php @@ -41,7 +41,7 @@ final class SwaggerCommand extends Command private $apiFormats; private $swaggerVersions; - public function __construct(NormalizerInterface $normalizer, ResourceNameCollectionFactoryInterface $resourceNameCollection, string $apiTitle, string $apiDescription, string $apiVersion, array $apiFormats = null, array $swaggerVersions = []) + public function __construct(NormalizerInterface $normalizer, ResourceNameCollectionFactoryInterface $resourceNameCollection, string $apiTitle, string $apiDescription, string $apiVersion, array $apiFormats = null, array $swaggerVersions = [2, 3]) { $this->normalizer = $normalizer; $this->resourceNameCollectionFactory = $resourceNameCollection; @@ -80,8 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { $io = new SymfonyStyle($input, $output); /** @var string $version */ - $version = $input->getOption('spec-version')[0]; - + $version = explode('.', $input->getOption('spec-version'))[0]; if (!\in_array($version, $this->swaggerVersions, true)) { throw new InvalidOptionException(sprintf('This tool only supports version %s of the OpenAPI specification ("%s" given).', implode(', ', $this->swaggerVersions), $version)); } diff --git a/src/Bridge/Symfony/Bundle/Resources/config/api.xml b/src/Bridge/Symfony/Bundle/Resources/config/api.xml index 2d1b17d8918..ae0a778da1b 100644 --- a/src/Bridge/Symfony/Bundle/Resources/config/api.xml +++ b/src/Bridge/Symfony/Bundle/Resources/config/api.xml @@ -241,7 +241,7 @@ %api_platform.description% %api_platform.version% null - container.hasParameter('api_platform.swagger.versions') ? parameter('api_platform.swagger.versions') : null + %api_platform.swagger.versions% diff --git a/src/Swagger/Serializer/DocumentationNormalizer.php b/src/Swagger/Serializer/DocumentationNormalizer.php index d77795d9658..7c247e35743 100644 --- a/src/Swagger/Serializer/DocumentationNormalizer.php +++ b/src/Swagger/Serializer/DocumentationNormalizer.php @@ -104,7 +104,7 @@ final class DocumentationNormalizer implements NormalizerInterface, CacheableSup * @param array|OperationAwareFormatsProviderInterface $formats * @param mixed|null $jsonSchemaTypeFactory */ - public function __construct(ResourceMetadataFactoryInterface $resourceMetadataFactory, PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, PropertyMetadataFactoryInterface $propertyMetadataFactory, $jsonSchemaFactory = null, $jsonSchemaTypeFactory = null, OperationPathResolverInterface $operationPathResolver, UrlGeneratorInterface $urlGenerator = null, $filterLocator = null, NameConverterInterface $nameConverter = null, bool $oauthEnabled = false, string $oauthType = '', string $oauthFlow = '', string $oauthTokenUrl = '', string $oauthAuthorizationUrl = '', array $oauthScopes = [], array $apiKeys = [], SubresourceOperationFactoryInterface $subresourceOperationFactory = null, bool $paginationEnabled = true, string $paginationPageParameterName = 'page', bool $clientItemsPerPage = false, string $itemsPerPageParameterName = 'itemsPerPage', $formats = [], bool $paginationClientEnabled = false, string $paginationClientEnabledParameterName = 'pagination', array $defaultContext = [], array $versions = []) + public function __construct(ResourceMetadataFactoryInterface $resourceMetadataFactory, PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, PropertyMetadataFactoryInterface $propertyMetadataFactory, $jsonSchemaFactory = null, $jsonSchemaTypeFactory = null, OperationPathResolverInterface $operationPathResolver, UrlGeneratorInterface $urlGenerator = null, $filterLocator = null, NameConverterInterface $nameConverter = null, bool $oauthEnabled = false, string $oauthType = '', string $oauthFlow = '', string $oauthTokenUrl = '', string $oauthAuthorizationUrl = '', array $oauthScopes = [], array $apiKeys = [], SubresourceOperationFactoryInterface $subresourceOperationFactory = null, bool $paginationEnabled = true, string $paginationPageParameterName = 'page', bool $clientItemsPerPage = false, string $itemsPerPageParameterName = 'itemsPerPage', $formats = [], bool $paginationClientEnabled = false, string $paginationClientEnabledParameterName = 'pagination', array $defaultContext = [], array $versions = [2, 3]) { if ($jsonSchemaTypeFactory instanceof OperationMethodResolverInterface) { @trigger_error(sprintf('Passing an instance of %s to %s() is deprecated since version 2.5 and will be removed in 3.0.', OperationMethodResolverInterface::class, __METHOD__), E_USER_DEPRECATED); diff --git a/tests/Bridge/Symfony/Bundle/Command/SwaggerCommandTest.php b/tests/Bridge/Symfony/Bundle/Command/SwaggerCommandTest.php index d4e230e327b..1b7d4001113 100644 --- a/tests/Bridge/Symfony/Bundle/Command/SwaggerCommandTest.php +++ b/tests/Bridge/Symfony/Bundle/Command/SwaggerCommandTest.php @@ -105,7 +105,7 @@ public function testExecuteOpenApiVersion2WithYaml() public function testExecuteWithBadArguments() { $this->expectException(InvalidOptionException::class); - $this->expectExceptionMessage('This tool only supports version 2 and 3 of the OpenAPI specification ("foo" given).'); + $this->expectExceptionMessage('This tool only supports version 2, 3 of the OpenAPI specification ("foo" given).'); $this->tester->run(['command' => 'api:openapi:export', '--spec-version' => 'foo', '--yaml' => true]); } From 4a4c52b7d34728dcd00cd596f02c6323444aabcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20H=C3=A9bert?= Date: Tue, 20 Aug 2019 08:16:15 +0200 Subject: [PATCH 09/13] fix phpstan --- src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php b/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php index 0cad4419683..c858dd8a70c 100644 --- a/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php +++ b/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php @@ -79,8 +79,13 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { $io = new SymfonyStyle($input, $output); + + /** @var string $spec_version */ + $spec_version = $input->getOption('spec-version'); + /** @var string $version */ - $version = explode('.', $input->getOption('spec-version'))[0]; + $version = explode('.', $spec_version)[0]; + if (!\in_array($version, $this->swaggerVersions, true)) { throw new InvalidOptionException(sprintf('This tool only supports version %s of the OpenAPI specification ("%s" given).', implode(', ', $this->swaggerVersions), $version)); } From fe105757d27364a660068c742f19f21c514827fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20H=C3=A9bert?= Date: Tue, 20 Aug 2019 13:18:44 +0200 Subject: [PATCH 10/13] fix code review --- .../Symfony/Bundle/Action/SwaggerUiAction.php | 4 +-- .../Symfony/Bundle/Command/SwaggerCommand.php | 12 ++++----- .../ApiPlatformExtension.php | 4 --- .../DependencyInjection/Configuration.php | 24 +++++++++++------ .../Action/DocumentationAction.php | 8 ++++-- .../Serializer/DocumentationNormalizer.php | 5 ++-- .../Bundle/Command/SwaggerCommandTest.php | 2 +- .../ApiPlatformExtensionTest.php | 2 +- .../DependencyInjection/ConfigurationTest.php | 27 +++++++++---------- 9 files changed, 47 insertions(+), 41 deletions(-) diff --git a/src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php b/src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php index 53826e123f7..e1e2bf11c96 100644 --- a/src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php +++ b/src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php @@ -58,7 +58,7 @@ final class SwaggerUiAction private $graphQlPlaygroundEnabled; private $swaggerVersions; - public function __construct(ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, ResourceMetadataFactoryInterface $resourceMetadataFactory, NormalizerInterface $normalizer, TwigEnvironment $twig, UrlGeneratorInterface $urlGenerator, string $title = '', string $description = '', string $version = '', $formats = [], $oauthEnabled = false, $oauthClientId = '', $oauthClientSecret = '', $oauthType = '', $oauthFlow = '', $oauthTokenUrl = '', $oauthAuthorizationUrl = '', $oauthScopes = [], bool $showWebby = true, bool $swaggerUiEnabled = false, bool $reDocEnabled = false, bool $graphqlEnabled = false, bool $graphiQlEnabled = false, bool $graphQlPlaygroundEnabled = false, array $swaggerVersions = []) + public function __construct(ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, ResourceMetadataFactoryInterface $resourceMetadataFactory, NormalizerInterface $normalizer, TwigEnvironment $twig, UrlGeneratorInterface $urlGenerator, string $title = '', string $description = '', string $version = '', $formats = [], $oauthEnabled = false, $oauthClientId = '', $oauthClientSecret = '', $oauthType = '', $oauthFlow = '', $oauthTokenUrl = '', $oauthAuthorizationUrl = '', $oauthScopes = [], bool $showWebby = true, bool $swaggerUiEnabled = false, bool $reDocEnabled = false, bool $graphqlEnabled = false, bool $graphiQlEnabled = false, bool $graphQlPlaygroundEnabled = false, array $swaggerVersions = [2, 3]) { $this->resourceNameCollectionFactory = $resourceNameCollectionFactory; $this->resourceMetadataFactory = $resourceMetadataFactory; @@ -129,7 +129,7 @@ private function getContext(Request $request, Documentation $documentation): arr 'graphQlPlaygroundEnabled' => $this->graphQlPlaygroundEnabled, ]; - $swaggerContext = ['spec_version' => $request->query->getInt('spec_version', (int) ($this->swaggerVersions[0] ?? 2))]; + $swaggerContext = ['spec_version' => $request->query->getInt('spec_version', $this->swaggerVersions[0] ?? 2)]; if ('' !== $baseUrl = $request->getBaseUrl()) { $swaggerContext['base_url'] = $baseUrl; } diff --git a/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php b/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php index c858dd8a70c..86edba65d8d 100644 --- a/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php +++ b/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php @@ -41,6 +41,9 @@ final class SwaggerCommand extends Command private $apiFormats; private $swaggerVersions; + /** + * @param int[] $swaggerVersions + */ public function __construct(NormalizerInterface $normalizer, ResourceNameCollectionFactoryInterface $resourceNameCollection, string $apiTitle, string $apiDescription, string $apiVersion, array $apiFormats = null, array $swaggerVersions = [2, 3]) { $this->normalizer = $normalizer; @@ -80,14 +83,11 @@ protected function execute(InputInterface $input, OutputInterface $output) { $io = new SymfonyStyle($input, $output); - /** @var string $spec_version */ - $spec_version = $input->getOption('spec-version'); - - /** @var string $version */ - $version = explode('.', $spec_version)[0]; + /** @var int $version */ + $version = $input->getOption('spec-version'); if (!\in_array($version, $this->swaggerVersions, true)) { - throw new InvalidOptionException(sprintf('This tool only supports version %s of the OpenAPI specification ("%s" given).', implode(', ', $this->swaggerVersions), $version)); + throw new InvalidOptionException(sprintf('This tool only supports versions %s of the OpenAPI specification ("%s" given).', implode(', ', $this->swaggerVersions), $version)); } $documentation = new Documentation($this->resourceNameCollectionFactory->create(), $this->apiTitle, $this->apiDescription, $this->apiVersion, $this->apiFormats); diff --git a/src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php b/src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php index 0f409fe8410..6fb0e44c216 100644 --- a/src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php +++ b/src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php @@ -307,10 +307,6 @@ private function registerOAuthConfiguration(ContainerBuilder $container, array $ */ private function registerSwaggerConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void { - if (!$config['enable_swagger']) { - @trigger_error('The "api_platform.enable_swagger" parameter is deprecated since version 2.5 and will have no effect in 3.0. Please use "api_platform.swagger.versions" instead.', E_USER_DEPRECATED); - } - if (empty($config['swagger']['versions'])) { return; } diff --git a/src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php b/src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php index 8a61a26d185..7ab0c5da92e 100644 --- a/src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php +++ b/src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php @@ -58,7 +58,7 @@ public function getConfigTreeBuilder() $rootNode ->beforeNormalization() ->ifTrue(static function ($v) { - return isset($v['enable_swagger']) && false === $v['enable_swagger']; + return false === ($v['enable_swagger'] ?? null); }) ->then(static function ($v) { $v['swagger']['versions'] = []; @@ -112,11 +112,7 @@ public function getConfigTreeBuilder() ->setDeprecated('Enabling the NelmioApiDocBundle integration has been deprecated in 2.2 and will be removed in 3.0. NelmioApiDocBundle 3 has native support for API Platform.') ->info('Enable the NelmioApiDocBundle integration.') ->end() - ->booleanNode('enable_swagger') - ->defaultTrue() - ->setDeprecated('The use of `enable_swagger` has been deprecated in 2.5 and will be removed in 3.0. use `api_platform.swagger.versions` instead.') - ->info('Enable the Swagger documentation and export.') - ->end() + ->booleanNode('enable_swagger')->defaultTrue()->info('Enable the Swagger documentation and export.')->end() ->booleanNode('enable_swagger_ui')->defaultValue(class_exists(TwigBundle::class))->info('Enable Swagger UI')->end() ->booleanNode('enable_re_doc')->defaultValue(class_exists(TwigBundle::class))->info('Enable ReDoc')->end() ->booleanNode('enable_entrypoint')->defaultTrue()->info('Enable the entrypoint')->end() @@ -250,7 +246,7 @@ private function addGraphQlSection(ArrayNodeDefinition $rootNode): void private function addSwaggerSection(ArrayNodeDefinition $rootNode): void { - $defaultVersions = ['2', '3']; + $defaultVersions = [2, 3]; $rootNode ->children() @@ -260,7 +256,19 @@ private function addSwaggerSection(ArrayNodeDefinition $rootNode): void ->arrayNode('versions') ->info('The active versions of OpenAPI to be exported or used in the swagger_ui. The first value is the default.') ->defaultValue($defaultVersions) - ->beforeNormalization()->castToArray()->end() + ->beforeNormalization() + ->always(static function ($v) { + if (!\is_array($v)) { + $v = [$v]; + } + + foreach ($v as &$version) { + $version = (int) $version; + } + + return $v; + }) + ->end() ->validate() ->ifTrue(function ($v) use ($defaultVersions) { return $v !== array_intersect($v, $defaultVersions); diff --git a/src/Documentation/Action/DocumentationAction.php b/src/Documentation/Action/DocumentationAction.php index 4574d935f2d..925da6166a0 100644 --- a/src/Documentation/Action/DocumentationAction.php +++ b/src/Documentation/Action/DocumentationAction.php @@ -34,7 +34,11 @@ final class DocumentationAction private $formatsProvider; private $swaggerVersions; - public function __construct(ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, string $title = '', string $description = '', string $version = '', $formatsProvider = null, ?array $swaggerVersions = []) + /** + * @param int[] $swaggerVersions + * @param mixed|null $formatsProvider + */ + public function __construct(ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, string $title = '', string $description = '', string $version = '', $formatsProvider = null, array $swaggerVersions = [2, 3]) { $this->resourceNameCollectionFactory = $resourceNameCollectionFactory; $this->title = $title; @@ -58,7 +62,7 @@ public function __construct(ResourceNameCollectionFactoryInterface $resourceName public function __invoke(Request $request = null): Documentation { if (null !== $request) { - $context = ['base_url' => $request->getBaseUrl(), 'spec_version' => $request->query->getInt('spec_version', (int) ($this->swaggerVersions[0] ?? 2))]; + $context = ['base_url' => $request->getBaseUrl(), 'spec_version' => $request->query->getInt('spec_version', $this->swaggerVersions[0] ?? 2)]; if ($request->query->getBoolean('api_gateway')) { $context['api_gateway'] = true; } diff --git a/src/Swagger/Serializer/DocumentationNormalizer.php b/src/Swagger/Serializer/DocumentationNormalizer.php index 7c247e35743..cd644be6d68 100644 --- a/src/Swagger/Serializer/DocumentationNormalizer.php +++ b/src/Swagger/Serializer/DocumentationNormalizer.php @@ -103,8 +103,9 @@ final class DocumentationNormalizer implements NormalizerInterface, CacheableSup * @param ContainerInterface|FilterCollection|null $filterLocator * @param array|OperationAwareFormatsProviderInterface $formats * @param mixed|null $jsonSchemaTypeFactory + * @param int[] $swaggerVersions */ - public function __construct(ResourceMetadataFactoryInterface $resourceMetadataFactory, PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, PropertyMetadataFactoryInterface $propertyMetadataFactory, $jsonSchemaFactory = null, $jsonSchemaTypeFactory = null, OperationPathResolverInterface $operationPathResolver, UrlGeneratorInterface $urlGenerator = null, $filterLocator = null, NameConverterInterface $nameConverter = null, bool $oauthEnabled = false, string $oauthType = '', string $oauthFlow = '', string $oauthTokenUrl = '', string $oauthAuthorizationUrl = '', array $oauthScopes = [], array $apiKeys = [], SubresourceOperationFactoryInterface $subresourceOperationFactory = null, bool $paginationEnabled = true, string $paginationPageParameterName = 'page', bool $clientItemsPerPage = false, string $itemsPerPageParameterName = 'itemsPerPage', $formats = [], bool $paginationClientEnabled = false, string $paginationClientEnabledParameterName = 'pagination', array $defaultContext = [], array $versions = [2, 3]) + public function __construct(ResourceMetadataFactoryInterface $resourceMetadataFactory, PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, PropertyMetadataFactoryInterface $propertyMetadataFactory, $jsonSchemaFactory = null, $jsonSchemaTypeFactory = null, OperationPathResolverInterface $operationPathResolver, UrlGeneratorInterface $urlGenerator = null, $filterLocator = null, NameConverterInterface $nameConverter = null, bool $oauthEnabled = false, string $oauthType = '', string $oauthFlow = '', string $oauthTokenUrl = '', string $oauthAuthorizationUrl = '', array $oauthScopes = [], array $apiKeys = [], SubresourceOperationFactoryInterface $subresourceOperationFactory = null, bool $paginationEnabled = true, string $paginationPageParameterName = 'page', bool $clientItemsPerPage = false, string $itemsPerPageParameterName = 'itemsPerPage', $formats = [], bool $paginationClientEnabled = false, string $paginationClientEnabledParameterName = 'pagination', array $defaultContext = [], array $swaggerVersions = [2, 3]) { if ($jsonSchemaTypeFactory instanceof OperationMethodResolverInterface) { @trigger_error(sprintf('Passing an instance of %s to %s() is deprecated since version 2.5 and will be removed in 3.0.', OperationMethodResolverInterface::class, __METHOD__), E_USER_DEPRECATED); @@ -162,7 +163,7 @@ public function __construct(ResourceMetadataFactoryInterface $resourceMetadataFa $this->paginationClientEnabled = $paginationClientEnabled; $this->paginationClientEnabledParameterName = $paginationClientEnabledParameterName; - $this->defaultContext[self::SPEC_VERSION] = (int) ($versions[0] ?? '2'); + $this->defaultContext[self::SPEC_VERSION] = $swaggerVersions[0] ?? 2; $this->defaultContext = array_merge($this->defaultContext, $defaultContext); } diff --git a/tests/Bridge/Symfony/Bundle/Command/SwaggerCommandTest.php b/tests/Bridge/Symfony/Bundle/Command/SwaggerCommandTest.php index 1b7d4001113..0b07dd66c02 100644 --- a/tests/Bridge/Symfony/Bundle/Command/SwaggerCommandTest.php +++ b/tests/Bridge/Symfony/Bundle/Command/SwaggerCommandTest.php @@ -105,7 +105,7 @@ public function testExecuteOpenApiVersion2WithYaml() public function testExecuteWithBadArguments() { $this->expectException(InvalidOptionException::class); - $this->expectExceptionMessage('This tool only supports version 2, 3 of the OpenAPI specification ("foo" given).'); + $this->expectExceptionMessage('This tool only supports versions 2, 3 of the OpenAPI specification ("foo" given).'); $this->tester->run(['command' => 'api:openapi:export', '--spec-version' => 'foo', '--yaml' => true]); } diff --git a/tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php b/tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php index 833940e97b6..384bec39977 100644 --- a/tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php +++ b/tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php @@ -1053,7 +1053,7 @@ private function getBaseContainerBuilderProphecy(array $doctrineIntegrationsToLo 'api_platform.oauth.tokenUrl' => '/oauth/v2/token', 'api_platform.oauth.authorizationUrl' => '/oauth/v2/auth', 'api_platform.oauth.scopes' => [], - 'api_platform.swagger.versions' => ['2', '3'], + 'api_platform.swagger.versions' => [2, 3], 'api_platform.swagger.api_keys' => [], 'api_platform.enable_swagger_ui' => true, 'api_platform.enable_re_doc' => true, diff --git a/tests/Bridge/Symfony/Bundle/DependencyInjection/ConfigurationTest.php b/tests/Bridge/Symfony/Bundle/DependencyInjection/ConfigurationTest.php index ec71d8b9ad5..c631b7b1fe9 100644 --- a/tests/Bridge/Symfony/Bundle/DependencyInjection/ConfigurationTest.php +++ b/tests/Bridge/Symfony/Bundle/DependencyInjection/ConfigurationTest.php @@ -141,7 +141,7 @@ private function runDefaultConfigTests(array $doctrineIntegrationsToLoad = ['orm 'scopes' => [], ], 'swagger' => [ - 'versions' => ['2', '3'], + 'versions' => [2, 3], 'api_keys' => [], ], 'eager_loading' => [ @@ -312,15 +312,12 @@ public function testApiKeysConfig() ], ]); - $this->assertTrue(isset($config['swagger']['api_keys'])); + $this->assertArrayHasKey('api_keys', $config['swagger']); $this->assertSame($exampleConfig, $config['swagger']['api_keys'][0]); } /** * Test config for disabled swagger versions. - * - * @group legacy - * @expectedDeprecation The use of `enable_swagger` has been deprecated in 2.5 and will be removed in 3.0. use `api_platform.swagger.versions` instead. */ public function testDisabledSwaggerVersionConfig() { @@ -328,13 +325,13 @@ public function testDisabledSwaggerVersionConfig() 'api_platform' => [ 'enable_swagger' => false, 'swagger' => [ - 'versions' => ['3'], + 'versions' => [3], ], ], ]); - $this->assertTrue(isset($config['swagger']['versions'])); - $this->assertSame([], $config['swagger']['versions']); + $this->assertArrayHasKey('versions', $config['swagger']); + $this->assertEmpty($config['swagger']['versions']); } /** @@ -345,24 +342,24 @@ public function testSwaggerVersionConfig() $config = $this->processor->processConfiguration($this->configuration, [ 'api_platform' => [ 'swagger' => [ - 'versions' => ['3'], + 'versions' => [3], ], ], ]); - $this->assertTrue(isset($config['swagger']['versions'])); - $this->assertSame(['3'], $config['swagger']['versions']); + $this->assertArrayHasKey('versions', $config['swagger']); + $this->assertSame([3], $config['swagger']['versions']); $config = $this->processor->processConfiguration($this->configuration, [ 'api_platform' => [ 'swagger' => [ - 'versions' => '2', + 'versions' => 2, ], ], ]); - $this->assertTrue(isset($config['swagger']['versions'])); - $this->assertSame(['2'], $config['swagger']['versions']); + $this->assertArrayHasKey('versions', $config['swagger']); + $this->assertSame([2], $config['swagger']['versions']); $this->expectException(InvalidConfigurationException::class); $this->expectExceptionMessageRegExp('/Only the versions .+ are supported. Got .+./'); @@ -370,7 +367,7 @@ public function testSwaggerVersionConfig() $this->processor->processConfiguration($this->configuration, [ 'api_platform' => [ 'swagger' => [ - 'versions' => ['1'], + 'versions' => [1], ], ], ]); From 3e60c0ae8981a6e561ef72295c49dc3cdb386c78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20H=C3=A9bert?= Date: Tue, 20 Aug 2019 13:42:09 +0200 Subject: [PATCH 11/13] fix SwaggerCommand default value for spec-version option --- src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php | 2 +- tests/Bridge/Symfony/Bundle/Command/SwaggerCommandTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php b/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php index 86edba65d8d..99056352948 100644 --- a/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php +++ b/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php @@ -71,7 +71,7 @@ protected function configure() ->setAliases(['api:swagger:export']) ->setDescription('Dump the OpenAPI documentation') ->addOption('yaml', 'y', InputOption::VALUE_NONE, 'Dump the documentation in YAML') - ->addOption('spec-version', null, InputOption::VALUE_OPTIONAL, sprintf('OpenAPI version to use (%s)', implode(' or ', $this->swaggerVersions)), (string) ($this->swaggerVersions[0] ?? '2')) + ->addOption('spec-version', null, InputOption::VALUE_OPTIONAL, sprintf('OpenAPI version to use (%s)', implode(' or ', $this->swaggerVersions)), $this->swaggerVersions[0] ?? 2) ->addOption('output', 'o', InputOption::VALUE_OPTIONAL, 'Write output to file') ->addOption('api-gateway', null, InputOption::VALUE_NONE, 'API Gateway compatibility'); } diff --git a/tests/Bridge/Symfony/Bundle/Command/SwaggerCommandTest.php b/tests/Bridge/Symfony/Bundle/Command/SwaggerCommandTest.php index 0b07dd66c02..e290d87768c 100644 --- a/tests/Bridge/Symfony/Bundle/Command/SwaggerCommandTest.php +++ b/tests/Bridge/Symfony/Bundle/Command/SwaggerCommandTest.php @@ -43,7 +43,7 @@ protected function setUp(): void public function testExecuteWithAliasVersion3() { - $this->tester->run(['command' => 'api:swagger:export', '--spec-version' => '3']); + $this->tester->run(['command' => 'api:swagger:export', '--spec-version' => 3]); $this->assertJson($this->tester->getDisplay()); } @@ -57,7 +57,7 @@ public function testExecuteOpenApiVersion2() public function testExecuteWithYamlVersion3() { - $this->tester->run(['command' => 'api:swagger:export', '--yaml' => true, '--spec-version' => '3']); + $this->tester->run(['command' => 'api:swagger:export', '--yaml' => true, '--spec-version' => 3]); $result = $this->tester->getDisplay(); $this->assertYaml($result); From d791891eed042d40be3906e6fafaefbfd036495d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20H=C3=A9bert?= Date: Tue, 20 Aug 2019 15:21:42 +0200 Subject: [PATCH 12/13] fix swagger Command cast int option --- src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php b/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php index 99056352948..2a44b68c106 100644 --- a/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php +++ b/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php @@ -83,10 +83,10 @@ protected function execute(InputInterface $input, OutputInterface $output) { $io = new SymfonyStyle($input, $output); - /** @var int $version */ + /** @var string $version */ $version = $input->getOption('spec-version'); - if (!\in_array($version, $this->swaggerVersions, true)) { + if (!\in_array((int) $version, $this->swaggerVersions, true)) { throw new InvalidOptionException(sprintf('This tool only supports versions %s of the OpenAPI specification ("%s" given).', implode(', ', $this->swaggerVersions), $version)); } From b8158c1ca26030b5a1b7c2453a224d587b9c5dc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20H=C3=A9bert?= Date: Tue, 20 Aug 2019 17:31:39 +0200 Subject: [PATCH 13/13] fix phpdoc --- src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php | 3 +++ src/Documentation/Action/DocumentationAction.php | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php b/src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php index e1e2bf11c96..976c2e0ea67 100644 --- a/src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php +++ b/src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php @@ -58,6 +58,9 @@ final class SwaggerUiAction private $graphQlPlaygroundEnabled; private $swaggerVersions; + /** + * @param int[] $swaggerVersions + */ public function __construct(ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, ResourceMetadataFactoryInterface $resourceMetadataFactory, NormalizerInterface $normalizer, TwigEnvironment $twig, UrlGeneratorInterface $urlGenerator, string $title = '', string $description = '', string $version = '', $formats = [], $oauthEnabled = false, $oauthClientId = '', $oauthClientSecret = '', $oauthType = '', $oauthFlow = '', $oauthTokenUrl = '', $oauthAuthorizationUrl = '', $oauthScopes = [], bool $showWebby = true, bool $swaggerUiEnabled = false, bool $reDocEnabled = false, bool $graphqlEnabled = false, bool $graphiQlEnabled = false, bool $graphQlPlaygroundEnabled = false, array $swaggerVersions = [2, 3]) { $this->resourceNameCollectionFactory = $resourceNameCollectionFactory; diff --git a/src/Documentation/Action/DocumentationAction.php b/src/Documentation/Action/DocumentationAction.php index 925da6166a0..57fd1698372 100644 --- a/src/Documentation/Action/DocumentationAction.php +++ b/src/Documentation/Action/DocumentationAction.php @@ -35,8 +35,8 @@ final class DocumentationAction private $swaggerVersions; /** - * @param int[] $swaggerVersions - * @param mixed|null $formatsProvider + * @param int[] $swaggerVersions + * @param mixed|array|FormatsProviderInterface $formatsProvider */ public function __construct(ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, string $title = '', string $description = '', string $version = '', $formatsProvider = null, array $swaggerVersions = [2, 3]) {