Skip to content

fix(InlineModelResolver): do not deduplicate distinctly-named component schemas (#24177)#24200

Open
Shaun-3adesign wants to merge 1 commit into
OpenAPITools:masterfrom
Shaun-3adesign:fix/24177-preserve-distinctly-named-schemas
Open

fix(InlineModelResolver): do not deduplicate distinctly-named component schemas (#24177)#24200
Shaun-3adesign wants to merge 1 commit into
OpenAPITools:masterfrom
Shaun-3adesign:fix/24177-preserve-distinctly-named-schemas

Conversation

@Shaun-3adesign

@Shaun-3adesign Shaun-3adesign commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #24177 (a follow-on to the #23856 deduplication feature and the later #24192 fix).

Problem

deduplicateComponents() was introduced in #23856 to collapse numbered duplicates — e.g. FlowSegment_1 sitting alongside FlowSegment — that the Swagger Parser / inline resolver emit when a shared multi-file schema fails to be reused. Its removal logic, however, matched any two titled, structurally-identical component schemas.

Since 7.23.0 this also silently removes schemas the user authored by hand with distinct, non-numbered names. The reporter's minimal spec:

components:
  schemas:
    upper1:
      type: object
      properties: { foo: { type: string } }
      title: foo title identical by purpose
    upper2:
      type: object
      properties: { foo: { type: string } }
      title: foo title identical by purpose

On 7.22.0 both Upper1 and Upper2 are generated; on 7.23.0 → master, Upper2 disappears. Because both schemas have a title, the earlier title != null guards (in flatten() pre-population, matchGenerated(), and #24192) do not catch this case.

Fix

Two component keys can only both be non-numbered when the user deliberately named them that way — the parser always numbers its own collisions (_1, _2, …). So restrict deduplicateComponents() removal to numbered names:

if (name.matches(".*_\\d+$")) {
    duplicateToCanonical.put(name, canonical);
}

The deduplication keeps collapsing generated artifacts exactly as before, but never deletes a distinctly-named user schema. No new option/flag is added.

Verification

No .mustache templates are touched — this is a code-generator logic change only.

/cc @wing328 @seonwooj0810

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    No templates changed and the fix only withholds dedup from hand-named schemas, so no sample output is expected to change; deferring to CI to confirm across all generators.
  • If your PR is targeting a particular programming language, @mention the technical committee members — n/a, this is a core (language-agnostic) change.

Summary by cubic

Fixes a bug where InlineModelResolver removed user-defined component schemas with distinct, non-numbered names. Deduplication now only collapses parser-generated numbered duplicates (e.g., Foo_1), preserving authored schemas; fixes #24177.

  • Bug Fixes
    • Only deduplicate schemas with numbered names (matches .*_\\d+$, e.g., Foo_1).
    • Added regression test deduplicateComponentsKeepsDistinctlyNamedUserSchemas.
    • No template changes; behavior for numbered duplicates is unchanged.

Written for commit 2d95832. Summary will update on new commits.

Review in cubic

…nt schemas (OpenAPITools#24177)

deduplicateComponents() was added in OpenAPITools#23856 to collapse numbered duplicates
(e.g. FlowSegment_1 alongside FlowSegment) that the Swagger Parser / inline
resolver produce when a shared multi-file schema fails to be reused. Its
removal logic, however, matched any two titled, structurally-identical
component schemas — including ones the user authored by hand with distinct,
non-numbered names. Since 7.23.0 this silently dropped user-defined schemas
(reported in OpenAPITools#24177: 'upper1'/'upper2', identical title + structure, kept
separate on purpose), removing previously-generated model classes.

Two component keys can only both be non-numbered when the user deliberately
named them that way — the parser always numbers its own collisions. Restrict
removal to numbered names so the deduplication keeps collapsing generated
artifacts while never deleting a distinctly-named user schema.

Verified: full InlineModelResolverTest suite (57 tests) passes; the TAMS spec
that motivated OpenAPITools#23856 generates byte-for-byte identical output (modulo
timestamps); the OpenAPITools#24177 minimal spec now emits both Upper1 and Upper2.

@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 2 files

Re-trigger cubic

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] [regression] [7.23.0] [InlineModelResolver] Previously generated sources are no longer generated without fallback

2 participants