Skip to content

Commit

Permalink
Serialize openapi properly fix #3997 (#4019)
Browse files Browse the repository at this point in the history
* OpenApi: fix #3997 do not use a name converter

* simplify api_platform.openapi.normalizer service definition

* fix tests

* fix tests

Co-authored-by: Kévin Dunglas <dunglas@gmail.com>
  • Loading branch information
soyuka and dunglas committed Feb 5, 2021
1 parent 7042390 commit 8a00d6e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Bridge/Symfony/Bundle/Resources/config/openapi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,24 @@

<services>
<service id="api_platform.openapi.normalizer" class="ApiPlatform\Core\OpenApi\Serializer\OpenApiNormalizer" public="false">
<argument type="service" id="serializer.normalizer.object" />
<argument type="service">
<service class="Symfony\Component\Serializer\Serializer">
<argument type="collection">
<argument type="service">
<service class="Symfony\Component\Serializer\Normalizer\ObjectNormalizer">
<argument>null</argument>
<argument>null</argument>
<argument type="service" id="api_platform.property_accessor"/>
<argument type="service" id="api_platform.property_info"/>
</service>
</argument>
</argument>
<argument type="collection">
<argument type="service" id="serializer.encoder.json" />
</argument>
</service>
</argument>

<!-- Just after the DocumentationNormalizer see swagger.xml -->
<tag name="serializer.normalizer" priority="-795" />
</service>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,13 @@ private function getBaseContainerBuilderProphecy(array $doctrineIntegrationsToLo
$definitions[] = 'api_platform.jsonld.normalizer.object';
}

// Ignore inlined services
$containerBuilderProphecy->setDefinition(Argument::that(static function (string $arg) {
return 0 === strpos($arg, '.');
}), Argument::type(Definition::class))->should(function () {
return true;
});

foreach ($definitions as $definition) {
$containerBuilderProphecy->setDefinition($definition, Argument::type(Definition::class))->shouldBeCalled();
}
Expand Down
2 changes: 2 additions & 0 deletions tests/OpenApi/Serializer/OpenApiNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,7 @@ public function testNormalize()

// Make sure things are sorted
$this->assertEquals(array_keys($openApiAsArray['paths']), ['/dummies', '/dummies/{id}', '/zorros', '/zorros/{id}']);
// Test name converter doesn't rename this property
$this->assertArrayHasKey('requestBody', $openApiAsArray['paths']['/dummies']['post']);
}
}

0 comments on commit 8a00d6e

Please sign in to comment.