[BUG][CORE] Fix #18963: stop reusing anonymous inline schemas across different parent schemas#23974
Open
rvlasveld wants to merge 1 commit into
Open
Conversation
3 tasks
94b336d to
81774d7
Compare
1 task
…ents (OpenAPITools#18963) Anonymous (untitled) inline schemas have context-derived names (e.g. `Item_user`). When two parent schemas define structurally identical inline objects without a `title`, the resolver was reusing the first-seen model for all subsequent matches, forcing a misleading name onto unrelated contexts. The fix adds a title guard in `matchGenerated`: only titled schemas are eligible for structural reuse, consistent with the two other dedup paths in the same file that already gate on `title`: - the `flatten()` pre-populate step (lines 198-202) - the `deduplicateComponents()` post-pass (line 1203-1204) All parser-mutation regression tests are unaffected — their test schemas are titled (`Widget`, `StorageBackend`, `Container Mapping`, etc.). Samples require regeneration after this change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
81774d7 to
2e2ca25
Compare
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
Fixes #18963.
Two different component schemas (e.g.
ItemandIssue) each declare an anonymous (untitled) inlineuserobject with identical members. The generator de-duplicates them by structural content, so bothItemDtoandIssueDtoend up referencing a singleItemUserDto. This is wrong: the two objects are conceptually distinct, and the reused name (ItemUserDto) is misleading in theIssuecontext.Root cause:
matchGenerated()inInlineModelResolvermatches by serialized content alone, ignoring whether the schema has atitle. Anonymous inline schemas have context-derived names (Item_user,Issue_user) that are arbitrary — reusing one parent's model for another's context forces a misleading name.Fix: Add a title guard in
matchGenerated: if a schema has notitle, returnnullimmediately (don't reuse). Only titled schemas represent intentionally shared named types.This makes the runtime cache consistent with the two other dedup paths in the same file that already gate on
title:flatten()pre-populate step (seeds only titled component schemas into the signature cache)deduplicateComponents()post-pass (skips untitled schemas:if (schema.getTitle() == null) continue)Changes
InlineModelResolver.java— add title guard inmatchGenerated()InlineModelResolverTest.java— add regression test for [BUG] [Kotlin] DTOs for components of different components are conflated if they have the same members #18963; updatetestInlineSchemaSkipReuseSetToFalseto reflect new default (anonymous schemas now get separate models)docs/customization.md— document the new default behaviourExisting tests unaffected
All
resolveInlineModelDeduplicates*regression tests use titled schemas (Widget,StorageBackend,Container Mapping,Deletion Request) — they continue to deduplicate correctly.Note on samples
This is a core behaviour change. Samples that happen to contain specs with structurally-identical anonymous inline objects across different parents will gain additional model classes. Sample regeneration is required before merge (
./bin/generate-samples.sh).Alternative (opt-in, no breaking change): #23975 adds
SKIP_ANONYMOUS_SCHEMA_REUSE=trueas aninlineSchemaOption(default off, no sample churn). Use that PR if a default behaviour change is undesirable.Test plan
InlineModelResolverTest#resolveAnonymousInlineSchemaNotReusedAcrossParents— direct [BUG] [Kotlin] DTOs for components of different components are conflated if they have the same members #18963 regression (Item/Issue with identical anonymoususerinline object)InlineModelResolverTest#testInlineSchemaSkipReuseSetToFalse— updated: bothmeta_200_responseandmega_200_responsenow created (anonymous schemas no longer reused by default)resolveInlineModelDeduplicates*tests — titled-schema dedup still works./bin/generate-samples.sh+./bin/utils/ensure-up-to-date🤖 Generated with Claude Code