Skip to content

Commit 0ad964f

Browse files
committed
fix(validator): property path on deepObject style
1 parent fdb485d commit 0ad964f

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/Symfony/Validator/State/ParameterValidatorProvider.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,12 @@ private function getProperty(Parameter $parameter, ConstraintViolationInterface
100100
return str_replace(':property', $violation->getPropertyPath(), $key);
101101
}
102102

103-
if ($p = $violation->getPropertyPath()) {
103+
$openApi = $parameter->getOpenApi();
104+
if (false === $openApi) {
105+
$openApi = null;
106+
}
107+
108+
if ('deepObject' === $openApi?->getStyle() && $p = $violation->getPropertyPath()) {
104109
return $key.$p;
105110
}
106111

tests/Fixtures/TestBundle/ApiResource/WithParameter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@
9292
#[GetCollection(
9393
uriTemplate: 'validate_parameters{._format}',
9494
parameters: [
95-
'enum' => new QueryParameter(schema: ['enum' => ['a', 'b'], 'uniqueItems' => true]),
95+
'enum' => new QueryParameter(schema: ['enum' => ['a', 'b'], 'uniqueItems' => true], openApi: new OpenApiParameter(name: 'enum', in: 'query', style: 'deepObject')),
96+
'enumNotDeepObject' => new QueryParameter(schema: ['enum' => ['a', 'b'], 'uniqueItems' => true]),
9697
'num' => new QueryParameter(
9798
schema: ['minimum' => 1, 'maximum' => 3],
9899
nativeType: new BuiltinType(TypeIdentifier::STRING),

tests/Functional/Parameters/ValidationTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ public function testValidation(string $queryString, array $expectedViolations):
5555
public static function provideQueryStrings(): array
5656
{
5757
return [
58+
[
59+
'enumNotDeepObject[]=c&enumNotDeepObject[]=c',
60+
[
61+
[
62+
'propertyPath' => 'enumNotDeepObject', 'message' => 'The value you selected is not a valid choice.',
63+
],
64+
[
65+
'propertyPath' => 'enumNotDeepObject', 'message' => 'The value you selected is not a valid choice.',
66+
],
67+
[
68+
'message' => 'This collection should contain only unique elements.',
69+
],
70+
],
71+
],
5872
[
5973
'enum[]=c&enum[]=c',
6074
[

0 commit comments

Comments
 (0)