From fc9f899e620881e1d4e1ca46dba603a29e30ec09 Mon Sep 17 00:00:00 2001 From: djordy Date: Fri, 1 Nov 2024 14:55:16 +0100 Subject: [PATCH 01/11] chore: 5.x remove NullablePropertyTrait --- UPGRADE-5.0.md | 6 +- .../NullablePropertyTrait.php | 62 ------------------- 2 files changed, 5 insertions(+), 63 deletions(-) delete mode 100644 src/PropertyDescriber/NullablePropertyTrait.php diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index 8f132674a..a9cd79ba4 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -36,4 +36,8 @@ nelmio_api_doc: - ^/api/foo - with_annotation: true + with_attribute: true -``` \ No newline at end of file +``` + +## BC BREAK: Removed `Nelmio\ApiDocBundle\PropertyDescriber\NullablePropertyTrait` +This class was deprecated since `4.17.0` + diff --git a/src/PropertyDescriber/NullablePropertyTrait.php b/src/PropertyDescriber/NullablePropertyTrait.php deleted file mode 100644 index 746a8edf3..000000000 --- a/src/PropertyDescriber/NullablePropertyTrait.php +++ /dev/null @@ -1,62 +0,0 @@ -nullable) { - if (!$property->nullable) { - // if already false mark it as undefined (so it does not show up as `nullable: false`) - $property->nullable = Generator::UNDEFINED; - } - - return; - } - - if ($type->isNullable()) { - $property->nullable = true; - } - - if (!$type->isNullable() && Generator::UNDEFINED !== $property->default) { - return; - } - - if (!$type->isNullable() && null !== $schema) { - $propertyName = Util::getSchemaPropertyName($schema, $property); - if (null === $propertyName) { - return; - } - - $existingRequiredFields = Generator::UNDEFINED !== $schema->required ? $schema->required : []; - $existingRequiredFields[] = $propertyName; - - $schema->required = array_values(array_unique($existingRequiredFields)); - } - } -} From 9268d005e3d5692e18ee7856ea8a0db2ea76687c Mon Sep 17 00:00:00 2001 From: djordy Date: Fri, 1 Nov 2024 14:57:36 +0100 Subject: [PATCH 02/11] chore: 5.x remove $overwrite param --- UPGRADE-5.0.md | 2 ++ src/Describer/OpenApiPhpDescriber.php | 6 +----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index a9cd79ba4..b69eb6de4 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -41,3 +41,5 @@ nelmio_api_doc: ## BC BREAK: Removed `Nelmio\ApiDocBundle\PropertyDescriber\NullablePropertyTrait` This class was deprecated since `4.17.0` +## Removed optional 4th param `bool $overwrite = false` from `Nelmio\ApiDocBundle\Describer\OpenApiPhpDescriber::__construct()` +This parameter was deprecated since `4.25.2` \ No newline at end of file diff --git a/src/Describer/OpenApiPhpDescriber.php b/src/Describer/OpenApiPhpDescriber.php index bec30c519..3fc5f0ef1 100644 --- a/src/Describer/OpenApiPhpDescriber.php +++ b/src/Describer/OpenApiPhpDescriber.php @@ -34,12 +34,8 @@ final class OpenApiPhpDescriber private ControllerReflector $controllerReflector; private LoggerInterface $logger; - public function __construct(RouteCollection $routeCollection, ControllerReflector $controllerReflector, LoggerInterface $logger, bool $overwrite = false) + public function __construct(RouteCollection $routeCollection, ControllerReflector $controllerReflector, LoggerInterface $logger) { - if ($overwrite || func_num_args() > 4) { - trigger_deprecation('nelmio/api-doc-bundle', '4.25.2', 'The "$overwrite" argument of "%s" is unused and therefore deprecated.', __METHOD__); - } - $this->routeCollection = $routeCollection; $this->controllerReflector = $controllerReflector; $this->logger = $logger; From 5063e5b45de565d89e53546333aab062e0e4652e Mon Sep 17 00:00:00 2001 From: djordy Date: Fri, 1 Nov 2024 14:59:17 +0100 Subject: [PATCH 03/11] chore: 5.x remove RequiredPropertyDescriber --- UPGRADE-5.0.md | 4 +- phpstan-baseline.neon | 5 -- .../RequiredPropertyDescriber.php | 73 ------------------- 3 files changed, 3 insertions(+), 79 deletions(-) delete mode 100644 src/PropertyDescriber/RequiredPropertyDescriber.php diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index b69eb6de4..b18b36485 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -42,4 +42,6 @@ nelmio_api_doc: This class was deprecated since `4.17.0` ## Removed optional 4th param `bool $overwrite = false` from `Nelmio\ApiDocBundle\Describer\OpenApiPhpDescriber::__construct()` -This parameter was deprecated since `4.25.2` \ No newline at end of file +This parameter was deprecated since `4.25.2` + +## BC BREAK: Removed `Nelmio\ApiDocBundle\PropertyDescriber\RequiredPropertyDescriber` \ No newline at end of file diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 8f22ab9b4..c45409037 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -40,11 +40,6 @@ parameters: count: 1 path: src/PropertyDescriber/PropertyDescriberInterface.php - - - message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\PropertyDescriberInterface\\:\\:describe\\(\\) invoked with 5 parameters, 2\\-3 required\\.$#" - count: 1 - path: src/PropertyDescriber/RequiredPropertyDescriber.php - - message: "#^Call to method render\\(\\) on an unknown class Twig_Environment\\.$#" count: 2 diff --git a/src/PropertyDescriber/RequiredPropertyDescriber.php b/src/PropertyDescriber/RequiredPropertyDescriber.php deleted file mode 100644 index f4d88fc41..000000000 --- a/src/PropertyDescriber/RequiredPropertyDescriber.php +++ /dev/null @@ -1,73 +0,0 @@ - $context Context options for describing the property - */ - public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = []) - { - if (null === $schema) { - trigger_deprecation( - 'nelmio/api-doc-bundle', - '4.15.0', - '"%s()" will have a new "OA\Schema $schema" argument in a future version. Not defining it or passing null is deprecated', - __METHOD__ - ); - } - - if (null !== $groups) { - trigger_deprecation( - 'nelmio/api-doc-bundle', - '4.17.0', - 'Using the $groups parameter of "%s()" is deprecated and will be removed in a future version. Pass groups via $context[\'groups\']', - __METHOD__ - ); - } - - $this->propertyDescriber->describe($types, $property, $groups, $schema, $context); - - if (!$property instanceof OA\Property) { - return; - } - - if (null === $schema) { - return; - } - - if (true === $property->nullable || !Generator::isDefault($property->default)) { - return; - } - - $existingRequiredFields = Generator::UNDEFINED !== $schema->required ? $schema->required : []; - $existingRequiredFields[] = $property->property; - - $schema->required = array_values(array_unique($existingRequiredFields)); - } - - public function supports(array $types): bool - { - return true; - } -} From f3b51f5b17efb365531ad6c9b56eec11d93c11e7 Mon Sep 17 00:00:00 2001 From: djordy Date: Fri, 8 Nov 2024 16:27:39 +0100 Subject: [PATCH 04/11] chore: 5.x remove getExtendedType() --- UPGRADE-5.0.md | 4 +++- src/Form/Extension/DocumentationExtension.php | 18 ------------------ 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index b18b36485..6a75fc787 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -44,4 +44,6 @@ This class was deprecated since `4.17.0` ## Removed optional 4th param `bool $overwrite = false` from `Nelmio\ApiDocBundle\Describer\OpenApiPhpDescriber::__construct()` This parameter was deprecated since `4.25.2` -## BC BREAK: Removed `Nelmio\ApiDocBundle\PropertyDescriber\RequiredPropertyDescriber` \ No newline at end of file +## BC BREAK: Removed `Nelmio\ApiDocBundle\PropertyDescriber\RequiredPropertyDescriber` + +## BC BREAK: Removed `Nelmio\ApiDocBundle\Form\Extension::getExtendedType()` \ No newline at end of file diff --git a/src/Form/Extension/DocumentationExtension.php b/src/Form/Extension/DocumentationExtension.php index 4c4c42c38..0c98b8baa 100644 --- a/src/Form/Extension/DocumentationExtension.php +++ b/src/Form/Extension/DocumentationExtension.php @@ -32,24 +32,6 @@ public function configureOptions(OptionsResolver $resolver): void ->setAllowedTypes('documentation', ['array', 'bool']); } - /** - * @deprecated since Symfony 4.2, use getExtendedTypes() instead. - * - * @return string - */ - public function getExtendedType() - { - trigger_deprecation( - 'nelmio/api-doc-bundle', - '4.28.1', - 'Calling %s is deprecated since Symfony 4.2, call %s instead', - __METHOD__, - 'DocumentationExtension::getExtendedTypes()', - ); - - return self::getExtendedTypes()[0]; - } - public static function getExtendedTypes(): iterable { return [FormType::class]; From d3d8d1a5af24182f9ede6cfbb6f6a2fe7e2b5425 Mon Sep 17 00:00:00 2001 From: djordy Date: Fri, 8 Nov 2024 16:31:59 +0100 Subject: [PATCH 05/11] chore: 5.x remove nullable $options --- UPGRADE-5.0.md | 4 +- src/Attribute/Model.php | 7 +- src/Model/Model.php | 7 +- .../Controller/DeprecationController.php | 31 ------- tests/Functional/ControllerTest.php | 7 -- .../Fixtures/DeprecationController.json | 86 ------------------- tests/Model/ModelRegistryTest.php | 2 +- 7 files changed, 6 insertions(+), 138 deletions(-) delete mode 100644 tests/Functional/Controller/DeprecationController.php delete mode 100644 tests/Functional/Fixtures/DeprecationController.json diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index 6a75fc787..4cbf26328 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -46,4 +46,6 @@ This parameter was deprecated since `4.25.2` ## BC BREAK: Removed `Nelmio\ApiDocBundle\PropertyDescriber\RequiredPropertyDescriber` -## BC BREAK: Removed `Nelmio\ApiDocBundle\Form\Extension::getExtendedType()` \ No newline at end of file +## BC BREAK: Removed `Nelmio\ApiDocBundle\Form\Extension::getExtendedType()` + +## BC BREAK: Removed `null` as a possible type for parameter `$options` in `Nelmio\ApiDocBundle\Model\Model::__construct()` & `Nelmio\ApiDocBundle\Attribute\Model::__construct()` \ No newline at end of file diff --git a/src/Attribute/Model.php b/src/Attribute/Model.php index 245951e6d..4a49bd74f 100644 --- a/src/Attribute/Model.php +++ b/src/Attribute/Model.php @@ -57,14 +57,9 @@ public function __construct( array $properties = [], string $type = Generator::UNDEFINED, ?array $groups = null, - ?array $options = [], + array $options = [], array $serializationContext = [] ) { - if (null === $options) { - trigger_deprecation('nelmio/api-doc-bundle', '4.33.4', 'Passing null to the "$options" argument of "%s()" is deprecated, pass an empty array instead.', __METHOD__); - $options = []; - } - parent::__construct($properties + [ 'type' => $type, 'groups' => $groups, diff --git a/src/Model/Model.php b/src/Model/Model.php index 1a911d156..5880937bf 100644 --- a/src/Model/Model.php +++ b/src/Model/Model.php @@ -32,13 +32,8 @@ final class Model * @param mixed[]|null $options * @param mixed[] $serializationContext */ - public function __construct(Type $type, ?array $groups = null, ?array $options = [], array $serializationContext = []) + public function __construct(Type $type, ?array $groups = null, array $options = [], array $serializationContext = []) { - if (null === $options) { - trigger_deprecation('nelmio/api-doc-bundle', '4.33.4', 'Passing null to the "$options" argument of "%s()" is deprecated, pass an empty array instead.', __METHOD__); - $options = []; - } - $this->type = $type; $this->options = $options; $this->serializationContext = $serializationContext; diff --git a/tests/Functional/Controller/DeprecationController.php b/tests/Functional/Controller/DeprecationController.php deleted file mode 100644 index eec971a02..000000000 --- a/tests/Functional/Controller/DeprecationController.php +++ /dev/null @@ -1,31 +0,0 @@ - [ - [ - 'name' => 'DeprecationController', - 'type' => $type, - ], - ]; - if (version_compare(Kernel::VERSION, '6.3.0', '>=')) { yield 'https://github.com/nelmio/NelmioApiDocBundle/issues/2209' => [ [ diff --git a/tests/Functional/Fixtures/DeprecationController.json b/tests/Functional/Fixtures/DeprecationController.json deleted file mode 100644 index 03c2b3fbb..000000000 --- a/tests/Functional/Fixtures/DeprecationController.json +++ /dev/null @@ -1,86 +0,0 @@ -{ - "openapi": "3.0.0", - "info": { - "title": "", - "version": "0.0.0" - }, - "paths": { - "/legacy/null_options": { - "post": { - "operationId": "post_legacy_null_options", - "responses": { - "200": { - "description": "Legacy null options", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Article81" - } - } - } - } - } - } - } - }, - "components": { - "schemas": { - "Article81": { - "required": [ - "id", - "type", - "intBackedType", - "notBackedType" - ], - "properties": { - "id": { - "type": "integer" - }, - "type": { - "$ref": "#/components/schemas/ArticleType81" - }, - "intBackedType": { - "$ref": "#/components/schemas/ArticleType81IntBacked" - }, - "notBackedType": { - "$ref": "#/components/schemas/ArticleType81NotBacked" - }, - "nullableType": { - "nullable": true, - "oneOf": [ - { - "$ref": "#/components/schemas/ArticleType81" - } - ] - } - }, - "type": "object" - }, - "ArticleType81": { - "type": "string", - "enum": [ - "draft", - "final" - ] - }, - "ArticleType81IntBacked": { - "type": "integer", - "enum": [ - 0, - 1 - ] - }, - "ArticleType81NotBacked": { - "required": [ - "name" - ], - "properties": { - "name": { - "type": "string" - } - }, - "type": "object" - } - } - } -} \ No newline at end of file diff --git a/tests/Model/ModelRegistryTest.php b/tests/Model/ModelRegistryTest.php index e24772f25..9c0c0957c 100644 --- a/tests/Model/ModelRegistryTest.php +++ b/tests/Model/ModelRegistryTest.php @@ -70,7 +70,7 @@ public function testNameCollisionsAreLogged(Type $type, array $arrayType): void $registry = new ModelRegistry([], $this->createOpenApi(), []); $registry->setLogger($logger); - $registry->register(new Model($type, ['group1'], null, ['extra_context' => true])); + $registry->register(new Model($type, ['group1'], [], ['extra_context' => true])); $registry->register(new Model($type, ['group2'])); } From 43de6d0fd11bc6aa6353f7e2eb5c62e3fb4cc615 Mon Sep 17 00:00:00 2001 From: djordy Date: Fri, 8 Nov 2024 16:34:00 +0100 Subject: [PATCH 06/11] chore: 5.x remove UndocumentedArrayItemsException --- UPGRADE-5.0.md | 4 +- .../UndocumentedArrayItemsException.php | 58 ------------------- 2 files changed, 3 insertions(+), 59 deletions(-) delete mode 100644 src/Exception/UndocumentedArrayItemsException.php diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index 4cbf26328..789626344 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -48,4 +48,6 @@ This parameter was deprecated since `4.25.2` ## BC BREAK: Removed `Nelmio\ApiDocBundle\Form\Extension::getExtendedType()` -## BC BREAK: Removed `null` as a possible type for parameter `$options` in `Nelmio\ApiDocBundle\Model\Model::__construct()` & `Nelmio\ApiDocBundle\Attribute\Model::__construct()` \ No newline at end of file +## BC BREAK: Removed `null` as a possible type for parameter `$options` in `Nelmio\ApiDocBundle\Model\Model::__construct()` & `Nelmio\ApiDocBundle\Attribute\Model::__construct()` + +## BC BREAK: Removed `Nelmio\ApiDocBundle\Exception\UndocumentedArrayItemsException` \ No newline at end of file diff --git a/src/Exception/UndocumentedArrayItemsException.php b/src/Exception/UndocumentedArrayItemsException.php deleted file mode 100644 index f6cee4224..000000000 --- a/src/Exception/UndocumentedArrayItemsException.php +++ /dev/null @@ -1,58 +0,0 @@ -class = $class; - $this->path = $path; - - $propertyName = ''; - if (null !== $class) { - $propertyName = $class.'::'; - } - $propertyName .= $path; - - parent::__construct(sprintf('Property "%s" is an array, but its items type isn\'t specified. You can specify that by using the type `string[]` for instance or `#[OA\Property(type="array", new OA\Items(type="string"))]`.', $propertyName)); - } - - /** - * @return string|null - */ - public function getClass() - { - return $this->class; - } - - /** - * @return string - */ - public function getPath() - { - return $this->path; - } -} From c0426930296fa5c6dfda792e71068f348eb38a26 Mon Sep 17 00:00:00 2001 From: djordy Date: Fri, 8 Nov 2024 16:36:22 +0100 Subject: [PATCH 07/11] phpstan --- src/Model/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/Model.php b/src/Model/Model.php index 5880937bf..304bdf672 100644 --- a/src/Model/Model.php +++ b/src/Model/Model.php @@ -29,7 +29,7 @@ final class Model /** * @param string[]|null $groups - * @param mixed[]|null $options + * @param mixed[] $options * @param mixed[] $serializationContext */ public function __construct(Type $type, ?array $groups = null, array $options = [], array $serializationContext = []) From 6db970a4c721ee8deef2f66777e10198e6a8ea18 Mon Sep 17 00:00:00 2001 From: djordy Date: Tue, 12 Nov 2024 15:00:34 +0100 Subject: [PATCH 08/11] chore: 5.x update type from ObjectModelDescriber --- UPGRADE-5.0.md | 4 ++- src/ModelDescriber/ObjectModelDescriber.php | 30 ++++++--------------- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index 789626344..8bb144e81 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -50,4 +50,6 @@ This parameter was deprecated since `4.25.2` ## BC BREAK: Removed `null` as a possible type for parameter `$options` in `Nelmio\ApiDocBundle\Model\Model::__construct()` & `Nelmio\ApiDocBundle\Attribute\Model::__construct()` -## BC BREAK: Removed `Nelmio\ApiDocBundle\Exception\UndocumentedArrayItemsException` \ No newline at end of file +## BC BREAK: Removed `Nelmio\ApiDocBundle\Exception\UndocumentedArrayItemsException` + +## BC BREAK: Changed type of parameter `$propertyDescriber` in `Nelmio\ApiDocBundle\ModelDescriber\ObjectModelDescriber::__construct()` from `PropertyDescriberInterface|PropertyDescriberInterface[]` to `PropertyDescriberInterface` \ No newline at end of file diff --git a/src/ModelDescriber/ObjectModelDescriber.php b/src/ModelDescriber/ObjectModelDescriber.php index 47253a84a..79bddc907 100644 --- a/src/ModelDescriber/ObjectModelDescriber.php +++ b/src/ModelDescriber/ObjectModelDescriber.php @@ -32,8 +32,7 @@ class ObjectModelDescriber implements ModelDescriberInterface, ModelRegistryAwar private PropertyInfoExtractorInterface $propertyInfo; private ?ClassMetadataFactoryInterface $classMetadataFactory; - /** @var PropertyDescriberInterface|PropertyDescriberInterface[] */ - private $propertyDescriber; + private PropertyDescriberInterface $propertyDescriber; /** @var string[] */ private array $mediaTypes; /** @var (NameConverterInterface&AdvancedNameConverterInterface)|null */ @@ -41,26 +40,17 @@ class ObjectModelDescriber implements ModelDescriberInterface, ModelRegistryAwar private bool $useValidationGroups; /** - * @param PropertyDescriberInterface|PropertyDescriberInterface[] $propertyDescribers * @param (NameConverterInterface&AdvancedNameConverterInterface)|null $nameConverter * @param string[] $mediaTypes */ public function __construct( PropertyInfoExtractorInterface $propertyInfo, - $propertyDescribers, + PropertyDescriberInterface $propertyDescribers, array $mediaTypes, ?NameConverterInterface $nameConverter = null, bool $useValidationGroups = false, ?ClassMetadataFactoryInterface $classMetadataFactory = null ) { - if (is_iterable($propertyDescribers)) { - trigger_deprecation('nelmio/api-doc-bundle', '4.17', 'Passing an array of PropertyDescriberInterface to %s() is deprecated. Pass a single PropertyDescriberInterface instead.', __METHOD__); - } else { - if (!$propertyDescribers instanceof PropertyDescriberInterface) { - throw new \InvalidArgumentException(sprintf('Argument 3 passed to %s() must be an array of %s or a single %s.', __METHOD__, PropertyDescriberInterface::class, PropertyDescriberInterface::class)); - } - } - $this->propertyInfo = $propertyInfo; $this->propertyDescriber = $propertyDescribers; $this->mediaTypes = $mediaTypes; @@ -190,17 +180,13 @@ private function camelize(string $string): string */ private function describeProperty(array $types, Model $model, OA\Schema $property, string $propertyName, OA\Schema $schema): void { - $propertyDescribers = is_iterable($this->propertyDescriber) ? $this->propertyDescriber : [$this->propertyDescriber]; - - foreach ($propertyDescribers as $propertyDescriber) { - if ($propertyDescriber instanceof ModelRegistryAwareInterface) { - $propertyDescriber->setModelRegistry($this->modelRegistry); - } - if ($propertyDescriber->supports($types)) { - $propertyDescriber->describe($types, $property, $model->getGroups(), $schema, $model->getSerializationContext()); + if ($this->propertyDescriber instanceof ModelRegistryAwareInterface) { + $this->propertyDescriber->setModelRegistry($this->modelRegistry); + } + if ($this->propertyDescriber->supports($types)) { + $this->propertyDescriber->describe($types, $property, $model->getGroups(), $schema, $model->getSerializationContext()); - return; - } + return; } throw new \Exception(sprintf('Type "%s" is not supported in %s::$%s. You may use the `#[OA\Property(type="")]` annotation to specify it manually.', $types[0]->getBuiltinType(), $model->getType()->getClassName(), $propertyName)); From 50ab5f7329b1d9d5ad3306cafc7905d26978f1e6 Mon Sep 17 00:00:00 2001 From: djordy Date: Tue, 12 Nov 2024 15:03:38 +0100 Subject: [PATCH 09/11] chore: 5.x remove passing indexed array --- UPGRADE-5.0.md | 4 ++- .../FilteredRouteCollectionBuilder.php | 7 ----- .../FilteredRouteCollectionBuilderTest.php | 27 ------------------- 3 files changed, 3 insertions(+), 35 deletions(-) diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index 8bb144e81..24b216ff2 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -52,4 +52,6 @@ This parameter was deprecated since `4.25.2` ## BC BREAK: Removed `Nelmio\ApiDocBundle\Exception\UndocumentedArrayItemsException` -## BC BREAK: Changed type of parameter `$propertyDescriber` in `Nelmio\ApiDocBundle\ModelDescriber\ObjectModelDescriber::__construct()` from `PropertyDescriberInterface|PropertyDescriberInterface[]` to `PropertyDescriberInterface` \ No newline at end of file +## BC BREAK: Changed type of parameter `$propertyDescriber` in `Nelmio\ApiDocBundle\ModelDescriber\ObjectModelDescriber::__construct()` from `PropertyDescriberInterface|PropertyDescriberInterface[]` to `PropertyDescriberInterface` + +## BC BREAK: Removed passing an indexed array with a collection of path patterns as argument 1 for `Nelmio\ApiDocBundle\Routing\FilteredRouteCollectionBuilder::__construct()` \ No newline at end of file diff --git a/src/Routing/FilteredRouteCollectionBuilder.php b/src/Routing/FilteredRouteCollectionBuilder.php index 02adde0f8..4c943ad04 100644 --- a/src/Routing/FilteredRouteCollectionBuilder.php +++ b/src/Routing/FilteredRouteCollectionBuilder.php @@ -53,13 +53,6 @@ public function __construct( ->setAllowedTypes('disable_default_routes', 'boolean') ; - if (array_key_exists(0, $options)) { - trigger_deprecation('nelmio/api-doc-bundle', '3.2', 'Passing an indexed array with a collection of path patterns as argument 1 for `%s()` is deprecated since 3.2.0, expected structure is an array containing parameterized options.', __METHOD__); - - $normalizedOptions = ['path_patterns' => $options]; - $options = $normalizedOptions; - } - $this->controllerReflector = $controllerReflector; $this->area = $area; $this->options = $resolver->resolve($options); diff --git a/tests/Routing/FilteredRouteCollectionBuilderTest.php b/tests/Routing/FilteredRouteCollectionBuilderTest.php index 6fd199baa..e7f70d8f8 100644 --- a/tests/Routing/FilteredRouteCollectionBuilderTest.php +++ b/tests/Routing/FilteredRouteCollectionBuilderTest.php @@ -57,33 +57,6 @@ public function testFilter(): void self::assertCount(4, $filteredRoutes); } - /** - * @group legacy - * - * @expectedDeprecation Passing an indexed array with a collection of path patterns as argument 1 for `Nelmio\ApiDocBundle\Routing\FilteredRouteCollectionBuilder::__construct()` is deprecated since 3.2.0, expected structure is an array containing parameterized options. - */ - public function testFilterWithDeprecatedArgument(): void - { - $pathPattern = [ - '^/api/foo', - '^/api/bar', - ]; - - $routes = new RouteCollection(); - foreach ($this->getRoutes() as $name => $route) { - $routes->add($name, $route); - } - - $routeBuilder = new FilteredRouteCollectionBuilder( - $this->createControllerReflector(), - 'areaName', - $pathPattern - ); - $filteredRoutes = $routeBuilder->filter($routes); - - self::assertCount(5, $filteredRoutes); - } - /** * @param array $options */ From f4b1cfe66fd88ad9db2773237d49b2e5a49db539 Mon Sep 17 00:00:00 2001 From: djordy Date: Tue, 12 Nov 2024 15:35:22 +0100 Subject: [PATCH 10/11] chore: 5.x update PropertyDescriberInterface::describe() --- UPGRADE-5.0.md | 12 ++++++- phpstan-baseline.neon | 35 ------------------- src/ModelDescriber/ObjectModelDescriber.php | 6 ++-- .../ArrayPropertyDescriber.php | 22 ++---------- .../BooleanPropertyDescriber.php | 20 +---------- .../CompoundPropertyDescriber.php | 22 ++---------- .../DateTimePropertyDescriber.php | 20 +---------- .../DictionaryPropertyDescriber.php | 22 ++---------- .../FloatPropertyDescriber.php | 20 +---------- .../IntegerPropertyDescriber.php | 20 +---------- .../NullablePropertyDescriber.php | 22 ++---------- .../ObjectPropertyDescriber.php | 24 ++----------- src/PropertyDescriber/PropertyDescriber.php | 22 ++---------- .../PropertyDescriberInterface.php | 4 +-- .../StringPropertyDescriber.php | 20 +---------- .../UuidPropertyDescriber.php | 2 +- .../UuidPropertyDescriberTest.php | 8 +---- 17 files changed, 35 insertions(+), 266 deletions(-) diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index 24b216ff2..06d55e28f 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -54,4 +54,14 @@ This parameter was deprecated since `4.25.2` ## BC BREAK: Changed type of parameter `$propertyDescriber` in `Nelmio\ApiDocBundle\ModelDescriber\ObjectModelDescriber::__construct()` from `PropertyDescriberInterface|PropertyDescriberInterface[]` to `PropertyDescriberInterface` -## BC BREAK: Removed passing an indexed array with a collection of path patterns as argument 1 for `Nelmio\ApiDocBundle\Routing\FilteredRouteCollectionBuilder::__construct()` \ No newline at end of file +## BC BREAK: Removed passing an indexed array with a collection of path patterns as argument 1 for `Nelmio\ApiDocBundle\Routing\FilteredRouteCollectionBuilder::__construct()` + +## BC BREAK: Updated `PropertyDescriberInterface::describe()` signature +```diff +- public function describe(array $types, Schema $property, ?array $groups = null /* , ?Schema $schema = null */ /* , array $context = [] */); ++ public function describe(array $types, Schema $property, array $context = []); +``` + +`$groups` are now passed in `$context` and can be accessed via `$context['groups']`. + +`$schema` has been removed with no replacement. \ No newline at end of file diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index c45409037..980635cd9 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -5,41 +5,6 @@ parameters: count: 1 path: src/Describer/ExternalDocDescriber.php - - - message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\PropertyDescriberInterface\\:\\:describe\\(\\) invoked with 5 parameters, 2\\-3 required\\.$#" - count: 1 - path: src/PropertyDescriber/ArrayPropertyDescriber.php - - - - message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\PropertyDescriberInterface\\:\\:describe\\(\\) invoked with 5 parameters, 2\\-3 required\\.$#" - count: 1 - path: src/PropertyDescriber/CompoundPropertyDescriber.php - - - - message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\PropertyDescriberInterface\\:\\:describe\\(\\) invoked with 5 parameters, 2\\-3 required\\.$#" - count: 1 - path: src/PropertyDescriber/DictionaryPropertyDescriber.php - - - - message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\PropertyDescriberInterface\\:\\:describe\\(\\) invoked with 5 parameters, 2\\-3 required\\.$#" - count: 1 - path: src/PropertyDescriber/NullablePropertyDescriber.php - - - - message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\PropertyDescriberInterface\\:\\:describe\\(\\) invoked with 5 parameters, 2\\-3 required\\.$#" - count: 1 - path: src/PropertyDescriber/PropertyDescriber.php - - - - message: "#^PHPDoc tag @param references unknown parameter\\: \\$context$#" - count: 1 - path: src/PropertyDescriber/PropertyDescriberInterface.php - - - - message: "#^PHPDoc tag @param references unknown parameter\\: \\$schema$#" - count: 1 - path: src/PropertyDescriber/PropertyDescriberInterface.php - - message: "#^Call to method render\\(\\) on an unknown class Twig_Environment\\.$#" count: 2 diff --git a/src/ModelDescriber/ObjectModelDescriber.php b/src/ModelDescriber/ObjectModelDescriber.php index 79bddc907..17b7595d8 100644 --- a/src/ModelDescriber/ObjectModelDescriber.php +++ b/src/ModelDescriber/ObjectModelDescriber.php @@ -141,7 +141,7 @@ public function describe(Model $model, OA\Schema $schema) throw new \LogicException(sprintf('The PropertyInfo component was not able to guess the type of %s::$%s. You may need to add a `@var` annotation or use `#[OA\Property(type="")]` to make its type explicit.', $class, $propertyName)); } - $this->describeProperty($types, $model, $property, $propertyName, $schema); + $this->describeProperty($types, $model, $property, $propertyName); } $this->markRequiredProperties($schema); @@ -178,13 +178,13 @@ private function camelize(string $string): string /** * @param Type[] $types */ - private function describeProperty(array $types, Model $model, OA\Schema $property, string $propertyName, OA\Schema $schema): void + private function describeProperty(array $types, Model $model, OA\Schema $property, string $propertyName): void { if ($this->propertyDescriber instanceof ModelRegistryAwareInterface) { $this->propertyDescriber->setModelRegistry($this->modelRegistry); } if ($this->propertyDescriber->supports($types)) { - $this->propertyDescriber->describe($types, $property, $model->getGroups(), $schema, $model->getSerializationContext()); + $this->propertyDescriber->describe($types, $property, $model->getSerializationContext()); return; } diff --git a/src/PropertyDescriber/ArrayPropertyDescriber.php b/src/PropertyDescriber/ArrayPropertyDescriber.php index 7aa845503..1bae32704 100644 --- a/src/PropertyDescriber/ArrayPropertyDescriber.php +++ b/src/PropertyDescriber/ArrayPropertyDescriber.php @@ -25,26 +25,8 @@ class ArrayPropertyDescriber implements PropertyDescriberInterface, ModelRegistr /** * @param array $context Context options for describing the property */ - public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = []) + public function describe(array $types, OA\Schema $property, array $context = []) { - if (null === $schema) { - trigger_deprecation( - 'nelmio/api-doc-bundle', - '4.15.0', - '"%s()" will have a new "OA\Schema $schema" argument in a future version. Not defining it or passing null is deprecated', - __METHOD__ - ); - } - - if (null !== $groups) { - trigger_deprecation( - 'nelmio/api-doc-bundle', - '4.17.0', - 'Using the $groups parameter of "%s()" is deprecated and will be removed in a future version. Pass groups via $context[\'groups\']', - __METHOD__ - ); - } - $property->type = 'array'; /** @var OA\Items $property */ $property = Util::getChild($property, OA\Items::class); @@ -56,7 +38,7 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul continue; } - $this->propertyDescriber->describe([$type], $property, $groups, $schema, $context); + $this->propertyDescriber->describe([$type], $property, $context); } } diff --git a/src/PropertyDescriber/BooleanPropertyDescriber.php b/src/PropertyDescriber/BooleanPropertyDescriber.php index c2a430424..f80c692a9 100644 --- a/src/PropertyDescriber/BooleanPropertyDescriber.php +++ b/src/PropertyDescriber/BooleanPropertyDescriber.php @@ -19,26 +19,8 @@ class BooleanPropertyDescriber implements PropertyDescriberInterface /** * @param array $context Context options for describing the property */ - public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = []) + public function describe(array $types, OA\Schema $property, array $context = []) { - if (null === $schema) { - trigger_deprecation( - 'nelmio/api-doc-bundle', - '4.15.0', - '"%s()" will have a new "OA\Schema $schema" argument in a future version. Not defining it or passing null is deprecated', - __METHOD__ - ); - } - - if (null !== $groups) { - trigger_deprecation( - 'nelmio/api-doc-bundle', - '4.17.0', - 'Using the $groups parameter of "%s()" is deprecated and will be removed in a future version. Pass groups via $context[\'groups\']', - __METHOD__ - ); - } - $property->type = 'boolean'; } diff --git a/src/PropertyDescriber/CompoundPropertyDescriber.php b/src/PropertyDescriber/CompoundPropertyDescriber.php index 799394f09..3d8be77c6 100644 --- a/src/PropertyDescriber/CompoundPropertyDescriber.php +++ b/src/PropertyDescriber/CompoundPropertyDescriber.php @@ -25,32 +25,14 @@ class CompoundPropertyDescriber implements PropertyDescriberInterface, ModelRegi /** * @param array $context Context options for describing the property */ - public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = []) + public function describe(array $types, OA\Schema $property, array $context = []) { - if (null === $schema) { - trigger_deprecation( - 'nelmio/api-doc-bundle', - '4.15.0', - '"%s()" will have a new "OA\Schema $schema" argument in a future version. Not defining it or passing null is deprecated', - __METHOD__ - ); - } - - if (null !== $groups) { - trigger_deprecation( - 'nelmio/api-doc-bundle', - '4.17.0', - 'Using the $groups parameter of "%s()" is deprecated and will be removed in a future version. Pass groups via $context[\'groups\']', - __METHOD__ - ); - } - $property->oneOf = Generator::UNDEFINED !== $property->oneOf ? $property->oneOf : []; foreach ($types as $type) { $property->oneOf[] = $schema = Util::createChild($property, OA\Schema::class, []); - $this->propertyDescriber->describe([$type], $schema, $groups, $schema, $context); + $this->propertyDescriber->describe([$type], $schema, $context); } } diff --git a/src/PropertyDescriber/DateTimePropertyDescriber.php b/src/PropertyDescriber/DateTimePropertyDescriber.php index 8b15f8ad4..449beeb14 100644 --- a/src/PropertyDescriber/DateTimePropertyDescriber.php +++ b/src/PropertyDescriber/DateTimePropertyDescriber.php @@ -19,26 +19,8 @@ class DateTimePropertyDescriber implements PropertyDescriberInterface /** * @param array $context Context options for describing the property */ - public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = []) + public function describe(array $types, OA\Schema $property, array $context = []) { - if (null === $schema) { - trigger_deprecation( - 'nelmio/api-doc-bundle', - '4.15.0', - '"%s()" will have a new "OA\Schema $schema" argument in a future version. Not defining it or passing null is deprecated', - __METHOD__ - ); - } - - if (null !== $groups) { - trigger_deprecation( - 'nelmio/api-doc-bundle', - '4.17.0', - 'Using the $groups parameter of "%s()" is deprecated and will be removed in a future version. Pass groups via $context[\'groups\']', - __METHOD__ - ); - } - $property->type = 'string'; $property->format = 'date-time'; } diff --git a/src/PropertyDescriber/DictionaryPropertyDescriber.php b/src/PropertyDescriber/DictionaryPropertyDescriber.php index bc5488b30..dc1c73b85 100644 --- a/src/PropertyDescriber/DictionaryPropertyDescriber.php +++ b/src/PropertyDescriber/DictionaryPropertyDescriber.php @@ -25,31 +25,13 @@ final class DictionaryPropertyDescriber implements PropertyDescriberInterface, M /** * @param array $context Context options for describing the property */ - public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = []) + public function describe(array $types, OA\Schema $property, array $context = []) { - if (null === $schema) { - trigger_deprecation( - 'nelmio/api-doc-bundle', - '4.15.0', - '"%s()" will have a new "OA\Schema $schema" argument in a future version. Not defining it or passing null is deprecated', - __METHOD__ - ); - } - - if (null !== $groups) { - trigger_deprecation( - 'nelmio/api-doc-bundle', - '4.17.0', - 'Using the $groups parameter of "%s()" is deprecated and will be removed in a future version. Pass groups via $context[\'groups\']', - __METHOD__ - ); - } - $property->type = 'object'; /** @var OA\AdditionalProperties $additionalProperties */ $additionalProperties = Util::getChild($property, OA\AdditionalProperties::class); - $this->propertyDescriber->describe($types[0]->getCollectionValueTypes(), $additionalProperties, $groups, $schema, $context); + $this->propertyDescriber->describe($types[0]->getCollectionValueTypes(), $additionalProperties, $context); } public function supports(array $types): bool diff --git a/src/PropertyDescriber/FloatPropertyDescriber.php b/src/PropertyDescriber/FloatPropertyDescriber.php index 7e50d4655..897d86440 100644 --- a/src/PropertyDescriber/FloatPropertyDescriber.php +++ b/src/PropertyDescriber/FloatPropertyDescriber.php @@ -19,26 +19,8 @@ class FloatPropertyDescriber implements PropertyDescriberInterface /** * @param array $context Context options for describing the property */ - public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = []) + public function describe(array $types, OA\Schema $property, array $context = []) { - if (null === $schema) { - trigger_deprecation( - 'nelmio/api-doc-bundle', - '4.15.0', - '"%s()" will have a new "OA\Schema $schema" argument in a future version. Not defining it or passing null is deprecated', - __METHOD__ - ); - } - - if (null !== $groups) { - trigger_deprecation( - 'nelmio/api-doc-bundle', - '4.17.0', - 'Using the $groups parameter of "%s()" is deprecated and will be removed in a future version. Pass groups via $context[\'groups\']', - __METHOD__ - ); - } - $property->type = 'number'; $property->format = 'float'; } diff --git a/src/PropertyDescriber/IntegerPropertyDescriber.php b/src/PropertyDescriber/IntegerPropertyDescriber.php index c6fac745f..922cc9d1e 100644 --- a/src/PropertyDescriber/IntegerPropertyDescriber.php +++ b/src/PropertyDescriber/IntegerPropertyDescriber.php @@ -19,26 +19,8 @@ class IntegerPropertyDescriber implements PropertyDescriberInterface /** * @param array $context Context options for describing the property */ - public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = []) + public function describe(array $types, OA\Schema $property, array $context = []) { - if (null === $schema) { - trigger_deprecation( - 'nelmio/api-doc-bundle', - '4.15.0', - '"%s()" will have a new "OA\Schema $schema" argument in a future version. Not defining it or passing null is deprecated', - __METHOD__ - ); - } - - if (null !== $groups) { - trigger_deprecation( - 'nelmio/api-doc-bundle', - '4.17.0', - 'Using the $groups parameter of "%s()" is deprecated and will be removed in a future version. Pass groups via $context[\'groups\']', - __METHOD__ - ); - } - $property->type = 'integer'; } diff --git a/src/PropertyDescriber/NullablePropertyDescriber.php b/src/PropertyDescriber/NullablePropertyDescriber.php index 299e04b6b..3a53f4053 100644 --- a/src/PropertyDescriber/NullablePropertyDescriber.php +++ b/src/PropertyDescriber/NullablePropertyDescriber.php @@ -21,31 +21,13 @@ final class NullablePropertyDescriber implements PropertyDescriberInterface, Pro /** * @param array $context Context options for describing the property */ - public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = []) + public function describe(array $types, OA\Schema $property, array $context = []) { - if (null === $schema) { - trigger_deprecation( - 'nelmio/api-doc-bundle', - '4.15.0', - '"%s()" will have a new "OA\Schema $schema" argument in a future version. Not defining it or passing null is deprecated', - __METHOD__ - ); - } - - if (null !== $groups) { - trigger_deprecation( - 'nelmio/api-doc-bundle', - '4.17.0', - 'Using the $groups parameter of "%s()" is deprecated and will be removed in a future version. Pass groups via $context[\'groups\']', - __METHOD__ - ); - } - if (Generator::UNDEFINED === $property->nullable) { $property->nullable = true; } - $this->propertyDescriber->describe($types, $property, $groups, $schema, $context); + $this->propertyDescriber->describe($types, $property, $context); } public function supports(array $types): bool diff --git a/src/PropertyDescriber/ObjectPropertyDescriber.php b/src/PropertyDescriber/ObjectPropertyDescriber.php index 09385fff9..60de8c360 100644 --- a/src/PropertyDescriber/ObjectPropertyDescriber.php +++ b/src/PropertyDescriber/ObjectPropertyDescriber.php @@ -25,26 +25,8 @@ class ObjectPropertyDescriber implements PropertyDescriberInterface, ModelRegist /** * @param array $context Context options for describing the property */ - public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = []) + public function describe(array $types, OA\Schema $property, array $context = []) { - if (null === $schema) { - trigger_deprecation( - 'nelmio/api-doc-bundle', - '4.15.0', - '"%s()" will have a new "OA\Schema $schema" argument in a future version. Not defining it or passing null is deprecated', - __METHOD__ - ); - } - - if (null !== $groups) { - trigger_deprecation( - 'nelmio/api-doc-bundle', - '4.17.0', - 'Using the $groups parameter of "%s()" is deprecated and will be removed in a future version. Pass groups via $context[\'groups\']', - __METHOD__ - ); - } - $type = new Type( $types[0]->getBuiltinType(), false, @@ -56,13 +38,13 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul if ($types[0]->isNullable()) { $weakContext = Util::createWeakContext($property->_context); - $schemas = [new OA\Schema(['ref' => $this->modelRegistry->register(new Model($type, $groups, [], $context)), '_context' => $weakContext])]; + $schemas = [new OA\Schema(['ref' => $this->modelRegistry->register(new Model($type, serializationContext: $context)), '_context' => $weakContext])]; $property->oneOf = $schemas; return; } - $property->ref = $this->modelRegistry->register(new Model($type, $groups, [], $context)); + $property->ref = $this->modelRegistry->register(new Model($type, serializationContext: $context)); } public function supports(array $types): bool diff --git a/src/PropertyDescriber/PropertyDescriber.php b/src/PropertyDescriber/PropertyDescriber.php index 801aaaf95..44a5676a2 100644 --- a/src/PropertyDescriber/PropertyDescriber.php +++ b/src/PropertyDescriber/PropertyDescriber.php @@ -40,32 +40,14 @@ public function __construct( /** * @param array $context Context options for describing the property */ - public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = []): void + public function describe(array $types, OA\Schema $property, array $context = []): void { - if (null === $schema) { - trigger_deprecation( - 'nelmio/api-doc-bundle', - '4.15.0', - '"%s()" will have a new "OA\Schema $schema" argument in a future version. Not defining it or passing null is deprecated', - __METHOD__ - ); - } - - if (null !== $groups) { - trigger_deprecation( - 'nelmio/api-doc-bundle', - '4.17.0', - 'Using the $groups parameter of "%s()" is deprecated and will be removed in a future version. Pass groups via $context[\'groups\']', - __METHOD__ - ); - } - if (null === $propertyDescriber = $this->getPropertyDescriber($types)) { return; } $this->called[$this->getHash($types)][] = $propertyDescriber; - $propertyDescriber->describe($types, $property, $groups, $schema, $context); + $propertyDescriber->describe($types, $property, $context); $this->called = []; // Reset recursion helper } diff --git a/src/PropertyDescriber/PropertyDescriberInterface.php b/src/PropertyDescriber/PropertyDescriberInterface.php index feac04bb3..05dc49a71 100644 --- a/src/PropertyDescriber/PropertyDescriberInterface.php +++ b/src/PropertyDescriber/PropertyDescriberInterface.php @@ -18,13 +18,11 @@ interface PropertyDescriberInterface { /** * @param Type[] $types - * @param string[]|null $groups Deprecated use $context['groups'] instead - * @param Schema $schema Allows to make changes inside of the schema (e.g. adding required fields) * @param array $context Context options for describing the property * * @return void */ - public function describe(array $types, Schema $property, ?array $groups = null /* , ?Schema $schema = null */ /* , array $context = [] */); + public function describe(array $types, Schema $property, array $context = []); /** * @param Type[] $types diff --git a/src/PropertyDescriber/StringPropertyDescriber.php b/src/PropertyDescriber/StringPropertyDescriber.php index 6c21c4326..ad895b9b8 100644 --- a/src/PropertyDescriber/StringPropertyDescriber.php +++ b/src/PropertyDescriber/StringPropertyDescriber.php @@ -19,26 +19,8 @@ class StringPropertyDescriber implements PropertyDescriberInterface /** * @param array $context Context options for describing the property */ - public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = []) + public function describe(array $types, OA\Schema $property, array $context = []) { - if (null === $schema) { - trigger_deprecation( - 'nelmio/api-doc-bundle', - '4.15.0', - '"%s()" will have a new "OA\Schema $schema" argument in a future version. Not defining it or passing null is deprecated', - __METHOD__ - ); - } - - if (null !== $groups) { - trigger_deprecation( - 'nelmio/api-doc-bundle', - '4.17.0', - 'Using the $groups parameter of "%s()" is deprecated and will be removed in a future version. Pass groups via $context[\'groups\']', - __METHOD__ - ); - } - $property->type = 'string'; } diff --git a/src/PropertyDescriber/UuidPropertyDescriber.php b/src/PropertyDescriber/UuidPropertyDescriber.php index 843d4ef63..097f0503d 100644 --- a/src/PropertyDescriber/UuidPropertyDescriber.php +++ b/src/PropertyDescriber/UuidPropertyDescriber.php @@ -20,7 +20,7 @@ final class UuidPropertyDescriber implements PropertyDescriberInterface /** * @param array $context Context options for describing the property */ - public function describe(array $types, OA\Schema $property, ?array $groups = null, ?OA\Schema $schema = null, array $context = []) + public function describe(array $types, OA\Schema $property, array $context = []) { $property->type = 'string'; $property->format = 'uuid'; diff --git a/tests/PropertyDescriber/UuidPropertyDescriberTest.php b/tests/PropertyDescriber/UuidPropertyDescriberTest.php index 89ef2ecbb..e3980daa6 100644 --- a/tests/PropertyDescriber/UuidPropertyDescriberTest.php +++ b/tests/PropertyDescriber/UuidPropertyDescriberTest.php @@ -48,10 +48,9 @@ public function testSupportsNoDifferentObjectPropertyType(): void public function testDescribeUuidPropertyType(): void { $property = $this->initProperty(); - $schema = $this->initSchema(); $describer = new UuidPropertyDescriber(); - $describer->describe([], $property, [], $schema); + $describer->describe([], $property, []); self::assertSame('string', $property->type); self::assertSame('uuid', $property->format); @@ -61,9 +60,4 @@ private function initProperty(): \OpenApi\Annotations\Property { return new \OpenApi\Attributes\Property(); // union types, used in schema attribute require PHP >= 8.0.0 } - - private function initSchema(): \OpenApi\Annotations\Schema - { - return new \OpenApi\Attributes\Schema(); // union types, used in schema attribute require PHP >= 8.0.0 - } } From 7acd32cb2615463a76c12239315a1974f2da671e Mon Sep 17 00:00:00 2001 From: djordy Date: Tue, 12 Nov 2024 16:03:06 +0100 Subject: [PATCH 11/11] chore: 5.x update PropertyDescriberInterface::supports() --- UPGRADE-5.0.md | 11 +++++++++-- src/ModelDescriber/ObjectModelDescriber.php | 2 +- src/PropertyDescriber/ArrayPropertyDescriber.php | 4 ++-- src/PropertyDescriber/BooleanPropertyDescriber.php | 2 +- src/PropertyDescriber/CompoundPropertyDescriber.php | 2 +- src/PropertyDescriber/DateTimePropertyDescriber.php | 2 +- .../DictionaryPropertyDescriber.php | 2 +- src/PropertyDescriber/FloatPropertyDescriber.php | 2 +- src/PropertyDescriber/IntegerPropertyDescriber.php | 2 +- src/PropertyDescriber/NullablePropertyDescriber.php | 2 +- src/PropertyDescriber/ObjectPropertyDescriber.php | 2 +- src/PropertyDescriber/PropertyDescriber.php | 13 +++++++------ .../PropertyDescriberInterface.php | 5 +++-- src/PropertyDescriber/StringPropertyDescriber.php | 2 +- src/PropertyDescriber/UuidPropertyDescriber.php | 2 +- 15 files changed, 32 insertions(+), 23 deletions(-) diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index 06d55e28f..d76b0ec65 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -62,6 +62,13 @@ This parameter was deprecated since `4.25.2` + public function describe(array $types, Schema $property, array $context = []); ``` -`$groups` are now passed in `$context` and can be accessed via `$context['groups']`. +`$groups` are passed in `$context` and can be accessed via `$context['groups']`. -`$schema` has been removed with no replacement. \ No newline at end of file +`$schema` has been removed with no replacement. + +## BC BREAK: Updated `PropertyDescriberInterface::supports()` signature +Future proofing for potential future changes and keeping it consistent with `describe()`. +```diff +- public function supports(array $types): bool; ++ public function supports(array $types, array $context = []): bool; +``` \ No newline at end of file diff --git a/src/ModelDescriber/ObjectModelDescriber.php b/src/ModelDescriber/ObjectModelDescriber.php index 17b7595d8..6a33149b2 100644 --- a/src/ModelDescriber/ObjectModelDescriber.php +++ b/src/ModelDescriber/ObjectModelDescriber.php @@ -183,7 +183,7 @@ private function describeProperty(array $types, Model $model, OA\Schema $propert if ($this->propertyDescriber instanceof ModelRegistryAwareInterface) { $this->propertyDescriber->setModelRegistry($this->modelRegistry); } - if ($this->propertyDescriber->supports($types)) { + if ($this->propertyDescriber->supports($types, $model->getSerializationContext())) { $this->propertyDescriber->describe($types, $property, $model->getSerializationContext()); return; diff --git a/src/PropertyDescriber/ArrayPropertyDescriber.php b/src/PropertyDescriber/ArrayPropertyDescriber.php index 1bae32704..78f46e1d6 100644 --- a/src/PropertyDescriber/ArrayPropertyDescriber.php +++ b/src/PropertyDescriber/ArrayPropertyDescriber.php @@ -34,7 +34,7 @@ public function describe(array $types, OA\Schema $property, array $context = []) foreach ($types[0]->getCollectionValueTypes() as $type) { // Handle list pseudo type // https://symfony.com/doc/current/components/property_info.html#type-getcollectionkeytypes-type-getcollectionvaluetypes - if ($this->supports([$type]) && [] === $type->getCollectionValueTypes()) { + if ($this->supports([$type], $context) && [] === $type->getCollectionValueTypes()) { continue; } @@ -42,7 +42,7 @@ public function describe(array $types, OA\Schema $property, array $context = []) } } - public function supports(array $types): bool + public function supports(array $types, array $context = []): bool { if (1 !== count($types) || !$types[0]->isCollection()) { return false; diff --git a/src/PropertyDescriber/BooleanPropertyDescriber.php b/src/PropertyDescriber/BooleanPropertyDescriber.php index f80c692a9..bc493e087 100644 --- a/src/PropertyDescriber/BooleanPropertyDescriber.php +++ b/src/PropertyDescriber/BooleanPropertyDescriber.php @@ -24,7 +24,7 @@ public function describe(array $types, OA\Schema $property, array $context = []) $property->type = 'boolean'; } - public function supports(array $types): bool + public function supports(array $types, array $context = []): bool { return 1 === count($types) && Type::BUILTIN_TYPE_BOOL === $types[0]->getBuiltinType(); } diff --git a/src/PropertyDescriber/CompoundPropertyDescriber.php b/src/PropertyDescriber/CompoundPropertyDescriber.php index 3d8be77c6..8cf5c4b54 100644 --- a/src/PropertyDescriber/CompoundPropertyDescriber.php +++ b/src/PropertyDescriber/CompoundPropertyDescriber.php @@ -36,7 +36,7 @@ public function describe(array $types, OA\Schema $property, array $context = []) } } - public function supports(array $types): bool + public function supports(array $types, array $context = []): bool { return count($types) >= 2; } diff --git a/src/PropertyDescriber/DateTimePropertyDescriber.php b/src/PropertyDescriber/DateTimePropertyDescriber.php index 449beeb14..50ade7408 100644 --- a/src/PropertyDescriber/DateTimePropertyDescriber.php +++ b/src/PropertyDescriber/DateTimePropertyDescriber.php @@ -25,7 +25,7 @@ public function describe(array $types, OA\Schema $property, array $context = []) $property->format = 'date-time'; } - public function supports(array $types): bool + public function supports(array $types, array $context = []): bool { return 1 === count($types) && Type::BUILTIN_TYPE_OBJECT === $types[0]->getBuiltinType() diff --git a/src/PropertyDescriber/DictionaryPropertyDescriber.php b/src/PropertyDescriber/DictionaryPropertyDescriber.php index dc1c73b85..18785d174 100644 --- a/src/PropertyDescriber/DictionaryPropertyDescriber.php +++ b/src/PropertyDescriber/DictionaryPropertyDescriber.php @@ -34,7 +34,7 @@ public function describe(array $types, OA\Schema $property, array $context = []) $this->propertyDescriber->describe($types[0]->getCollectionValueTypes(), $additionalProperties, $context); } - public function supports(array $types): bool + public function supports(array $types, array $context = []): bool { return 1 === count($types) && $types[0]->isCollection() diff --git a/src/PropertyDescriber/FloatPropertyDescriber.php b/src/PropertyDescriber/FloatPropertyDescriber.php index 897d86440..7dc29cf1d 100644 --- a/src/PropertyDescriber/FloatPropertyDescriber.php +++ b/src/PropertyDescriber/FloatPropertyDescriber.php @@ -25,7 +25,7 @@ public function describe(array $types, OA\Schema $property, array $context = []) $property->format = 'float'; } - public function supports(array $types): bool + public function supports(array $types, array $context = []): bool { return 1 === count($types) && Type::BUILTIN_TYPE_FLOAT === $types[0]->getBuiltinType(); } diff --git a/src/PropertyDescriber/IntegerPropertyDescriber.php b/src/PropertyDescriber/IntegerPropertyDescriber.php index 922cc9d1e..4d20443b9 100644 --- a/src/PropertyDescriber/IntegerPropertyDescriber.php +++ b/src/PropertyDescriber/IntegerPropertyDescriber.php @@ -24,7 +24,7 @@ public function describe(array $types, OA\Schema $property, array $context = []) $property->type = 'integer'; } - public function supports(array $types): bool + public function supports(array $types, array $context = []): bool { return 1 === count($types) && Type::BUILTIN_TYPE_INT === $types[0]->getBuiltinType(); } diff --git a/src/PropertyDescriber/NullablePropertyDescriber.php b/src/PropertyDescriber/NullablePropertyDescriber.php index 3a53f4053..332983b8e 100644 --- a/src/PropertyDescriber/NullablePropertyDescriber.php +++ b/src/PropertyDescriber/NullablePropertyDescriber.php @@ -30,7 +30,7 @@ public function describe(array $types, OA\Schema $property, array $context = []) $this->propertyDescriber->describe($types, $property, $context); } - public function supports(array $types): bool + public function supports(array $types, array $context = []): bool { foreach ($types as $type) { if ($type->isNullable()) { diff --git a/src/PropertyDescriber/ObjectPropertyDescriber.php b/src/PropertyDescriber/ObjectPropertyDescriber.php index 60de8c360..2b2084415 100644 --- a/src/PropertyDescriber/ObjectPropertyDescriber.php +++ b/src/PropertyDescriber/ObjectPropertyDescriber.php @@ -47,7 +47,7 @@ public function describe(array $types, OA\Schema $property, array $context = []) $property->ref = $this->modelRegistry->register(new Model($type, serializationContext: $context)); } - public function supports(array $types): bool + public function supports(array $types, array $context = []): bool { return 1 === count($types) && Type::BUILTIN_TYPE_OBJECT === $types[0]->getBuiltinType(); diff --git a/src/PropertyDescriber/PropertyDescriber.php b/src/PropertyDescriber/PropertyDescriber.php index 44a5676a2..f748aed1e 100644 --- a/src/PropertyDescriber/PropertyDescriber.php +++ b/src/PropertyDescriber/PropertyDescriber.php @@ -42,7 +42,7 @@ public function __construct( */ public function describe(array $types, OA\Schema $property, array $context = []): void { - if (null === $propertyDescriber = $this->getPropertyDescriber($types)) { + if (null === $propertyDescriber = $this->getPropertyDescriber($types, $context)) { return; } @@ -51,9 +51,9 @@ public function describe(array $types, OA\Schema $property, array $context = []) $this->called = []; // Reset recursion helper } - public function supports(array $types): bool + public function supports(array $types, array $context = []): bool { - return null !== $this->getPropertyDescriber($types); + return null !== $this->getPropertyDescriber($types, $context); } /** @@ -65,9 +65,10 @@ private function getHash(array $types): string } /** - * @param Type[] $types + * @param Type[] $types + * @param array $context */ - private function getPropertyDescriber(array $types): ?PropertyDescriberInterface + private function getPropertyDescriber(array $types, array $context): ?PropertyDescriberInterface { foreach ($this->propertyDescribers as $propertyDescriber) { /* BC layer for Symfony < 6.3 @see https://symfony.com/doc/6.3/service_container/tags.html#reference-tagged-services */ @@ -90,7 +91,7 @@ private function getPropertyDescriber(array $types): ?PropertyDescriberInterface $propertyDescriber->setPropertyDescriber($this); } - if ($propertyDescriber->supports($types)) { + if ($propertyDescriber->supports($types, $context)) { return $propertyDescriber; } } diff --git a/src/PropertyDescriber/PropertyDescriberInterface.php b/src/PropertyDescriber/PropertyDescriberInterface.php index 05dc49a71..2a3c3ff4a 100644 --- a/src/PropertyDescriber/PropertyDescriberInterface.php +++ b/src/PropertyDescriber/PropertyDescriberInterface.php @@ -25,7 +25,8 @@ interface PropertyDescriberInterface public function describe(array $types, Schema $property, array $context = []); /** - * @param Type[] $types + * @param Type[] $types + * @param array $context Context options for describing the property */ - public function supports(array $types): bool; + public function supports(array $types, array $context = []): bool; } diff --git a/src/PropertyDescriber/StringPropertyDescriber.php b/src/PropertyDescriber/StringPropertyDescriber.php index ad895b9b8..73841efff 100644 --- a/src/PropertyDescriber/StringPropertyDescriber.php +++ b/src/PropertyDescriber/StringPropertyDescriber.php @@ -24,7 +24,7 @@ public function describe(array $types, OA\Schema $property, array $context = []) $property->type = 'string'; } - public function supports(array $types): bool + public function supports(array $types, array $context = []): bool { return 1 === count($types) && Type::BUILTIN_TYPE_STRING === $types[0]->getBuiltinType(); } diff --git a/src/PropertyDescriber/UuidPropertyDescriber.php b/src/PropertyDescriber/UuidPropertyDescriber.php index 097f0503d..e57f69f3e 100644 --- a/src/PropertyDescriber/UuidPropertyDescriber.php +++ b/src/PropertyDescriber/UuidPropertyDescriber.php @@ -26,7 +26,7 @@ public function describe(array $types, OA\Schema $property, array $context = []) $property->format = 'uuid'; } - public function supports(array $types): bool + public function supports(array $types, array $context = []): bool { return 1 === count($types) && Type::BUILTIN_TYPE_OBJECT === $types[0]->getBuiltinType()