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()