diff --git a/src/Symfony/Validator/State/ParameterValidatorProvider.php b/src/Symfony/Validator/State/ParameterValidatorProvider.php index 741c4292edb..f962e91fd76 100644 --- a/src/Symfony/Validator/State/ParameterValidatorProvider.php +++ b/src/Symfony/Validator/State/ParameterValidatorProvider.php @@ -100,7 +100,7 @@ private function getProperty(Parameter $parameter, ConstraintViolationInterface return str_replace(':property', $violation->getPropertyPath(), $key); } - if ($p = $violation->getPropertyPath()) { + if ('deepObject' === $parameter->getOpenApi()?->getStyle() && $p = $violation->getPropertyPath()) { return $key.$p; } diff --git a/tests/Fixtures/TestBundle/ApiResource/WithParameter.php b/tests/Fixtures/TestBundle/ApiResource/WithParameter.php index 31544ae7ea0..8a522ed4575 100644 --- a/tests/Fixtures/TestBundle/ApiResource/WithParameter.php +++ b/tests/Fixtures/TestBundle/ApiResource/WithParameter.php @@ -92,7 +92,8 @@ #[GetCollection( uriTemplate: 'validate_parameters{._format}', parameters: [ - 'enum' => new QueryParameter(schema: ['enum' => ['a', 'b'], 'uniqueItems' => true]), + 'enum' => new QueryParameter(schema: ['enum' => ['a', 'b'], 'uniqueItems' => true], openApi: new OpenApiParameter(name: 'enum', in: 'query', style: 'deepObject')), + 'enumNotDeepObject' => new QueryParameter(schema: ['enum' => ['a', 'b'], 'uniqueItems' => true]), 'num' => new QueryParameter( schema: ['minimum' => 1, 'maximum' => 3], nativeType: new BuiltinType(TypeIdentifier::STRING), diff --git a/tests/Functional/Parameters/ValidationTest.php b/tests/Functional/Parameters/ValidationTest.php index 73b2752df46..663b8b643b4 100644 --- a/tests/Functional/Parameters/ValidationTest.php +++ b/tests/Functional/Parameters/ValidationTest.php @@ -55,6 +55,20 @@ public function testValidation(string $queryString, array $expectedViolations): public static function provideQueryStrings(): array { return [ + [ + 'enumNotDeepObject[]=c&enumNotDeepObject[]=c', + [ + [ + 'propertyPath' => 'enumNotDeepObject', 'message' => 'The value you selected is not a valid choice.', + ], + [ + 'propertyPath' => 'enumNotDeepObject', 'message' => 'The value you selected is not a valid choice.', + ], + [ + 'message' => 'This collection should contain only unique elements.', + ], + ], + ], [ 'enum[]=c&enum[]=c', [