Skip to content

Commit 9ac50d2

Browse files
authored
feat(state): review validation for required parameters (#6441)
1 parent c2d3aeb commit 9ac50d2

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
"symfony/property-info": "^6.4 || ^7.0",
3535
"symfony/serializer": "^6.4 || ^7.0",
3636
"symfony/translation-contracts": "^3.3",
37-
"symfony/type-info": "^7.1",
3837
"symfony/web-link": "^6.4 || ^7.0",
3938
"willdurand/negotiation": "^3.0"
4039
},

src/Metadata/Resource/Factory/ParameterResourceMetadataCollectionFactory.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,14 @@ private function addSchemaValidation(Parameter $parameter, ?array $schema = null
156156
{
157157
$assertions = [];
158158

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

163+
if (false === ($allowEmptyValue ?? $openApi?->getAllowEmptyValue())) {
164+
$assertions[] = new NotBlank(allowNull: !$required);
165+
}
166+
163167
if (isset($schema['exclusiveMinimum'])) {
164168
$assertions[] = new GreaterThan(value: $schema['exclusiveMinimum']);
165169
}
@@ -200,10 +204,6 @@ private function addSchemaValidation(Parameter $parameter, ?array $schema = null
200204
$assertions[] = new Choice(choices: $schema['enum']);
201205
}
202206

203-
if (false === $openApi?->getAllowEmptyValue()) {
204-
$assertions[] = new NotBlank(allowNull: !$required);
205-
}
206-
207207
if (!$assertions) {
208208
return $parameter;
209209
}

tests/Fixtures/app/AppKernel.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
2121
use Doctrine\Bundle\MongoDBBundle\Command\TailCursorDoctrineODMCommand;
2222
use Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle;
23-
use Doctrine\Common\Inflector\Inflector;
24-
use Doctrine\Inflector\InflectorFactory;
2523
use FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle;
2624
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
2725
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;

0 commit comments

Comments
 (0)