Skip to content

fix(InlineModelResolver): do not merge untitled inline schemas differing only by description (#24004)#24007

Open
seonwooj0810 wants to merge 1 commit into
OpenAPITools:masterfrom
seonwooj0810:fix/issue-24004-untitled-inline-dedup
Open

fix(InlineModelResolver): do not merge untitled inline schemas differing only by description (#24004)#24007
seonwooj0810 wants to merge 1 commit into
OpenAPITools:masterfrom
seonwooj0810:fix/issue-24004-untitled-inline-dedup

Conversation

@seonwooj0810

@seonwooj0810 seonwooj0810 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #24004

Problem

A schema with two structurally-identical inline (untitled) object properties that differ only in their descriptions is generated differently in 7.22 vs 7.23. Given:

"properties": {
  "abc": { "type": "object", "description": "first container",
           "properties": { "result": { "type": "string", "description": "ABC Result" } } },
  "def": { "type": "object", "description": "second container",
           "properties": { "result": { "type": "string", "description": "DEF Result" } } }
}
  • 7.22 generates two distinct types — abc…Abc, def…Def.
  • 7.23 generates def with type …Abc, so code expecting …Def no longer compiles.

Root cause

The structural-signature dedup fallback introduced in #23856 (to prevent numbered duplicate models from multi-file OAS 3.1 specs) serialises schemas with description/type/example stripped at every level and was consulted/registered for all schemas in matchGenerated()/addGenerated(). Once those volatile fields are stripped, abc and def produce an identical signature, so def is unified with abc.

That fallback is only appropriate for titled named types (which should be reused wherever they appear, despite parser-induced volatility). Anonymous/untitled inline schemas may be intentionally distinct — exactly as the existing titled-only guards in flatten() pre-population and deduplicateComponents() already note ("anonymous schemas may be intentionally distinct").

Fix

Restrict the structural-signature fallback (both lookup in matchGenerated() and registration in addGenerated()) to schemas with a non-null title. Exact-signature matching is unchanged, so genuine duplicates are still reused, and the #23856 multi-file dedup behaviour (which operates on titled schemas) is preserved.

Test evidence

Added InlineModelResolverTest#resolveInlineModelKeepsUntitledSchemasDifferingOnlyByDescriptionDistinct, which reproduces the issue and asserts abc/def resolve to distinct $refs. Verified it fails on master and passes with this change.

Full InlineModelResolverTest suite (including the #23856 structural-dedup regression tests …MutatesPropertyDescriptions, …MutatesPropertyTypes, and the multi-file root.yaml cases) passes:

Tests run: 56, Failures: 0, Errors: 0, Skipped: 0

Verification done: built/tested on JDK 21 via ./mvnw -pl modules/openapi-generator -am test -Dtest=InlineModelResolverTest.

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore samples — N/A: this change does not alter generated output for any existing sample (no committed sample uses two untitled inline schemas differing only by description); full InlineModelResolverTest passes unchanged.
  • Filed the PR against the correct branch: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Summary by cubic

Prevent merging of untitled inline schemas that differ only by description, restoring distinct generated types and fixing a 7.23 regression. Structural-signature dedup now applies only to titled schemas; named types are still reused as expected.

  • Bug Fixes
    • Limit structural-signature fallback to titled schemas in InlineModelResolver (matchGenerated() and addGenerated()).
    • Keep exact-signature dedup unchanged for true duplicates.
    • Add regression test to ensure abc/def inline objects resolve to distinct $refs.
    • Preserve multi-file OAS 3.1 reuse behavior for titled schemas.

Written for commit a30b402. Summary will update on new commits.

Review in cubic

…ing only by description

The structural-signature dedup fallback added for multi-file OAS 3.1 specs
(OpenAPITools#23856) strips description/type/example at every level and was applied to all
schemas in matchGenerated()/addGenerated(). For untitled inline schemas that are
structurally identical once those fields are stripped but intentionally distinct
(e.g. two response properties differing only by description), this collapsed them
into a single generated type, changing one property's type and breaking compiling
user code (regression since 7.23).

Restrict the structural-signature fallback to titled schemas only, mirroring the
existing titled-only guards in flatten() pre-population and deduplicateComponents()
("anonymous schemas may be intentionally distinct"). Exact-signature matching is
unaffected, so genuine duplicates are still reused.

Fixes OpenAPITools#24004

Signed-off-by: seonwoo_jung <79202163+seonwooj0810@users.noreply.github.com>

@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] [JAVA] Deduplication feature in 7.23 breaks existing code

1 participant