fix(openapi): disambiguate definition names when input and output share a shortname#8230
Merged
soyuka merged 1 commit intoJun 3, 2026
Conversation
…re a shortname When an operation declares both input and output DTO classes whose FQCNs differ but whose basenames are identical (e.g. App\...\Input\ThingCreate and App\...\Output\ThingCreate), DefinitionNameFactory produced the same definition name for both. The input schema was overwritten by the output schema and Swagger UI displayed the output DTO as the request body. Reuse the existing createPrefixFromClass disambiguation (already used for the resource class itself) for the input/output suffix. This keeps existing definition names stable for the common case where the DTO short name does not collide with anything else, and falls back to progressively longer namespace-qualified suffixes only when a real collision is detected. Fixes api-platform#8169
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When an operation declares both
inputandoutputas DTO classes that share the same basename(but live in different namespaces),
DefinitionNameFactoryproduced an identical definition namefor both, so the input schema was overwritten by the output schema and Swagger UI displayed the
output DTO as the request body. This patch reuses the existing
createPrefixFromClassdisambiguation for the input/output suffix, so colliding short names now fall back to
progressively longer namespace-qualified suffixes — existing non-colliding names are unchanged.
Reproduction
Declare an operation with
input: App\...\Input\ThingCreate::classandoutput: App\...\Output\ThingCreate::class— before this fix both produced the same$ref(e.g.
#/definitions/Thing.ThingCreate.jsonld).Test plan
Fixes #8169