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 daadd14
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions PropertyDescriber/ObjectPropertyDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Nelmio\ApiDocBundle\Model\Model;
use Nelmio\ApiDocBundle\OpenApiPhp\Util;
use OpenApi\Annotations as OA;
use OpenApi\Generator;
use Symfony\Component\PropertyInfo\Type;

class ObjectPropertyDescriber implements PropertyDescriberInterface, ModelRegistryAwareInterface
Expand Down Expand Up @@ -45,6 +46,18 @@ public function describe(array $types, OA\Schema $property, array $groups = null
}

$property->ref = $this->modelRegistry->register(new Model($type, $groups));

if (!$type->isNullable() && null !== $schema) {
$propertyName = Util::getSchemaPropertyName($schema, $property);
if (null === $propertyName) {
return;
}

$existingRequiredFields = Generator::UNDEFINED !== $schema->required ? $schema->required : [];
$existingRequiredFields[] = $propertyName;

$schema->required = array_values(array_unique($existingRequiredFields));
}
}

public function supports(array $types): bool
Expand Down

0 comments on commit daadd14

Please sign in to comment.