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 - } }