Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Symfony/Validator/State/ParameterValidatorProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,12 @@ private function getProperty(Parameter $parameter, ConstraintViolationInterface
return str_replace(':property', $violation->getPropertyPath(), $key);
}

if ($p = $violation->getPropertyPath()) {
$openApi = $parameter->getOpenApi();
if (false === $openApi) {
$openApi = null;
}

if ('deepObject' === $openApi?->getStyle() && $p = $violation->getPropertyPath()) {
return $key.$p;
}

Expand Down
7 changes: 6 additions & 1 deletion tests/Fixtures/TestBundle/ApiResource/WithParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@
parameters: [
'enum' => new QueryParameter(
schema: ['enum' => ['a', 'b'], 'uniqueItems' => true],
castToArray: true
castToArray: true,
openApi: new OpenApiParameter(name: 'enum', in: 'query', style: 'deepObject')
),
'enumNotDeepObject' => new QueryParameter(
schema: ['enum' => ['a', 'b'], 'uniqueItems' => true],
castToArray: true,
),
'num' => new QueryParameter(
schema: ['minimum' => 1, 'maximum' => 3],
Expand Down
14 changes: 14 additions & 0 deletions tests/Functional/Parameters/ValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
[
Expand Down
Loading