From 5f11f3a00ee47f7d9e9bb0cf7b71fad6e0cebd5e Mon Sep 17 00:00:00 2001 From: djordy Date: Tue, 12 Nov 2024 16:03:06 +0100 Subject: [PATCH 1/4] chore: 5.x update PropertyDescriberInterface::supports() --- 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 +- 14 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/ModelDescriber/ObjectModelDescriber.php b/src/ModelDescriber/ObjectModelDescriber.php index 309def099..6e486c729 100644 --- a/src/ModelDescriber/ObjectModelDescriber.php +++ b/src/ModelDescriber/ObjectModelDescriber.php @@ -201,7 +201,7 @@ private function describeProperty(array $types, Model $model, OA\Schema $propert if ($propertyDescriber instanceof ModelRegistryAwareInterface) { $propertyDescriber->setModelRegistry($this->modelRegistry); } - if ($propertyDescriber->supports($types)) { + if ($propertyDescriber->supports($types, $model->getSerializationContext())) { $propertyDescriber->describe($types, $property, $model->getGroups(), $schema, $model->getSerializationContext()); return; diff --git a/src/PropertyDescriber/ArrayPropertyDescriber.php b/src/PropertyDescriber/ArrayPropertyDescriber.php index 7aa845503..2fcf7a0e5 100644 --- a/src/PropertyDescriber/ArrayPropertyDescriber.php +++ b/src/PropertyDescriber/ArrayPropertyDescriber.php @@ -52,7 +52,7 @@ 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; } @@ -60,7 +60,7 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul } } - 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..32c522ccc 100644 --- a/src/PropertyDescriber/BooleanPropertyDescriber.php +++ b/src/PropertyDescriber/BooleanPropertyDescriber.php @@ -42,7 +42,7 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul $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..cac6fd0f7 100644 --- a/src/PropertyDescriber/CompoundPropertyDescriber.php +++ b/src/PropertyDescriber/CompoundPropertyDescriber.php @@ -54,7 +54,7 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul } } - 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..fc452ead6 100644 --- a/src/PropertyDescriber/DateTimePropertyDescriber.php +++ b/src/PropertyDescriber/DateTimePropertyDescriber.php @@ -43,7 +43,7 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul $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..4c687a8fc 100644 --- a/src/PropertyDescriber/DictionaryPropertyDescriber.php +++ b/src/PropertyDescriber/DictionaryPropertyDescriber.php @@ -52,7 +52,7 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul $this->propertyDescriber->describe($types[0]->getCollectionValueTypes(), $additionalProperties, $groups, $schema, $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..6b95ec7ac 100644 --- a/src/PropertyDescriber/FloatPropertyDescriber.php +++ b/src/PropertyDescriber/FloatPropertyDescriber.php @@ -43,7 +43,7 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul $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..0d503e366 100644 --- a/src/PropertyDescriber/IntegerPropertyDescriber.php +++ b/src/PropertyDescriber/IntegerPropertyDescriber.php @@ -42,7 +42,7 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul $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..d34fa69b4 100644 --- a/src/PropertyDescriber/NullablePropertyDescriber.php +++ b/src/PropertyDescriber/NullablePropertyDescriber.php @@ -48,7 +48,7 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul $this->propertyDescriber->describe($types, $property, $groups, $schema, $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 09385fff9..5e28272a3 100644 --- a/src/PropertyDescriber/ObjectPropertyDescriber.php +++ b/src/PropertyDescriber/ObjectPropertyDescriber.php @@ -65,7 +65,7 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul $property->ref = $this->modelRegistry->register(new Model($type, $groups, [], $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..96c3a99c6 100644 --- a/src/PropertyDescriber/PropertyDescriber.php +++ b/src/PropertyDescriber/PropertyDescriber.php @@ -60,7 +60,7 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul ); } - if (null === $propertyDescriber = $this->getPropertyDescriber($types)) { + if (null === $propertyDescriber = $this->getPropertyDescriber($types, $context)) { return; } @@ -69,9 +69,9 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul $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 +83,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 +109,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..1699ad34b 100644 --- a/src/PropertyDescriber/PropertyDescriberInterface.php +++ b/src/PropertyDescriber/PropertyDescriberInterface.php @@ -27,7 +27,8 @@ interface PropertyDescriberInterface public function describe(array $types, Schema $property, ?array $groups = null /* , ?Schema $schema = null */ /* , 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 6c21c4326..21bfa726f 100644 --- a/src/PropertyDescriber/StringPropertyDescriber.php +++ b/src/PropertyDescriber/StringPropertyDescriber.php @@ -42,7 +42,7 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul $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..24bdabb70 100644 --- a/src/PropertyDescriber/UuidPropertyDescriber.php +++ b/src/PropertyDescriber/UuidPropertyDescriber.php @@ -26,7 +26,7 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul $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() From c30f6e691623a9c6c284e72398b1a60a38e76602 Mon Sep 17 00:00:00 2001 From: djordy Date: Tue, 12 Nov 2024 16:16:46 +0100 Subject: [PATCH 2/4] changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f23be4a92..6cb1f2175 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # CHANGELOG +## 4.33.5 +* Added new optional parameter `$context` to` PropertyDescriberInterface::supports()` + ## 4.33.4 * Deprecated `null` type from `$options` in `Nelmio\ApiDocBundle\Attribute\Model::__construct()`. Pass an empty array (`[]`) instead. * Deprecated `null` type from `$options` in `NNelmio\ApiDocBundle\Attribute\Model::__construct()`. Pass an empty array (`[]`) instead. From 5fc88ab2ae398a474b9a80873a0f656ec2383dd9 Mon Sep 17 00:00:00 2001 From: djordy Date: Tue, 12 Nov 2024 16:17:29 +0100 Subject: [PATCH 3/4] fix --- src/PropertyDescriber/RequiredPropertyDescriber.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PropertyDescriber/RequiredPropertyDescriber.php b/src/PropertyDescriber/RequiredPropertyDescriber.php index f4d88fc41..a51f31509 100644 --- a/src/PropertyDescriber/RequiredPropertyDescriber.php +++ b/src/PropertyDescriber/RequiredPropertyDescriber.php @@ -66,7 +66,7 @@ public function describe(array $types, OA\Schema $property, ?array $groups = nul $schema->required = array_values(array_unique($existingRequiredFields)); } - public function supports(array $types): bool + public function supports(array $types, array $context = []): bool { return true; } From 34d6b58c7ee2342a6a6c4b1a1e7678afc287b7a9 Mon Sep 17 00:00:00 2001 From: djordy Date: Tue, 12 Nov 2024 16:18:01 +0100 Subject: [PATCH 4/4] fix interface BC --- phpstan-baseline.neon | 72 ++++++++++++++++++- .../PropertyDescriberInterface.php | 2 +- 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 4754d1794..e6f2a0b4e 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -25,34 +25,89 @@ parameters: count: 1 path: src/Describer/ExternalDocDescriber.php + - + message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\ArrayPropertyDescriber\\:\\:supports\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" + 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/ArrayPropertyDescriber.php + - + message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\BooleanPropertyDescriber\\:\\:supports\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" + count: 1 + path: src/PropertyDescriber/BooleanPropertyDescriber.php + + - + message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\CompoundPropertyDescriber\\:\\:supports\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" + 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/CompoundPropertyDescriber.php + - + message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\DateTimePropertyDescriber\\:\\:supports\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" + count: 1 + path: src/PropertyDescriber/DateTimePropertyDescriber.php + + - + message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\DictionaryPropertyDescriber\\:\\:supports\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" + 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/DictionaryPropertyDescriber.php + - + message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\FloatPropertyDescriber\\:\\:supports\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" + count: 1 + path: src/PropertyDescriber/FloatPropertyDescriber.php + + - + message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\IntegerPropertyDescriber\\:\\:supports\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" + count: 1 + path: src/PropertyDescriber/IntegerPropertyDescriber.php + + - + message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\NullablePropertyDescriber\\:\\:supports\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" + 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/NullablePropertyDescriber.php + - + message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\ObjectPropertyDescriber\\:\\:supports\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" + count: 1 + path: src/PropertyDescriber/ObjectPropertyDescriber.php + + - + message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\PropertyDescriber\\:\\:supports\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" + count: 1 + path: src/PropertyDescriber/PropertyDescriber.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$#" + message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\PropertyDescriberInterface\\:\\:supports\\(\\) invoked with 2 parameters, 1 required\\.$#" count: 1 + path: src/PropertyDescriber/PropertyDescriber.php + + - + message: "#^PHPDoc tag @param references unknown parameter\\: \\$context$#" + count: 2 path: src/PropertyDescriber/PropertyDescriberInterface.php - @@ -65,6 +120,21 @@ parameters: count: 1 path: src/PropertyDescriber/RequiredPropertyDescriber.php + - + message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\RequiredPropertyDescriber\\:\\:supports\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" + count: 1 + path: src/PropertyDescriber/RequiredPropertyDescriber.php + + - + message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\StringPropertyDescriber\\:\\:supports\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" + count: 1 + path: src/PropertyDescriber/StringPropertyDescriber.php + + - + message: "#^Method Nelmio\\\\ApiDocBundle\\\\PropertyDescriber\\\\UuidPropertyDescriber\\:\\:supports\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" + count: 1 + path: src/PropertyDescriber/UuidPropertyDescriber.php + - message: "#^Call to method render\\(\\) on an unknown class Twig_Environment\\.$#" count: 2 diff --git a/src/PropertyDescriber/PropertyDescriberInterface.php b/src/PropertyDescriber/PropertyDescriberInterface.php index 1699ad34b..31562d22b 100644 --- a/src/PropertyDescriber/PropertyDescriberInterface.php +++ b/src/PropertyDescriber/PropertyDescriberInterface.php @@ -30,5 +30,5 @@ public function describe(array $types, Schema $property, ?array $groups = null / * @param Type[] $types * @param array $context Context options for describing the property */ - public function supports(array $types, array $context = []): bool; + public function supports(array $types /* , array $context = [] */): bool; }