Skip to content

Commit

Permalink
fix: handling of nullable on union typed property
Browse files Browse the repository at this point in the history
  • Loading branch information
DjordyKoert committed Jan 9, 2024
1 parent bd221dc commit 2510b0e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
14 changes: 11 additions & 3 deletions PropertyDescriber/NullablePropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
5 changes: 5 additions & 0 deletions Tests/Functional/Entity/CompoundEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ class CompoundEntity
* @var int|CompoundEntity[]
*/
public $complex;

/**
* @var int|CompoundEntity[]|null
*/
public $nullableComplex;
}
14 changes: 14 additions & 0 deletions Tests/Functional/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down

0 comments on commit 2510b0e

Please sign in to comment.