Skip to content

fix(openapi): don't apply the global name converter to the generated document#8360

Merged
soyuka merged 2 commits into
api-platform:4.3from
soyuka:fix-openapi-name-converter-8306
Jun 30, 2026
Merged

fix(openapi): don't apply the global name converter to the generated document#8360
soyuka merged 2 commits into
api-platform:4.3from
soyuka:fix-openapi-name-converter-8306

Conversation

@soyuka

@soyuka soyuka commented Jun 27, 2026

Copy link
Copy Markdown
Member

Problem

#8306 fixed Reference serialization ($ref) by wiring serializer.mapping.class_metadata_factory and serializer.name_converter.metadata_aware into the OpenAPI serializer's inline ObjectNormalizer, so that #[SerializedName('$ref')] on Reference::getRef() is honored.

Side effect (reported by @thomas-hiron in #8306): serializer.name_converter.metadata_aware carries framework.serializer.name_converter as its fallback converter (see FrameworkExtension, which sets argument 1 of that service to the configured name converter). So a project configured with:

framework:
    serializer:
        name_converter: serializer.name_converter.camel_case_to_snake_case

now gets the whole OpenAPI document run through that converter, producing snake_case keys: operation_id, extension_properties, request_bodies, security_schemes, authorization_url… which break openapi-generator-cli:

-attribute paths.'/api/article'(get).extension_properties is unexpected

Fix

Reference::getRef()'s #[SerializedName('$ref')] is the only serialization metadata the OpenAPI models rely on. Use a dedicated MetadataAwareNameConverter built with the class metadata factory only (no fallback). SerializedName is still honored; the globally configured converter no longer leaks into the document.

Tests

New tests/Functional/OpenApiNameConverterTest.php boots a kernel configuring the global camelCase_to_snake_case converter and asserts:

  • OpenAPI keys stay camelCase (operationId, no operation_id / extension_properties / request_bodies / security_schemes)
  • #[SerializedName('$ref')] still emits $ref

Verified failing on the buggy wiring, passing with the fix. Full OpenApiTest + OpenApiNormalizerTest suites green (28 tests, 268 assertions).

…document

PR api-platform#8306 wired serializer.name_converter.metadata_aware into the OpenAPI
serializer to honor #[SerializedName('$ref')] on Reference. That service
carries framework.serializer.name_converter as its fallback, so a globally
configured converter (e.g. camelCase_to_snake_case) leaked into the spec,
producing keys like operation_id, extension_properties, request_bodies that
break openapi-generator-cli.

Use a dedicated MetadataAwareNameConverter with no fallback: SerializedName
metadata is still honored, the global converter no longer applies.
@soyuka soyuka force-pushed the fix-openapi-name-converter-8306 branch from 60f66c6 to 62d033e Compare June 29, 2026 15:06
Comment thread src/Symfony/Bundle/Resources/config/openapi.php Outdated
Co-authored-by: Antoine Bluchet <soyuka@users.noreply.github.com>
@soyuka soyuka merged commit 43e3b4c into api-platform:4.3 Jun 30, 2026
111 of 112 checks passed
@soyuka soyuka deleted the fix-openapi-name-converter-8306 branch June 30, 2026 06:35
@thomas-hiron

Copy link
Copy Markdown
Contributor

Fix confirmed, thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants