Skip to content

Expose AllowDuplicateKeys on DecodeOpts - #17

Open
reuvenharrison wants to merge 1 commit into
mainfrom
feat/allow-duplicate-keys
Open

Expose AllowDuplicateKeys on DecodeOpts#17
reuvenharrison wants to merge 1 commit into
mainfrom
feat/allow-duplicate-keys

Conversation

@reuvenharrison

Copy link
Copy Markdown
Collaborator

Passes through to Decoder.AllowDuplicateKeys in oasdiff/yaml3#17.

Why

A repeated mapping key is an error on this package's YAML path, which is YAML's rule. encoding/json takes 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

yaml3 is 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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant