diff --git a/PropertyDescriber/NullablePropertyDescriber.php b/PropertyDescriber/NullablePropertyDescriber.php index 159341844..ae293fe73 100644 --- a/PropertyDescriber/NullablePropertyDescriber.php +++ b/PropertyDescriber/NullablePropertyDescriber.php @@ -34,8 +34,16 @@ public function describe(array $types, OA\Schema $property, array $groups = null public function supports(array $types, array $context = []): bool { - return 1 === count($types) - && $types[0]->isNullable() - && !array_key_exists(self::RECURSIVE, $context); + if (array_key_exists(self::RECURSIVE, $context)) { + return false; + } + + foreach ($types as $type) { + if ($type->isNullable()) { + return true; + } + } + + return false; } } diff --git a/Tests/Functional/Entity/CompoundEntity.php b/Tests/Functional/Entity/CompoundEntity.php index ba0a6cf3c..29faca007 100644 --- a/Tests/Functional/Entity/CompoundEntity.php +++ b/Tests/Functional/Entity/CompoundEntity.php @@ -17,4 +17,9 @@ class CompoundEntity * @var int|CompoundEntity[] */ public $complex; + + /** + * @var int|CompoundEntity[]|null + */ + public $nullableComplex; } diff --git a/Tests/Functional/FunctionalTest.php b/Tests/Functional/FunctionalTest.php index d4712d2ba..cac5fe90b 100644 --- a/Tests/Functional/FunctionalTest.php +++ b/Tests/Functional/FunctionalTest.php @@ -642,6 +642,20 @@ public function testCompoundEntityAction() ], ], ], + 'nullableComplex' => [ + 'nullable' => true, + 'oneOf' => [ + [ + 'type' => 'integer', + ], + [ + 'type' => 'array', + 'items' => [ + '$ref' => '#/components/schemas/CompoundEntity', + ], + ], + ], + ], ], ], json_decode($this->getModel('CompoundEntity')->toJson(), true)); }