From e24c5e8e3fc1c751e55a9d7a16cac9f9aae0015d Mon Sep 17 00:00:00 2001 From: Sullivan SENECHAL Date: Fri, 14 Dec 2018 15:09:31 +0100 Subject: [PATCH 1/3] Always pass an array for AdvancedNameConverterInterface::normalize --- src/Swagger/Serializer/DocumentationNormalizer.php | 2 +- .../Serializer/DocumentationNormalizerTest.php | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Swagger/Serializer/DocumentationNormalizer.php b/src/Swagger/Serializer/DocumentationNormalizer.php index 88ebd916e40..ba6cd74a4c7 100644 --- a/src/Swagger/Serializer/DocumentationNormalizer.php +++ b/src/Swagger/Serializer/DocumentationNormalizer.php @@ -431,7 +431,7 @@ private function getDefinitionSchema(string $resourceClass, ResourceMetadata $re foreach ($this->propertyNameCollectionFactory->create($resourceClass, $options) as $propertyName) { $propertyMetadata = $this->propertyMetadataFactory->create($resourceClass, $propertyName); $normalizedPropertyName = $this->nameConverter - ? $this->nameConverter->normalize($propertyName, $resourceClass, self::FORMAT, $serializerContext) + ? $this->nameConverter->normalize($propertyName, $resourceClass, self::FORMAT, $serializerContext ?? []) : $propertyName ; diff --git a/tests/Swagger/Serializer/DocumentationNormalizerTest.php b/tests/Swagger/Serializer/DocumentationNormalizerTest.php index 0acc16042dd..964e54be9b5 100644 --- a/tests/Swagger/Serializer/DocumentationNormalizerTest.php +++ b/tests/Swagger/Serializer/DocumentationNormalizerTest.php @@ -48,6 +48,7 @@ use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing\RouterInterface; +use Symfony\Component\Serializer\NameConverter\AdvancedNameConverterInterface; use Symfony\Component\Serializer\NameConverter\NameConverterInterface; use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; @@ -331,9 +332,13 @@ public function testNormalizeWithNameConverter() $operationMethodResolverProphecy = $this->prophesize(OperationMethodResolverInterface::class); $operationMethodResolverProphecy->getItemOperationMethod(Dummy::class, 'get')->shouldBeCalled()->willReturn('GET'); - $nameConverterProphecy = $this->prophesize(NameConverterInterface::class); - $nameConverterProphecy->normalize('name', Dummy::class, DocumentationNormalizer::FORMAT, null)->willReturn('name')->shouldBeCalled(); - $nameConverterProphecy->normalize('nameConverted', Dummy::class, DocumentationNormalizer::FORMAT, null)->willReturn('name_converted')->shouldBeCalled(); + $nameConverterProphecy = $this->prophesize( + interface_exists(AdvancedNameConverterInterface::class) + ? AdvancedNameConverterInterface::class + : NameConverterInterface::class + ); + $nameConverterProphecy->normalize('name', Dummy::class, DocumentationNormalizer::FORMAT, [])->willReturn('name')->shouldBeCalled(); + $nameConverterProphecy->normalize('nameConverted', Dummy::class, DocumentationNormalizer::FORMAT, [])->willReturn('name_converted')->shouldBeCalled(); $operationPathResolver = new CustomOperationPathResolver(new OperationPathResolver(new UnderscorePathSegmentNameGenerator())); From 8a9ffe1cce40c72a46dbec9497e947608f0eaea2 Mon Sep 17 00:00:00 2001 From: Teoh Han Hui Date: Mon, 17 Dec 2018 16:58:10 +0100 Subject: [PATCH 2/3] Fix exclude app cache path for PHP-CS-Fixer --- .php_cs.dist | 1 + 1 file changed, 1 insertion(+) diff --git a/.php_cs.dist b/.php_cs.dist index f55c7eeb237..083bd060b1b 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -14,6 +14,7 @@ HEADER; $finder = PhpCsFixer\Finder::create() ->in(__DIR__) ->exclude('tests/Fixtures/app/cache') + ->exclude('tests/Fixtures/app/var') ; return PhpCsFixer\Config::create() From 501906dcc6fd9097d06000804f212bac1f7a96e7 Mon Sep 17 00:00:00 2001 From: Yanick Witschi Date: Tue, 18 Dec 2018 14:05:12 +0100 Subject: [PATCH 3/3] Added swagger description to property filter --- src/Serializer/Filter/PropertyFilter.php | 14 ++++++++++++++ tests/Serializer/Filter/PropertyFilterTest.php | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Serializer/Filter/PropertyFilter.php b/src/Serializer/Filter/PropertyFilter.php index d8aa4e79752..d4d34923ead 100644 --- a/src/Serializer/Filter/PropertyFilter.php +++ b/src/Serializer/Filter/PropertyFilter.php @@ -67,12 +67,26 @@ public function apply(Request $request, bool $normalization, array $attributes, */ public function getDescription(string $resourceClass): array { + $swaggerExample = sprintf('%s[]={propertyName}&%s[]={anotherPropertyName}&%s[{nestedPropertyParent}][]={nestedProperty}', + $this->parameterName, + $this->parameterName, + $this->parameterName + ); + return [ "$this->parameterName[]" => [ 'property' => null, 'type' => 'string', 'is_collection' => true, 'required' => false, + 'swagger' => [ + '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, + 'name' => $this->parameterName, + 'type' => 'array', + 'items' => [ + 'type' => 'string', + ], + ], ], ]; } diff --git a/tests/Serializer/Filter/PropertyFilterTest.php b/tests/Serializer/Filter/PropertyFilterTest.php index 4f552466ec1..bedc8a294dd 100644 --- a/tests/Serializer/Filter/PropertyFilterTest.php +++ b/tests/Serializer/Filter/PropertyFilterTest.php @@ -130,6 +130,14 @@ public function testGetDescription() 'type' => 'string', 'is_collection' => true, 'required' => false, + 'swagger' => [ + '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}', + 'name' => 'custom_properties', + 'type' => 'array', + 'items' => [ + 'type' => 'string', + ], + ], ], ];