Skip to content

Commit

Permalink
feat(state): review validation for required parameters (#6441)
Browse files Browse the repository at this point in the history
  • Loading branch information
deguif authored Jun 30, 2024
1 parent c2d3aeb commit 9ac50d2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"symfony/property-info": "^6.4 || ^7.0",
"symfony/serializer": "^6.4 || ^7.0",
"symfony/translation-contracts": "^3.3",
"symfony/type-info": "^7.1",
"symfony/web-link": "^6.4 || ^7.0",
"willdurand/negotiation": "^3.0"
},
Expand Down
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 ?? $openApi?->getAllowEmptyValue())) {
$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
2 changes: 0 additions & 2 deletions tests/Fixtures/app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Doctrine\Bundle\MongoDBBundle\Command\TailCursorDoctrineODMCommand;
use Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle;
use Doctrine\Common\Inflector\Inflector;
use Doctrine\Inflector\InflectorFactory;
use FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
Expand Down

0 comments on commit 9ac50d2

Please sign in to comment.