fix(InlineModelResolver): do not deduplicate distinctly-named component schemas (#24177)#24200
Open
Shaun-3adesign wants to merge 1 commit into
Conversation
…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.
5 tasks
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 #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_1sitting alongsideFlowSegment— 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:
On 7.22.0 both
Upper1andUpper2are generated; on 7.23.0 → master,Upper2disappears. Because both schemas have atitle, the earliertitle != nullguards (inflatten()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 restrictdeduplicateComponents()removal to numbered names:The deduplication keeps collapsing generated artifacts exactly as before, but never deletes a distinctly-named user schema. No new option/flag is added.
Verification
deduplicateComponentsKeepsDistinctlyNamedUserSchemas— red before the fix (logsRemoved duplicate component schema 'upper2'), green after.InlineModelResolverTestsuite: 57/57 pass (JDK 21), including every existing numbered-duplicate test (Widget_1,FlowSegment,StorageBackend_1,ContainerMapping_1, fix(InlineModelResolver): do not merge untitled inline schemas differing only by description #24192).foo.yamlnow emits bothUpper1.javaandUpper2.java.No
.mustachetemplates are touched — this is a code-generator logic change only./cc @wing328 @seonwooj0810
PR checklist
Summary by cubic
Fixes a bug where
InlineModelResolverremoved 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..*_\\d+$, e.g.,Foo_1).deduplicateComponentsKeepsDistinctlyNamedUserSchemas.Written for commit 2d95832. Summary will update on new commits.