Skip to content

Commit

Permalink
Merge branch '2.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Dec 19, 2018
2 parents cf7fd3f + 6884830 commit f8693d1
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
1 change: 1 addition & 0 deletions .php_cs.dist
Expand Up @@ -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()
Expand Down
14 changes: 14 additions & 0 deletions src/Serializer/Filter/PropertyFilter.php
Expand Up @@ -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',
],
],
],
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Swagger/Serializer/DocumentationNormalizer.php
Expand Up @@ -442,7 +442,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
;

Expand Down
8 changes: 8 additions & 0 deletions tests/Serializer/Filter/PropertyFilterTest.php
Expand Up @@ -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',
],
],
],
];

Expand Down
11 changes: 8 additions & 3 deletions tests/Swagger/Serializer/DocumentationNormalizerTest.php
Expand Up @@ -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;

Expand Down Expand Up @@ -336,9 +337,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()));

Expand Down

0 comments on commit f8693d1

Please sign in to comment.