fix(InlineModelResolver): do not merge untitled inline schemas differing only by description (#24004)#24007
Open
seonwooj0810 wants to merge 1 commit into
Conversation
…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>
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.
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:
abc→…Abc,def→…Def.defwith type…Abc, so code expecting…Defno 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/examplestripped at every level and was consulted/registered for all schemas inmatchGenerated()/addGenerated(). Once those volatile fields are stripped,abcanddefproduce an identical signature, sodefis unified withabc.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 anddeduplicateComponents()already note ("anonymous schemas may be intentionally distinct").Fix
Restrict the structural-signature fallback (both lookup in
matchGenerated()and registration inaddGenerated()) to schemas with a non-nulltitle. 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 assertsabc/defresolve to distinct$refs. Verified it fails on master and passes with this change.Full
InlineModelResolverTestsuite (including the #23856 structural-dedup regression tests…MutatesPropertyDescriptions,…MutatesPropertyTypes, and the multi-fileroot.yamlcases) passes:Verification done: built/tested on JDK 21 via
./mvnw -pl modules/openapi-generator -am test -Dtest=InlineModelResolverTest.PR checklist
./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); fullInlineModelResolverTestpasses unchanged.master.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.
InlineModelResolver(matchGenerated()andaddGenerated()).abc/definline objects resolve to distinct$refs.Written for commit a30b402. Summary will update on new commits.