Expose AllowDuplicateKeys on DecodeOpts - #17
Open
reuvenharrison wants to merge 1 commit into
Open
Conversation
Passes through to the yaml3 decoder option of the same name. A repeated mapping key is an error by default, which is YAML's rule; enabling this makes the last occurrence win, which is what encoding/json does with a repeated JSON object name. It matters for a caller that decodes both YAML and JSON into the same types: without it, a document loads or fails depending only on which format it happens to be written in, since this package's yaml path rejects repeated keys while a direct json.Unmarshal accepts them. Tests assert the surviving value rather than only the absence of an error, and cover composition with origin tracking, since the option has to survive the JSON round trip this package performs and must not disable origin extraction. yaml3 is pinned to the commit carrying the option; repoint at the tag once it is cut.
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.
Passes through to
Decoder.AllowDuplicateKeysin oasdiff/yaml3#17.Why
A repeated mapping key is an error on this package's YAML path, which is YAML's rule.
encoding/jsontakes the last occurrence for a repeated JSON object name — RFC 8259 says names SHOULD be unique, so the handling is the implementation's to choose.That difference is invisible until one program decodes both formats into the same types. Then a document loads or fails depending only on which format it happens to be written in, which is nobody's intended behaviour.
What
DecodeOpts.AllowDuplicateKeys. Default false, so behaviour is unchanged: repeated keys still error. Enabled, the last occurrence wins.Tests
Assert the surviving value, not merely the absence of an error — "does not fail" would equally be satisfied by dropping the key or keeping the first, and neither matches
encoding/json. Also covers composition with origin tracking, since the option has to survive the JSON round trip this package performs and must not disable origin extraction.Note
yaml3is pinned to the commit carrying the option (v0.0.15-0.20260802195239-79d189934084). Repoint at the tag once oasdiff/yaml3#17 merges and is tagged.