fix: prevent duplicate __origin__ on YAML anchor alias expansion#1
Merged
reuvenharrison merged 1 commit intov3from Mar 30, 2026
Merged
Conversation
When a YAML alias (*anchor) is used as a map value or sequence element, the decoder re-walks the anchor's subtree via d.unmarshal(n.Alias, ...). This caused addOriginInMap/addOriginInSeq to append a second __origin__ entry to nested MappingNodes that were already annotated when the anchor was first processed — producing a "mapping key already defined" error on any spec that uses YAML anchors with nested objects. Fix: skip origin injection while inside an alias expansion (aliasDepth > 0). The anchor's origin from the definition site is preserved; alias use sites do not get their own injection (which would mutate the shared anchor node). Regression test for oasdiff/oasdiff#821. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Summary
*Nodepointer for the anchor targetaddOriginInMap/addOriginInSeqappended__origin__to nested mapping nodes once at the anchor definition, then again for every alias expansion that re-walked the same subtreemapping key "__origin__" already definederror on any spec using YAML anchors with nested objectsFix
Skip origin injection while inside an alias expansion (
aliasDepth > 0). The anchor's origin from its definition site is preserved; alias use sites don't inject again, avoiding mutation of the shared anchor node.Two lines changed in
decode.go:Tests
Two regression tests added to
origin_test.go:TestOrigin_AnchorAliasInMap— alias used as a map value (exact repro from v1.12.4 regression: fails to load specs with YAML anchors (__origin__ duplicate key) oasdiff#821)TestOrigin_AnchorAliasInSequence— alias used as a sequence element with nested mappingsBoth tests were written first (failing), then the fix was applied.
Fixes oasdiff/oasdiff#821.
🤖 Generated with Claude Code