Open IcarusSosie opened 3 months ago
would you be able to propose a patch? Thanks!
Hi, I just got back from vacation :smile:
I can absolutely create the PR. I'm assuming editing the relevant XML configuration file should suffice for the behavior to be fixed, but I'll have to take a closer look to tests to add a test case with OpenAPI references.
Nice lmk if you need help
Not sure I understand the bug actually I could not reproduce, you can override the name converter by specifying the service name inside api_platform.name_converter
and we do the proper aliasing to always use the MetadataAwareNameConverter
. Can you provide a proper reproducer?
API Platform version(s) affected: 2.6.2 to 3.3.6
Description
PR #4019 introduces an anonymous service argument in
openapi.xml
for the serviceapi_platform.openapi.normalizer
. Whilst the change does fix an issue with incorrect OpenAPI document serialization when the default name converter is changed, it also has a secondary effect :OpenApiNormalizer
now does not have access to Attribute metadata when serializing the OpenAPI definition. SinceApiPlatform\OpenApi\Model\Reference
declares a#[SerializedName('$ref')]
attribute on itsgetRef()
method, any reference created by theOpenApiFactory
will be serialized asinstead of
causing SwaggerUI to render incorrectly. For example, a reference to a path parameter will show up as an empty field with no info or context.
As far as I know, the default
OpenApiFactory
does not generate references except for JSON schemas, which are not affected, but any reference added to theOpenApi
object by a decorator ofOpenApiFactory
will serialize incorrectly.How to reproduce
In an API-Platform project, decorate
OpenApiFactory
:Then, access the swagger docs. All operations will have a dud input corresponding to the invalid reference.
Possible Solution
Currently, I'm solving this by overriding
api_platform.openapi.normalizer
inservices.yaml
:The solution is quite similar to the fix in #4019, using anonymous services to not override other services declarations using the same underlying class. I'm just adding the
MetadataAwareNameConverter
with no fallback, which I think might avoid issues if I decide to specify a default name converter in the future.Additional Context
I'm not a Symfony expert by any means, so I might be missing some other quicker solution or workaround. My API-Platform setup is also quite custom, which might affect serializer functionality, although that would be surprising.