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 9eae193
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/ModelDescriber/ObjectModelDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@ 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)) !== false) {

Check failure on line 179 in src/ModelDescriber/ObjectModelDescriber.php

View workflow job for this annotation

GitHub Actions / PHPStan

Call to function array_search() requires parameter #3 to be set.

Check failure on line 179 in src/ModelDescriber/ObjectModelDescriber.php

View workflow job for this annotation

GitHub Actions / PHPStan

Call to function is_array() with incorrect case: is_Array
unset($schema->required[$key]);
}
}

$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 9eae193

Please sign in to comment.