From abd21f3025ef1a4908d8a674296c26d37986b63e Mon Sep 17 00:00:00 2001 From: Djordy Koert Date: Tue, 12 Nov 2024 16:11:26 +0100 Subject: [PATCH] chore: [5.x] remove deprecations (#2388) ## Description Removes all deprecations from `4.x` ## What type of PR is this? (check all applicable) - [ ] Bug Fix - [ ] Feature - [ ] Refactor - [ ] Deprecation - [x] Breaking Change - [ ] Documentation Update - [ ] CI ## Checklist - [ ] I have made corresponding changes to the documentation (`docs/`) - [x] I have made corresponding changes to the changelog (`CHANGELOG.md`) --- UPGRADE-5.0.md | 35 ++++++++ phpstan-baseline.neon | 40 --------- src/Attribute/Model.php | 7 +- src/Describer/OpenApiPhpDescriber.php | 6 +- .../UndocumentedArrayItemsException.php | 58 ------------- src/Form/Extension/DocumentationExtension.php | 18 ---- src/Model/Model.php | 9 +- src/ModelDescriber/ObjectModelDescriber.php | 34 +++----- .../ArrayPropertyDescriber.php | 26 +----- .../BooleanPropertyDescriber.php | 22 +---- .../CompoundPropertyDescriber.php | 24 +----- .../DateTimePropertyDescriber.php | 22 +---- .../DictionaryPropertyDescriber.php | 24 +----- .../FloatPropertyDescriber.php | 22 +---- .../IntegerPropertyDescriber.php | 22 +---- .../NullablePropertyDescriber.php | 24 +----- .../NullablePropertyTrait.php | 62 ------------- .../ObjectPropertyDescriber.php | 26 +----- src/PropertyDescriber/PropertyDescriber.php | 35 ++------ .../PropertyDescriberInterface.php | 9 +- .../RequiredPropertyDescriber.php | 73 ---------------- .../StringPropertyDescriber.php | 22 +---- .../UuidPropertyDescriber.php | 4 +- .../FilteredRouteCollectionBuilder.php | 7 -- .../Controller/DeprecationController.php | 31 ------- tests/Functional/ControllerTest.php | 7 -- .../Fixtures/DeprecationController.json | 86 ------------------- tests/Model/ModelRegistryTest.php | 2 +- .../UuidPropertyDescriberTest.php | 8 +- .../FilteredRouteCollectionBuilderTest.php | 27 ------ 30 files changed, 93 insertions(+), 699 deletions(-) delete mode 100644 src/Exception/UndocumentedArrayItemsException.php delete mode 100644 src/PropertyDescriber/NullablePropertyTrait.php delete mode 100644 src/PropertyDescriber/RequiredPropertyDescriber.php 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 8f132674a..d76b0ec65 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -36,4 +36,39 @@ nelmio_api_doc: - ^/api/foo - with_annotation: true + with_attribute: true +``` + +## 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` + +## BC BREAK: Removed `Nelmio\ApiDocBundle\PropertyDescriber\RequiredPropertyDescriber` + +## 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()` + +## 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` + +## 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 passed in `$context` and can be accessed via `$context['groups']`. + +`$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/phpstan-baseline.neon b/phpstan-baseline.neon index 8f22ab9b4..980635cd9 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -5,46 +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: "#^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/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/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; 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; - } -} 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]; diff --git a/src/Model/Model.php b/src/Model/Model.php index 1a911d156..304bdf672 100644 --- a/src/Model/Model.php +++ b/src/Model/Model.php @@ -29,16 +29,11 @@ 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 = []) + 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/src/ModelDescriber/ObjectModelDescriber.php b/src/ModelDescriber/ObjectModelDescriber.php index 47253a84a..6a33149b2 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; @@ -151,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); @@ -188,19 +178,15 @@ 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 { - $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, $model->getSerializationContext())) { + $this->propertyDescriber->describe($types, $property, $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)); diff --git a/src/PropertyDescriber/ArrayPropertyDescriber.php b/src/PropertyDescriber/ArrayPropertyDescriber.php index 7aa845503..78f46e1d6 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); @@ -52,15 +34,15 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul 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; } - $this->propertyDescriber->describe([$type], $property, $groups, $schema, $context); + $this->propertyDescriber->describe([$type], $property, $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 c2a430424..bc493e087 100644 --- a/src/PropertyDescriber/BooleanPropertyDescriber.php +++ b/src/PropertyDescriber/BooleanPropertyDescriber.php @@ -19,30 +19,12 @@ 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'; } - 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 799394f09..8cf5c4b54 100644 --- a/src/PropertyDescriber/CompoundPropertyDescriber.php +++ b/src/PropertyDescriber/CompoundPropertyDescriber.php @@ -25,36 +25,18 @@ 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); } } - 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 8b15f8ad4..50ade7408 100644 --- a/src/PropertyDescriber/DateTimePropertyDescriber.php +++ b/src/PropertyDescriber/DateTimePropertyDescriber.php @@ -19,31 +19,13 @@ 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'; } - 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 bc5488b30..18785d174 100644 --- a/src/PropertyDescriber/DictionaryPropertyDescriber.php +++ b/src/PropertyDescriber/DictionaryPropertyDescriber.php @@ -25,34 +25,16 @@ 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 + 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 7e50d4655..7dc29cf1d 100644 --- a/src/PropertyDescriber/FloatPropertyDescriber.php +++ b/src/PropertyDescriber/FloatPropertyDescriber.php @@ -19,31 +19,13 @@ 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'; } - 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 c6fac745f..4d20443b9 100644 --- a/src/PropertyDescriber/IntegerPropertyDescriber.php +++ b/src/PropertyDescriber/IntegerPropertyDescriber.php @@ -19,30 +19,12 @@ 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'; } - 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 299e04b6b..332983b8e 100644 --- a/src/PropertyDescriber/NullablePropertyDescriber.php +++ b/src/PropertyDescriber/NullablePropertyDescriber.php @@ -21,34 +21,16 @@ 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 + public function supports(array $types, array $context = []): bool { foreach ($types as $type) { if ($type->isNullable()) { 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)); - } - } -} diff --git a/src/PropertyDescriber/ObjectPropertyDescriber.php b/src/PropertyDescriber/ObjectPropertyDescriber.php index 09385fff9..2b2084415 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,16 +38,16 @@ 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 + 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 801aaaf95..f748aed1e 100644 --- a/src/PropertyDescriber/PropertyDescriber.php +++ b/src/PropertyDescriber/PropertyDescriber.php @@ -40,38 +40,20 @@ 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)) { + if (null === $propertyDescriber = $this->getPropertyDescriber($types, $context)) { return; } $this->called[$this->getHash($types)][] = $propertyDescriber; - $propertyDescriber->describe($types, $property, $groups, $schema, $context); + $propertyDescriber->describe($types, $property, $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); } /** @@ -83,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 */ @@ -108,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 feac04bb3..2a3c3ff4a 100644 --- a/src/PropertyDescriber/PropertyDescriberInterface.php +++ b/src/PropertyDescriber/PropertyDescriberInterface.php @@ -18,16 +18,15 @@ 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 + * @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/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; - } -} diff --git a/src/PropertyDescriber/StringPropertyDescriber.php b/src/PropertyDescriber/StringPropertyDescriber.php index 6c21c4326..73841efff 100644 --- a/src/PropertyDescriber/StringPropertyDescriber.php +++ b/src/PropertyDescriber/StringPropertyDescriber.php @@ -19,30 +19,12 @@ 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'; } - 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 843d4ef63..e57f69f3e 100644 --- a/src/PropertyDescriber/UuidPropertyDescriber.php +++ b/src/PropertyDescriber/UuidPropertyDescriber.php @@ -20,13 +20,13 @@ 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'; } - 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/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/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'])); } 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 - } } 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 */