Repository navigation
feat(v3): allOf can only annotate external and x-go-type schemas - #2568
Merged
Merged
Conversation
schema-merging-behavior v3 no longer reads the schema of an allOf member
that is in another document, or that x-go-type replaces with a Go type.
Another generator run owns an external schema's type, and an x-go-type's
fields are unknown, so neither can be merged into a new struct.
- Such a member plus members that only annotate it (description,
nullable, readOnly, validation constraints, extensions other than
x-go-type) is that member's type: `allOf: [$ref ext#/User,
{nullable: true}]` is `*externalRef0.User` rather than a copy of
User's body.
- Combined with anything that shapes a Go type (properties, required,
type, another $ref, the parent's own properties), it is an error that
names both members. For an external schema it says that a reference
to another document can't be merged with other allOf members, and to
define the schema in this document; for x-go-type, to give the
composition an x-go-type of its own. Neither suggests v2: v2 generates
code for these shapes, but not correct code. In particular, v2 drops
an x-go-type member's type without a word (oapi-codegen#1622); v1 embeds it, if
that's what the spec author wants.
- A local component that is only a $ref to another document, directly
or through other such components, counts as external: kin-openapi
hands us the other document's schema for it, and copying it produced
references to types this package doesn't have. So does a local schema
that is an annotated external or x-go-type schema.
- Every member read goes through one function that refuses these
schemas, so nested allOfs and array items can't copy one either.
- External refs inside a member (properties, items,
additionalProperties) and external oneOf/anyOf variants are just type
names and keep working.
- v3 drops the remote-ref rewriting that flattening external schemas
needed (oapi-codegen#2288, oapi-codegen#2557).
- Errors from a nested allOf merge now keep their cause.
The aggregate matrix gains a `rejects:` shape key: a version that
rejects a shape gets a cell with the spec and config but no generated
code, and a test that expects the error. Two new x-go-type shapes use
it. They also add new v2 cells; no existing v1 or v2 cell changes.
Three fixtures test shapes v3 rejects, so their configs now pin
schema-merging-behavior: v2: oapi-codegen#2288 (multipackage/packageA), oapi-codegen#2470
(multipackage/discriminated_union_allof) and the oapi-codegen#2335 overlay fixture
(overlays/allof_merge_extensions). v2 is the default, so their
generated code is unchanged. Regenerating every fixture under v3 found
no other rejection. The only other difference is in
extensions/x_go_type, where an annotated $ref to an x-go-type schema
becomes the component's alias, which is the same Go type.
Closes: oapi-codegen#1622
Refs: oapi-codegen#2288
Refs: oapi-codegen#2335
Refs: oapi-codegen#2470
Refs: oapi-codegen#2557
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Contributor
|
This comment has been minimized.
This comment has been minimized.
- A $ref to a whole document (`./user.yaml`, no fragment) is no longer
treated as opaque. oapi-codegen has no Go type for such a schema and
inlines it wherever it's used, so v3 merges it like an inline schema.
Before, v3 rejected merging one and still copied it when annotated.
- Array items that merge an opaque schema with an annotating one keep
the annotations: `items: {nullable: true}` next to `items: $ref
ext#/User` now gives `[]*externalRef0.User`, not
`[]externalRef0.User`.
- x-go-type-name on a member that annotates an opaque one names the
composition's type, as it does anywhere else (`type MyUser =
externalRef0.User`), instead of being ignored.
- Errors name the member that brings an opaque schema in: a member
whose own allOf includes one ("#/components/schemas/Inner (whose
allOf includes ./common.yaml#/...)"), where the error used to name
only the external schema. They call the schema's own properties
"the schema's own properties" rather than "an inline schema", show an
inline member's x-go-type, and for OpenAPI 3.1 specs spell nullable
as `type: "null"`.
- v3 rejects old-allof-sibling-merging, so generateAllOfV3 no longer
checks it, and the merge no longer deletes an x-go-type that can't
reach it.
- New tests for 3.1 specs, whole-document refs, nested members,
nullable array items, x-go-type-name, and x-go-type items,
x-go-type-skip-optional-pointer and $ref siblings.
v1 and v2 are unchanged: regenerating the repository changes no file.
Regenerating every fixture under v3 gives the same result as before.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This was referenced Sep 24, 2026
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.
schema-merging-behavior v3 no longer reads the schema of an allOf member that is in another document, or that x-go-type replaces with a Go type. Another generator run owns an external schema's type, and an x-go-type's fields are unknown, so neither can be merged into a new struct.
allOf: [$ref ext#/User, {nullable: true}]is*externalRef0.Userrather than a copy of User's body.The aggregate matrix gains a
rejects:shape key: a version that rejects a shape gets a cell with the spec and config but no generated code, and a test that expects the error. Two new x-go-type shapes use it. They also add new v2 cells; no existing v1 or v2 cell changes.Three fixtures test shapes v3 rejects, so their configs now pin schema-merging-behavior: v2: #2288 (multipackage/packageA), #2470 (multipackage/discriminated_union_allof) and the #2335 overlay fixture (overlays/allof_merge_extensions). v2 is the default, so their generated code is unchanged. Regenerating every fixture under v3 found no other rejection. The only other difference is in extensions/x_go_type, where an annotated $ref to an x-go-type schema becomes the component's alias, which is the same Go type.
Closes: #1622
Refs: #2288
Refs: #2335
Refs: #2470
Refs: #2557