Skip to content

Commit 986ebeb

Browse files
authored
Merge pull request #2391 from Toflar/propertyfilter-swagger-docs
Added swagger description to property filter
2 parents 5513d27 + 501906d commit 986ebeb

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/Serializer/Filter/PropertyFilter.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,26 @@ 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,
73+
$this->parameterName
74+
);
75+
7076
return [
7177
"$this->parameterName[]" => [
7278
'property' => null,
7379
'type' => 'string',
7480
'is_collection' => true,
7581
'required' => false,
82+
'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,
84+
'name' => $this->parameterName,
85+
'type' => 'array',
86+
'items' => [
87+
'type' => 'string',
88+
],
89+
],
7690
],
7791
];
7892
}

tests/Serializer/Filter/PropertyFilterTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ public function testGetDescription()
130130
'type' => 'string',
131131
'is_collection' => true,
132132
'required' => false,
133+
'swagger' => [
134+
'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}',
135+
'name' => 'custom_properties',
136+
'type' => 'array',
137+
'items' => [
138+
'type' => 'string',
139+
],
140+
],
133141
],
134142
];
135143

0 commit comments

Comments
 (0)