Skip to content
Open
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
6 changes: 5 additions & 1 deletion src/Doctrine/Common/Filter/OpenApiFilterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ public function getOpenApiParameters(Parameter $parameter): OpenApiParameter|arr
return new OpenApiParameter(name: $parameter->getKey(), in: 'query');
}

$arraySchema = ['type' => 'array', 'items' => $schema ?? ['type' => 'string']];
if ('array' === ($schema['type'] ?? null)) {
$arraySchema = $schema;
} else {
$arraySchema = ['type' => 'array', 'items' => $schema ?? ['type' => 'string']];
}

return new OpenApiParameter(name: $parameter->getKey().'[]', in: 'query', style: 'deepObject', explode: true, schema: $arraySchema);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@
property: 'tags',
schema: ['anyOf' => [['type' => 'array', 'items' => ['type' => 'string']], ['type' => 'string']]]
),
'listOfTags' => new QueryParameter(
filter: new ExactFilter(),
property: 'tags',
schema: ['type' => 'array', 'items' => ['type' => 'string']],
),
]
),
]
Expand Down
8 changes: 8 additions & 0 deletions tests/Functional/Parameters/DoctrineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,14 @@ public static function openApiParameterDocumentationProvider(): array
'expectedDescription' => '',
'expectedSchema' => ['type' => 'array', 'items' => ['anyOf' => [['type' => 'array', 'items' => ['type' => 'string']], ['type' => 'string']]]],
],
'with schema and default castToArray should not wrap schema in array type if already an array' => [
'parameterName' => 'listOfTags',
'shouldHaveArrayNotation' => true,
'expectedStyle' => 'deepObject',
'expectedExplode' => true,
'expectedDescription' => '',
'expectedSchema' => ['type' => 'array', 'items' => ['type' => 'string']],
],
];
}
}
Loading