Skip to content

Commit

Permalink
feat(state): review validation for required parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
deguif authored and soyuka committed Jun 29, 2024
1 parent 89e284a commit 264b4bf
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,14 @@ private function addSchemaValidation(Parameter $parameter, ?array $schema = null
{
$assertions = [];

if ($required) {
if ($required && false !== ($allowEmptyValue = $openApi?->getAllowEmptyValue())) {
$assertions[] = new NotNull(message: sprintf('The parameter "%s" is required.', $parameter->getKey()));
}

if (false === $allowEmptyValue) {

Check failure on line 163 in src/Metadata/Resource/Factory/ParameterResourceMetadataCollectionFactory.php

View workflow job for this annotation

GitHub Actions / PHPStan (PHP 8.3)

Variable $allowEmptyValue might not be defined.
$assertions[] = new NotBlank(allowNull: !$required);
}

if (isset($schema['exclusiveMinimum'])) {
$assertions[] = new GreaterThan(value: $schema['exclusiveMinimum']);
}
Expand Down Expand Up @@ -200,10 +204,6 @@ private function addSchemaValidation(Parameter $parameter, ?array $schema = null
$assertions[] = new Choice(choices: $schema['enum']);
}

if (false === $openApi?->getAllowEmptyValue()) {
$assertions[] = new NotBlank(allowNull: !$required);
}

if (!$assertions) {
return $parameter;
}
Expand Down

0 comments on commit 264b4bf

Please sign in to comment.