Skip to content

fix(openapi): disambiguate definition names when input and output share a shortname#8230

Merged
soyuka merged 1 commit into
api-platform:4.3from
soyuka:fix/definition-name-input-output-collision-8169
Jun 3, 2026
Merged

fix(openapi): disambiguate definition names when input and output share a shortname#8230
soyuka merged 1 commit into
api-platform:4.3from
soyuka:fix/definition-name-input-output-collision-8169

Conversation

@soyuka
Copy link
Copy Markdown
Member

@soyuka soyuka commented Jun 3, 2026

Summary

When an operation declares both input and output as DTO classes that share the same basename
(but live in different namespaces), DefinitionNameFactory produced an identical definition name
for 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 createPrefixFromClass
disambiguation 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::class and
output: App\...\Output\ThingCreate::class — before this fix both produced the same $ref
(e.g. #/definitions/Thing.ThingCreate.jsonld).

Test plan

  • Added failing test covering the bug.
  • Test passes after the fix.
  • Related test classes still pass locally.

Fixes #8169

…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
@soyuka soyuka merged commit c835589 into api-platform:4.3 Jun 3, 2026
106 of 108 checks passed
@soyuka soyuka deleted the fix/definition-name-input-output-collision-8169 branch June 3, 2026 14:48
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.

1 participant