Skip to content

Commit

Permalink
Remove fields with default from required entry
Browse files Browse the repository at this point in the history
  • Loading branch information
heiglandreas committed Nov 6, 2024
1 parent c685a61 commit de11fd1
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/ModelDescriber/ObjectModelDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,18 @@ public function describe(Model $model, OA\Schema $schema)
$property->default = $defaultValues[$propertyName];
}

if (Generator::UNDEFINED !== $property->default) {
// Fix for https://github.com/nelmio/NelmioApiDocBundle/issues/2222
// When a default value has been set for the property, we can
// remove the field from the required fields.
if (is_array($schema->required) && ($key = array_search($propertyName, $schema->required, true)) !== false) {
unset($schema->required[$key]);
}
}
if ($schema->required === []) {
unset($schema->required);
}

$types = $this->propertyInfo->getTypes($class, $propertyName);
if (null === $types || 0 === count($types)) {
throw new \LogicException(sprintf('The PropertyInfo component was not able to guess the type of %s::$%s. You may need to add a `@var` annotation or use `@OA\Property(type="")` to make its type explicit.', $class, $propertyName));
Expand Down

0 comments on commit de11fd1

Please sign in to comment.