Skip to content

Commit

Permalink
Use NullablePropertyTrait when describing an object property
Browse files Browse the repository at this point in the history
  • Loading branch information
DjordyKoert committed Oct 27, 2023
1 parent 534be18 commit ff9d18b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions PropertyDescriber/ObjectPropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@

class ObjectPropertyDescriber implements PropertyDescriberInterface, ModelRegistryAwareInterface
{
use NullablePropertyTrait;
use ModelRegistryAwareTrait;

public function describe(array $types, OA\Schema $property, array $groups = null, ?OA\Schema $schema = null)
{
$type = new Type(
$types[0]->getBuiltinType(),
false,
$types[0]->isNullable(),
$types[0]->getClassName(),
$types[0]->isCollection(),
// BC layer for symfony < 5.3
Expand All @@ -36,9 +37,10 @@ public function describe(array $types, OA\Schema $property, array $groups = null
$types[0]->getCollectionValueType()
); // ignore nullable field

$this->setNullableProperty($type, $property, $schema);

if ($types[0]->isNullable()) {
$weakContext = Util::createWeakContext($property->_context);
$property->nullable = true;
$property->allOf = [new OA\Schema(['ref' => $this->modelRegistry->register(new Model($type, $groups)), '_context' => $weakContext])];

return;
Expand Down

0 comments on commit ff9d18b

Please sign in to comment.