From 8b7128e49df3e12636af9d62b9731146c415f70a Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Tue, 9 Aug 2022 17:03:35 +0200 Subject: [PATCH] chore: better BC/FC layer for deprecated `Command::$defaultName` --- .../Symfony/Bundle/Command/GraphQlExportCommand.php | 12 +++++++----- src/Bridge/Symfony/Bundle/Command/OpenApiCommand.php | 12 +++++++----- src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php | 12 +++++++----- src/JsonSchema/Command/JsonSchemaGenerateCommand.php | 12 +++++++----- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/Bridge/Symfony/Bundle/Command/GraphQlExportCommand.php b/src/Bridge/Symfony/Bundle/Command/GraphQlExportCommand.php index 94b959a01c3..2c93ac953f8 100644 --- a/src/Bridge/Symfony/Bundle/Command/GraphQlExportCommand.php +++ b/src/Bridge/Symfony/Bundle/Command/GraphQlExportCommand.php @@ -15,6 +15,7 @@ use ApiPlatform\Core\GraphQl\Type\SchemaBuilderInterface; use GraphQL\Utils\SchemaPrinter; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -28,8 +29,14 @@ * * @author Alan Poulain */ +#[AsCommand(name: 'api:graphql:export', description: 'Export the GraphQL schema in Schema Definition Language (SDL)')] class GraphQlExportCommand extends Command { + /** + * @deprecated To be removed along with Symfony <6.1 compatibility + */ + protected static $defaultName = 'api:graphql:export'; + private $schemaBuilder; public function __construct(SchemaBuilderInterface $schemaBuilder) @@ -77,9 +84,4 @@ protected function execute(InputInterface $input, OutputInterface $output) return 0; } - - public static function getDefaultName(): string - { - return 'api:graphql:export'; - } } diff --git a/src/Bridge/Symfony/Bundle/Command/OpenApiCommand.php b/src/Bridge/Symfony/Bundle/Command/OpenApiCommand.php index 98e5b93c961..32470ce0db0 100644 --- a/src/Bridge/Symfony/Bundle/Command/OpenApiCommand.php +++ b/src/Bridge/Symfony/Bundle/Command/OpenApiCommand.php @@ -14,6 +14,7 @@ namespace ApiPlatform\Core\Bridge\Symfony\Bundle\Command; use ApiPlatform\Core\OpenApi\Factory\OpenApiFactoryInterface; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputInterface; @@ -27,8 +28,14 @@ /** * Dumps Open API documentation. */ +#[AsCommand(name: 'api:openapi:export', description: 'Dump the Open API documentation')] final class OpenApiCommand extends Command { + /** + * @deprecated To be removed along with Symfony <6.1 compatibility + */ + protected static $defaultName = 'api:openapi:export'; + private $openApiFactory; private $normalizer; @@ -89,9 +96,4 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 0; } - - public static function getDefaultName(): string - { - return 'api:openapi:export'; - } } diff --git a/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php b/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php index f6134ca2901..69e468b8248 100644 --- a/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php +++ b/src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php @@ -17,6 +17,7 @@ use ApiPlatform\Core\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface; use ApiPlatform\Core\Swagger\Serializer\ApiGatewayNormalizer; use ApiPlatform\Core\Swagger\Serializer\DocumentationNormalizer; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Exception\InvalidOptionException; use Symfony\Component\Console\Input\InputInterface; @@ -31,8 +32,14 @@ * * @author Amrouche Hamza */ +#[AsCommand(name: 'swagger:export', description: 'Dump the Swagger v2 documentation')] final class SwaggerCommand extends Command { + /** + * @deprecated To be removed along with Symfony <6.1 compatibility + */ + protected static $defaultName = 'api:swagger:export'; + private $normalizer; private $resourceNameCollectionFactory; private $apiTitle; @@ -107,9 +114,4 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 0; } - - public static function getDefaultName(): string - { - return 'api:swagger:export'; - } } diff --git a/src/JsonSchema/Command/JsonSchemaGenerateCommand.php b/src/JsonSchema/Command/JsonSchemaGenerateCommand.php index c2bb5db782f..4ee0a2c52ea 100644 --- a/src/JsonSchema/Command/JsonSchemaGenerateCommand.php +++ b/src/JsonSchema/Command/JsonSchemaGenerateCommand.php @@ -16,6 +16,7 @@ use ApiPlatform\Core\Api\OperationType; use ApiPlatform\Core\JsonSchema\Schema; use ApiPlatform\Core\JsonSchema\SchemaFactoryInterface; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Exception\InvalidOptionException; use Symfony\Component\Console\Input\InputArgument; @@ -29,8 +30,14 @@ * * @author Jacques Lefebvre */ +#[AsCommand(name: 'api:json-schema:generate', description: 'Generates the JSON Schema for a resource operation.')] final class JsonSchemaGenerateCommand extends Command { + /** + * @deprecated To be removed along with Symfony <6.1 compatibility + */ + protected static $defaultName = 'api:json-schema:generate'; + private $schemaFactory; private $formats; @@ -112,9 +119,4 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 0; } - - public static function getDefaultName(): string - { - return 'api:json-schema:generate'; - } }