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