fix(openapi): serialize Reference objects with $ref in the generated document#8306
Conversation
…document
The openapi serializer's inline ObjectNormalizer was built without a class
metadata factory or a metadata-aware name converter, so Reference::getRef()'s
#[SerializedName('$ref')] was ignored and emitted as "ref". Wire the standard
class_metadata_factory and metadata-aware name converter so the model's own
serialization metadata is honored.
Fixes api-platform#8143
The Issue8143 ReferenceResponse fixture emits a $ref to #/components/responses/401, but the generated document defined no such component, so the Redocly no-unresolved-refs rule failed. Register a test-only OpenApiFactory decorator that declares the reusable 401 response component so the $ref resolves, without weakening the assertion that $ref is emitted.
|
Hi! I think there is a regression with this. framework:
serializer:
name_converter: serializer.name_converter.camel_case_to_snake_case
api_platform:
path_segment_name_generator: api_platform.metadata.path_segment_name_generator.dash
name_converter: serializer.name_converter.camel_case_to_snake_caseAnd now, the spec is generated in snake_case: operation_id, extension_properties...
How to configure the spec being generated in camel case? Should I open an issue? Thanks! |
|
@thomas-hiron confirmed, this is a regression — not a config issue on your side. #8306 wired Fix in #8360: a dedicated |
…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.
Summary
A custom
OpenApiFactoryplacing aReferenceobject inOperation::$responsesproduced"ref"instead of"$ref"in the generated OpenAPI document. The dedicated inlineObjectNormalizerused byOpenApiNormalizerwas constructed without a class metadata factory or a metadata-aware name converter, soReference::getRef()'s#[SerializedName('$ref')]was never applied.Reference::$refis the only#[SerializedName]among the OpenAPI models, so the change only affects this property — emitting the spec-correct$ref.Reproduction
Serializing an OpenAPI document whose components/responses reference a schema via a
Referenceobject emitted the key asref, which is invalid per the OpenAPI spec.Test plan
OpenApiNormalizerTest) and functional test (OpenApiTest, real DI) asserting$refis present.Fixes #8143