Skip to content

Commit 9c45965

Browse files
committed
Added OpenAPI description to property filter
follow up on #2391
1 parent 20590a0 commit 9c45965

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

src/Api/FilterInterface.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ interface FilterInterface
3535
* 'name' => 'My Name',
3636
* 'type' => 'integer',
3737
* ]
38+
* - openapi (optional): additional parameters for the path operation in the version 3 spec,
39+
* e.g. 'openapi' => [
40+
* 'description' => 'My Description',
41+
* 'name' => 'My Name',
42+
* 'schema' => [
43+
* 'type' => 'integer',
44+
* ]
45+
* ]
3846
* The description can contain additional data specific to a filter.
3947
*
4048
* @see \ApiPlatform\Core\Swagger\Serializer\DocumentationNormalizer::getFiltersParameters

src/Serializer/Filter/PropertyFilter.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ public function apply(Request $request, bool $normalization, array $attributes,
6767
*/
6868
public function getDescription(string $resourceClass): array
6969
{
70-
$swaggerExample = sprintf('%s[]={propertyName}&%s[]={anotherPropertyName}&%s[{nestedPropertyParent}][]={nestedProperty}',
71-
$this->parameterName,
72-
$this->parameterName,
70+
$example = sprintf('%1$s[]={propertyName}&%1$s[]={anotherPropertyName}&%1$s[{nestedPropertyParent}][]={nestedProperty}',
7371
$this->parameterName
7472
);
7573

@@ -80,13 +78,23 @@ public function getDescription(string $resourceClass): array
8078
'is_collection' => true,
8179
'required' => false,
8280
'swagger' => [
83-
'description' => 'Allows you to reduce the response to contain only the properties you need. If your desired property is nested, you can address it using nested arrays. Example: '.$swaggerExample,
81+
'description' => 'Allows you to reduce the response to contain only the properties you need. If your desired property is nested, you can address it using nested arrays. Example: '.$example,
8482
'name' => $this->parameterName,
8583
'type' => 'array',
8684
'items' => [
8785
'type' => 'string',
8886
],
8987
],
88+
'openapi' => [
89+
'description' => 'Allows you to reduce the response to contain only the properties you need. If your desired property is nested, you can address it using nested arrays. Example: '.$example,
90+
'name' => $this->parameterName,
91+
'schema' => [
92+
'type' => 'array',
93+
'items' => [
94+
'type' => 'string',
95+
],
96+
],
97+
],
9098
],
9199
];
92100
}

tests/Serializer/Filter/PropertyFilterTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ public function testGetDescription()
138138
'type' => 'string',
139139
],
140140
],
141+
'openapi' => [
142+
'description' => 'Allows you to reduce the response to contain only the properties you need. If your desired property is nested, you can address it using nested arrays. Example: custom_properties[]={propertyName}&custom_properties[]={anotherPropertyName}&custom_properties[{nestedPropertyParent}][]={nestedProperty}',
143+
'name' => 'custom_properties',
144+
'schema' => [
145+
'type' => 'array',
146+
'items' => [
147+
'type' => 'string',
148+
],
149+
],
150+
],
141151
],
142152
];
143153

0 commit comments

Comments
 (0)