Skip to content

Commit fe516ff

Browse files
committed
error list throw all erreors (not only the first one)
1 parent 0186719 commit fe516ff

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

features/filter/filter_validation.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ Feature: Validate filters based upon filter description
2020
Scenario: Required filter should throw an error if not set
2121
When I am on "/array_filter_validators"
2222
Then the response status code should be 400
23-
And the JSON node "detail" should be equal to 'Query parameter "arrayRequired[]" is required'
23+
And the JSON node "detail" should match '/^Query parameter "arrayRequired\[\]" is required\nQuery parameter "indexedArrayRequired\[foo\]" is required$/'
2424

2525
When I am on "/array_filter_validators?arrayRequired=foo&indexedArrayRequired[foo]=foo"
2626
Then the response status code should be 400
2727
And the JSON node "detail" should be equal to 'Query parameter "arrayRequired[]" is required'
2828

2929
When I am on "/array_filter_validators?arrayRequired[foo]=foo"
3030
Then the response status code should be 400
31-
And the JSON node "detail" should be equal to 'Query parameter "arrayRequired[]" is required'
31+
And the JSON node "detail" should match '/^Query parameter "arrayRequired\[\]" is required\nQuery parameter "indexedArrayRequired\[foo\]" is required$/'
3232

3333
When I am on "/array_filter_validators?arrayRequired[]=foo"
3434
Then the response status code should be 400

src/Filter/QueryParameterValidateListener.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,26 @@ public function onKernelRequest(GetResponseEvent $event)
5252
$resourceMetadata = $this->resourceMetadataFactory->create($attributes['resource_class']);
5353
$resourceFilters = $resourceMetadata->getCollectionOperationAttribute($operationName, 'filters', [], true);
5454

55+
$errorList = [];
5556
foreach ($resourceFilters as $filterId) {
5657
if (!$filter = $this->getFilter($filterId)) {
5758
continue;
5859
}
5960

6061
foreach ($filter->getDescription($attributes['resource_class']) as $name => $data) {
61-
$errorList = [];
62-
6362
if (!($data['required'] ?? false)) { // property is not required
6463
continue;
6564
}
6665

6766
if (!$this->isRequiredFilterValid($name, $request)) {
6867
$errorList[] = sprintf('Query parameter "%s" is required', $name);
6968
}
70-
71-
if ($errorList) {
72-
throw new FilterValidationException($errorList);
73-
}
7469
}
7570
}
71+
72+
if ($errorList) {
73+
throw new FilterValidationException($errorList);
74+
}
7675
}
7776

7877
/**

0 commit comments

Comments
 (0)