Repository navigation
feat: add schema-merging-behavior v3 as a copy of v2 - #2564
Merged
Merged
Conversation
Adds v3, the schema-merging-behavior version that further work on allOf/anyOf/oneOf goes into. In this commit it is an exact copy of v2, so every later change to it shows up as a diff against v2's behavior. - merge_schemas_v3.go and union_v3.go are merge_schemas_v2.go and union_v2.go with the V2 suffixes renamed to V3; only their header comments and one comment about v1's merge (which v3 never uses) differ. generateAllOf, generateUnions and schemaMergerFor dispatch v3 to them. - `schema-merging-behavior: v3` is accepted, but is not documented or exported yet. It rejects old-merge-schemas and old-allof-sibling-merging in the same function Validate and Generate share. - schemaMergerFor now names v2 explicitly and panics on a version it doesn't know, so a future version that isn't wired in fails loudly instead of generating v2's output. - The configuration schema's description of v1 now says that anyOf/oneOf are handled as in v2, as the Go doc already did. Tests: - Every matrix shape now also runs under v3; the new matrix/v3 packages generate the same code as their v2 counterparts, apart from package names. The shape files that v1 and v2 use changed only in their `versions:` lists, which add v3 (shapes that listed none now list v2 explicitly), so the v1 and v2 packages are unchanged. - The hand-written v2 matrix tests and merge_schemas_v2_test.go are copied for v3 (test names suffixed V3); the v2 originals are unchanged. - New tests pin the version-to-merge mapping, and check that Configuration.Validate reports invalid schema-merging settings. - .greptile/rules.md notes that v3's code and tests are expected to change, and that shapes now always list their versions. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Contributor
|
This was referenced Sep 24, 2026
mromaszewicz
added a commit
that referenced
this pull request
Sep 26, 2026
v3 has been accepted but undocumented while it was built (#2564 to #2580). This makes it an option like the others, and documents it: - docs/schema-merging.md explains the three versions: v1 embeds an allOf's member types and is very limited, v2 is the default, and v3 is an option that becomes the default after at least one release as one. It shows how v1's embedding differs from v2 and v3's composition, compares v2 and v3 side by side with the code each generates, lists where v3 reads the spec generously with the spelling validators also accept, and says what to check when moving to v3. - The README's anyOf/allOf/oneOf FAQ says there are three ways and links the new page. Its IdentityWithDuplicateField example, which documented v2's last-wins merge that v3 rejects, now refines the property instead, and generates the same code under v2 and v3; so does examples/anyof-allof-oneof, which it mirrors. - SchemaMergingV3 is exported, and v3 is in the configuration schema's enum, the SchemaMergingBehavior doc comment, the unknown-value error and docs/configuration.md, which also lists lenient-union-accessors. - docs/extensions.md and the README's table document x-oapi-codegen-enum-merge. Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
mromaszewicz
added a commit
that referenced
this pull request
Sep 26, 2026
* refactor: one sameSchema for schema-merging-behavior v2 and v3 sameSchemaV2 and sameSchemaV3 were byte-identical: the one function of the v2 copy that v3 never changed. It is now sameSchema, in merge_schemas.go with the code every version shares. Generated output is unchanged. Co-Authored-By: Claude Fable 5.1 <[email protected]> * refactor: share the allOf recursion and alias bookkeeping between v2 and v3 generateAllOfV2 and generateAllOfV3 began and ended with the same 69 lines: the reference to a composition an enclosing frame is already generating (issue #2542), and, after the merge, the alias target for generatesMarshalJSON, the description, x-go-type-skip-optional-pointer and the naming of a recursive composition. They are now genContext.inProgressAllOf and finishAllOf in merge_schemas.go, whose file comment says that the versions move in step for the code there. Each version keeps only its own middle. Generated output is unchanged. Co-Authored-By: Claude Fable 5.1 <[email protected]> * refactor: share the nullable-union collapse between v2 and v3, in union.go generateUnionV2 and generateUnionV3 had the same 54 lines to collapse a oneOf or anyOf whose only branch besides a 3.1 null one is that branch. They are now effectiveBranches and collapseNullableUnion in a new union.go, the anyOf/oneOf counterpart of merge_schemas.go. generateUnions and the union helpers every version reads (unionTextKinds, discriminatorValueType, findProperty, propertyNames, scalarType, and the Schema methods for the union template's text binding) move there from schema.go unchanged. Generated output is unchanged. Co-Authored-By: Claude Fable 5.1 <[email protected]> * refactor: drop dead code and constant parameters from the allOf and union code - refToGoTypeMap in generateUnionV2 and generateUnionV3 was written and never read. - generateAllOfV3 was always handed mergeSchemasV3; it calls it directly. - opaqueSchemaFor was always called with a nil seen set. - allOfMerge.member was set by every caller just before add and cleared at the top of add: a parameter passed through a field. It is add's first parameter now. - The label of a nested allOf member was computed once in add and once in allOfMemberLabel; allOfMemberLabel takes the parent's label. - MergeSchemas and Discriminator.PropertyName had no caller in the repo, templates included. Generated output and error messages are unchanged. Co-Authored-By: Claude Fable 5.1 <[email protected]> * refactor: drop the V2/V3 suffix from one-version allOf and union helpers A V2 or V3 suffix marks a function with a same-named counterpart in another schema-merging-behavior version. #2563 suffixed every function of the v2 files and #2564 copied them all to v3, but v3 has since replaced its copies with code of other names, which left these without a counterpart: isExtensionOnlySchema, valueWithPropagatedRef, propagateRemoteRefs, qualifyRemoteRef, mergeAllOf, mergeOpenapiSchemas, sameTypeSet, mergeTypes, mergeItems and addNestedOwnProperties in v2, and withoutConstraintOnlyUnions and generateUnionComponents in v3. The suffix stays on the twins: mergeSchemas, generateAllOf, generateUnions, generateUnion, hasStructuralSiblings and isConstraintOnlyUnion. Generated output is unchanged. Co-Authored-By: Claude Fable 5.1 <[email protected]> * refactor: one union.stamp template for the From* and Merge* discriminator stamp union.tmpl had the same eight lines twice, assigning the stamped discriminator value to the union struct's own field in From* and in Merge*. They are now a union.stamp template, called from both. The template keeps the indentation and trim markers of the inline blocks, so generated code is unchanged with and without skip-fmt. Co-Authored-By: Claude Fable 5.1 <[email protected]> * refactor(v3): walk allOf trees and alias chains with one iterator each v3 walked the tree of a schema and its allOf members, all the way down, in five places, each with its own nil checks, seen set and recursion: opaqueSchemaWithin, allOfMerge.markFlattening, declaredVariantKeys, pinnedDiscriminatorValue and discriminatorPropertyTyped. They now range over allOfTree, which yields the schemas in the same order and stops a cycle the same way. standsFor and declaredTypes keep their own walks: one judges the other members of each composition, the other folds the types. aliasGeneratesMarshalJSON and v3's variantKeys followed a schema's aliases with the same loop; it is Schema.aliasChain now, and each keeps its own check per step. Generated output is unchanged. Co-Authored-By: Claude Fable 5.1 <[email protected]> * refactor: appendUnique for the append-unless-present idiom Ten places in the allOf and union code appended a value to a slice unless slices.Contains found it there, three lines each; one wrapped the idiom in a closure. They call appendUnique now. The order of every slice is as before, so generated output is unchanged. Co-Authored-By: Claude Fable 5.1 <[email protected]> * docs: bring the allOf and union comments up to date with the code - gencontext.go said the allOf code lives in merge_schemas_v2.go and that generateAllOfV2 registers, names and re-checks a recursive composition; both versions do, through inProgressAllOf and finishAllOf. - rootPosition was described as a diagnostic for a case believed impossible. v3 reads it to keep a component from being defined as an alias of itself (annotatedRefMember), which TestAnnotatedRefV3Aliases covers. - schema.go and externalref.go named generateUnionV2 for what every version's union generator does, and aliasOf's setters had moved. - A comment in mergeSchemasV3 ended with an empty line. Co-Authored-By: Claude Fable 5.1 <[email protected]> --------- Co-authored-by: Claude Fable 5.1 <[email protected]>
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.
Adds v3, the schema-merging-behavior version that further work on allOf/anyOf/oneOf goes into. In this commit it is an exact copy of v2, so every later change to it shows up as a diff against v2's behavior.
schema-merging-behavior: v3is accepted, but is not documented or exported yet. It rejects old-merge-schemas and old-allof-sibling-merging in the same function Validate and Generate share.Tests:
versions:lists, which add v3 (shapes that listed none now list v2 explicitly), so the v1 and v2 packages are unchanged.