Skip to content

Commit f8693d1

Browse files
committed
Merge branch '2.3'
2 parents cf7fd3f + 6884830 commit f8693d1

File tree

5 files changed

+32
-4
lines changed

5 files changed

+32
-4
lines changed

.php_cs.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ HEADER;
1414
$finder = PhpCsFixer\Finder::create()
1515
->in(__DIR__)
1616
->exclude('tests/Fixtures/app/cache')
17+
->exclude('tests/Fixtures/app/var')
1718
;
1819

1920
return PhpCsFixer\Config::create()

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
}

src/Swagger/Serializer/DocumentationNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ private function getDefinitionSchema(string $resourceClass, ResourceMetadata $re
442442
foreach ($this->propertyNameCollectionFactory->create($resourceClass, $options) as $propertyName) {
443443
$propertyMetadata = $this->propertyMetadataFactory->create($resourceClass, $propertyName);
444444
$normalizedPropertyName = $this->nameConverter
445-
? $this->nameConverter->normalize($propertyName, $resourceClass, self::FORMAT, $serializerContext)
445+
? $this->nameConverter->normalize($propertyName, $resourceClass, self::FORMAT, $serializerContext ?? [])
446446
: $propertyName
447447
;
448448

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

tests/Swagger/Serializer/DocumentationNormalizerTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
use Symfony\Component\Routing\Route;
4949
use Symfony\Component\Routing\RouteCollection;
5050
use Symfony\Component\Routing\RouterInterface;
51+
use Symfony\Component\Serializer\NameConverter\AdvancedNameConverterInterface;
5152
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
5253
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
5354

@@ -336,9 +337,13 @@ public function testNormalizeWithNameConverter()
336337
$operationMethodResolverProphecy = $this->prophesize(OperationMethodResolverInterface::class);
337338
$operationMethodResolverProphecy->getItemOperationMethod(Dummy::class, 'get')->shouldBeCalled()->willReturn('GET');
338339

339-
$nameConverterProphecy = $this->prophesize(NameConverterInterface::class);
340-
$nameConverterProphecy->normalize('name', Dummy::class, DocumentationNormalizer::FORMAT, null)->willReturn('name')->shouldBeCalled();
341-
$nameConverterProphecy->normalize('nameConverted', Dummy::class, DocumentationNormalizer::FORMAT, null)->willReturn('name_converted')->shouldBeCalled();
340+
$nameConverterProphecy = $this->prophesize(
341+
interface_exists(AdvancedNameConverterInterface::class)
342+
? AdvancedNameConverterInterface::class
343+
: NameConverterInterface::class
344+
);
345+
$nameConverterProphecy->normalize('name', Dummy::class, DocumentationNormalizer::FORMAT, [])->willReturn('name')->shouldBeCalled();
346+
$nameConverterProphecy->normalize('nameConverted', Dummy::class, DocumentationNormalizer::FORMAT, [])->willReturn('name_converted')->shouldBeCalled();
342347

343348
$operationPathResolver = new CustomOperationPathResolver(new OperationPathResolver(new UnderscorePathSegmentNameGenerator()));
344349

0 commit comments

Comments
 (0)