fix(gen): preserve schema Ref in single-element allOf fast path#1652
Merged
ernado merged 2 commits intoogen-go:mainfrom Mar 26, 2026
Merged
Conversation
When a component schema uses allOf with a single element, the allOf() fast path returned the inner schema directly without copying the outer schema's Ref field. This caused the type to be registered as anonymous instead of ref-keyed, leading to "anonymous type name conflict" errors when the same schema was referenced from multiple operations. Fixes ogen-go#1651
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.
When a component schema uses
allOfwith a single element (e.g.,nullable: true+type: object+allOf: [single item]), theallOf()fast path ingen/schema_gen_sum.goreturned the inner schema directly, losing the outer schema'sReffield. This caused the type to be registered as anonymous instead of ref-keyed, leading toanonymous type name conflicterrors when the same schema was referenced across multiple operations.The multi-element
allOfpath already preservesRefviamergedSchema.Ref = schema.Ref, but the single-element fast path skipped this.Fixes #1651
Likely fixed by PR:
Fix
Copy the outer schema's
Refonto the inner schema (via shallow copy) before generating, so the type is registered under the correct reference key and reused by subsequent operations.Reproduction
A schema like:
referenced from a parent schema used in two operations, once directly, once inside another allOf merge, would fail with: anonymous type name conflict: "Bar"
Test plan