Skip to content

[BUG][CORE] Fix #18963: stop reusing anonymous inline schemas across different parent schemas#23974

Open
rvlasveld wants to merge 1 commit into
OpenAPITools:masterfrom
rvlasveld:fix/18963-no-reuse-anonymous-inline-schemas
Open

[BUG][CORE] Fix #18963: stop reusing anonymous inline schemas across different parent schemas#23974
rvlasveld wants to merge 1 commit into
OpenAPITools:masterfrom
rvlasveld:fix/18963-no-reuse-anonymous-inline-schemas

Conversation

@rvlasveld

@rvlasveld rvlasveld commented Jun 9, 2026

Copy link
Copy Markdown

Summary

Fixes #18963.

Two different component schemas (e.g. Item and Issue) each declare an anonymous (untitled) inline user object with identical members. The generator de-duplicates them by structural content, so both ItemDto and IssueDto end up referencing a single ItemUserDto. This is wrong: the two objects are conceptually distinct, and the reused name (ItemUserDto) is misleading in the Issue context.

Root cause: matchGenerated() in InlineModelResolver matches by serialized content alone, ignoring whether the schema has a title. 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 no title, return null immediately (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

Existing 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=true as an inlineSchemaOption (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 anonymous user inline object)
  • InlineModelResolverTest#testInlineSchemaSkipReuseSetToFalse — updated: both meta_200_response and mega_200_response now created (anonymous schemas no longer reused by default)
  • All resolveInlineModelDeduplicates* tests — titled-schema dedup still works
  • Regenerate samples: ./bin/generate-samples.sh + ./bin/utils/ensure-up-to-date

🤖 Generated with Claude Code

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Re-trigger cubic

…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>
@rvlasveld rvlasveld force-pushed the fix/18963-no-reuse-anonymous-inline-schemas branch from 81774d7 to 2e2ca25 Compare June 9, 2026 11:27
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.

[BUG] [Kotlin] DTOs for components of different components are conflated if they have the same members

1 participant