You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
x-go-type on a schema with allOf is silently ignored; first member's x-go-type leaks through instead #2335
When a schema has both allOf and x-go-type, the x-go-type directive on the schema itself is silently ignored. Worse, if any allOf member has its own x-go-type, that override leaks through and becomes the alias target for the outer schema — producing a nonsensical alias that drops fields the user expects.
This was originally surfaced as an overlay issue in #2087, but the bug is unrelated to overlays. Overlays merely make it easy to add x-go-type to a third-party spec; the same misbehavior reproduces with a hand-edited spec containing no overlay at all.
PR #2087 contains a runnable demonstration in examples/anyof-allof-oneof/.
Root cause
There are two compounding bugs.
(1) pkg/codegen/schema.go:335-342 — The allOf branch in GenerateGoSchema returns before the x-go-type check at line 344:
if schema.AllOf \!=nil {
mergedSchema, err:=MergeSchemas(schema.AllOf, path)
...returnmergedSchema, nil// early return; x-go-type never consulted
}
// Check x-go-type, which will completely override the definition ...ifextension, ok:=schema.Extensions[extPropGoType]; ok { ... }
The code comment explicitly states x-go-type "will completely override the definition of this schema" — this contract is violated when the outer schema uses allOf.
(2) pkg/codegen/merge_schemas.go:113-116 — mergeOpenapiSchemas unions extensions from both sides without filtering out Go-specific directives:
So Client's x-go-type: OverlayClient is copied into the merged schema's extensions. mergeSchemas then recursively calls GenerateGoSchema on the merged schema (line 62), which this time has no AllOf, hits the x-go-type branch, and emits type ClientWithId = OverlayClient.
Version
Reproduced on main as of PR #2087 (commit f64f92b).
It's nonsensical to merge any of our extensions which appear at the schema level. I was a bit hasty in merging all of them when I wrote that code originally.
The behavior can't be correct in any case that comes up. I had Claude go through and find the interaction of all extensions with allOf, and I agree with it, that merge should be dropped.
Identity-bound (never merge)
- x-go-type, x-go-type-name, x-go-type-import — name or define this specific schema. A+B is a different shape than either; inheriting one side's
identity claim is always wrong.
- x-deprecated-reason (when on a schema) — "component X is deprecated" shouldn't automatically make everything that allOfs X deprecated. Parent has
its own lifecycle.
Usage modifiers (never merge)
- x-go-type-skip-optional-pointer — describes "when a field of this type is optional, how to represent it." A child's preference doesn't bind the
merged parent. Note this one is read at schema.go:298-305 from the outer schema's extensions before the allOf branch, so the outer schema's setting
already wins on the first pass. The merge just re-leaks it on the recursive call. Don't propagate.
Enum-specific (never merge)
- x-enum-varnames, x-enumNames — only meaningful on enum schemas. In theory you could imagine merging two compatible enum-allOf by unioning values
(mergeOpenapiSchemas already does this for Enum at line 154), in which case you'd want to union the varnames in matching order. But (a) allOf-ing
enums is an unusual pattern, (b) positional alignment would be fragile, and (c) the safer posture is "set it on the merged schema explicitly if you
want it." Don't propagate.
Field-level (not applicable)
x-go-name, x-go-json-ignore, x-omitempty, x-omitzero, x-oapi-codegen-extra-tags, x-oapi-codegen-only-honour-go-name, x-order — live inside property
definitions, not at the schema level. They ride along correctly when maps.Copy(result.Properties, ...) copies the property SchemaRefs whole (lines
217-220). That's different machinery and isn't affected by the extension-merge question.
Unknown user extensions
A user might put x-my-org-doc-tag: "pii" on Client. Should that propagate to ClientWithId? We can't know its semantics. Default-deny is safer — if the
user wants it on the merged result, they put it there directly (or via overlay on the merged schema's path).
Activity
mromaszewicz commentedon Apr 23, 2026
It's nonsensical to merge any of our extensions which appear at the schema level. I was a bit hasty in merging all of them when I wrote that code originally.
The behavior can't be correct in any case that comes up. I had Claude go through and find the interaction of all extensions with allOf, and I agree with it, that merge should be dropped.
Reorganize bug test case
fix: honor x-go-type on allOf schemas, stop extension leakage (oapi-c…
Bug Report: demonstration of overlays and allOf not playing together …
feat(v3): allOf can only annotate external and x-go-type schemas (#2568)
test(overlay): keep only overlay-specific tests under internal/test/o…
feat(overlay): apply overlays with an in-tree applier on theory/jsonp…