Skip to content

Commit c2d3aeb

Browse files
authored
feat(state): list all violations during query parameters validation (#6442)
1 parent 89e284a commit c2d3aeb

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/Symfony/Validator/State/ParameterValidatorProvider.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
4444
}
4545

4646
$operation = $request->attributes->get('_api_operation') ?? $operation;
47+
$constraintViolationList = new ConstraintViolationList();
4748
foreach ($operation->getParameters() ?? [] as $parameter) {
4849
if (!$constraints = $parameter->getConstraints()) {
4950
continue;
@@ -52,28 +53,27 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
5253
$key = $this->getParameterFlattenKey($parameter->getKey(), $this->extractParameterValues($parameter, $request, $context));
5354
$value = $parameter->getExtraProperties()['_api_values'][$key] ?? null;
5455
$violations = $this->validator->validate($value, $constraints);
55-
if (0 !== \count($violations)) {
56-
$constraintViolationList = new ConstraintViolationList();
57-
foreach ($violations as $violation) {
58-
$propertyPath = $key !== $parameter->getKey() ? $key.$violation->getPropertyPath() : ($parameter->getProperty() ?? $key);
59-
$constraintViolationList->add(new ConstraintViolation(
60-
$violation->getMessage(),
61-
$violation->getMessageTemplate(),
62-
$violation->getParameters(),
63-
$violation->getRoot(),
64-
$propertyPath,
65-
$violation->getInvalidValue(),
66-
$violation->getPlural(),
67-
$violation->getCode(),
68-
$violation->getConstraint(),
69-
$violation->getCause()
70-
));
71-
}
72-
73-
throw new ValidationException($constraintViolationList);
56+
foreach ($violations as $violation) {
57+
$propertyPath = $key !== $parameter->getKey() ? $key.$violation->getPropertyPath() : ($parameter->getProperty() ?? $key);
58+
$constraintViolationList->add(new ConstraintViolation(
59+
$violation->getMessage(),
60+
$violation->getMessageTemplate(),
61+
$violation->getParameters(),
62+
$violation->getRoot(),
63+
$propertyPath,
64+
$violation->getInvalidValue(),
65+
$violation->getPlural(),
66+
$violation->getCode(),
67+
$violation->getConstraint(),
68+
$violation->getCause()
69+
));
7470
}
7571
}
7672

73+
if (0 !== \count($constraintViolationList)) {
74+
throw new ValidationException($constraintViolationList);
75+
}
76+
7777
return $this->decorated->provide($operation, $uriVariables, $context);
7878
}
7979
}

0 commit comments

Comments
 (0)