Skip to content

Commit d1e6772

Browse files
authored
fix(validation): property path on deepObject style (#7179)
1 parent d35e46b commit d1e6772

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/Symfony/Validator/State/ParameterValidatorProvider.php

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

118-
if ($p = $violation->getPropertyPath()) {
118+
$openApi = $parameter->getOpenApi();
119+
if (false === $openApi) {
120+
$openApi = null;
121+
}
122+
123+
if ('deepObject' === $openApi?->getStyle() && $p = $violation->getPropertyPath()) {
119124
return $key.$p;
120125
}
121126

tests/Fixtures/TestBundle/ApiResource/WithParameter.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,12 @@
9797
parameters: [
9898
'enum' => new QueryParameter(
9999
schema: ['enum' => ['a', 'b'], 'uniqueItems' => true],
100-
castToArray: true
100+
castToArray: true,
101+
openApi: new OpenApiParameter(name: 'enum', in: 'query', style: 'deepObject')
102+
),
103+
'enumNotDeepObject' => new QueryParameter(
104+
schema: ['enum' => ['a', 'b'], 'uniqueItems' => true],
105+
castToArray: true,
101106
),
102107
'num' => new QueryParameter(
103108
schema: ['minimum' => 1, 'maximum' => 3],

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)