Skip to content

Commit e24c5e8

Browse files
committed
Always pass an array for AdvancedNameConverterInterface::normalize
1 parent b53bb0b commit e24c5e8

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/Swagger/Serializer/DocumentationNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ private function getDefinitionSchema(string $resourceClass, ResourceMetadata $re
431431
foreach ($this->propertyNameCollectionFactory->create($resourceClass, $options) as $propertyName) {
432432
$propertyMetadata = $this->propertyMetadataFactory->create($resourceClass, $propertyName);
433433
$normalizedPropertyName = $this->nameConverter
434-
? $this->nameConverter->normalize($propertyName, $resourceClass, self::FORMAT, $serializerContext)
434+
? $this->nameConverter->normalize($propertyName, $resourceClass, self::FORMAT, $serializerContext ?? [])
435435
: $propertyName
436436
;
437437

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

@@ -331,9 +332,13 @@ public function testNormalizeWithNameConverter()
331332
$operationMethodResolverProphecy = $this->prophesize(OperationMethodResolverInterface::class);
332333
$operationMethodResolverProphecy->getItemOperationMethod(Dummy::class, 'get')->shouldBeCalled()->willReturn('GET');
333334

334-
$nameConverterProphecy = $this->prophesize(NameConverterInterface::class);
335-
$nameConverterProphecy->normalize('name', Dummy::class, DocumentationNormalizer::FORMAT, null)->willReturn('name')->shouldBeCalled();
336-
$nameConverterProphecy->normalize('nameConverted', Dummy::class, DocumentationNormalizer::FORMAT, null)->willReturn('name_converted')->shouldBeCalled();
335+
$nameConverterProphecy = $this->prophesize(
336+
interface_exists(AdvancedNameConverterInterface::class)
337+
? AdvancedNameConverterInterface::class
338+
: NameConverterInterface::class
339+
);
340+
$nameConverterProphecy->normalize('name', Dummy::class, DocumentationNormalizer::FORMAT, [])->willReturn('name')->shouldBeCalled();
341+
$nameConverterProphecy->normalize('nameConverted', Dummy::class, DocumentationNormalizer::FORMAT, [])->willReturn('name_converted')->shouldBeCalled();
337342

338343
$operationPathResolver = new CustomOperationPathResolver(new OperationPathResolver(new UnderscorePathSegmentNameGenerator()));
339344

0 commit comments

Comments
 (0)