Skip to content

origin: record scalar-valued mapping keys as a sequence#15

Closed
reuvenharrison wants to merge 2 commits into
v3from
feat/origin-map-key-locations
Closed

origin: record scalar-valued mapping keys as a sequence#15
reuvenharrison wants to merge 2 commits into
v3from
feat/origin-map-key-locations

Conversation

@reuvenharrison

@reuvenharrison reuvenharrison commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

What

addOrigin already records per-item locations for sequence-valued fields under a mapping's __origin__. This extends it to also record the keys of a scalar-valued mapping (a map of atomic values) into the same sequence slot, addressable by name.

Why

A scalar-valued mapping, e.g.

labels:
  env: production
  region: us-east

decodes into a Go map[string]V with scalar V, which carries no Origin field of its own. The per-key __origin__ injected on the nested mapping node is therefore lost on decode, so a consumer has no way to locate an individual entry. The only place a key's location can survive decode is on the parent object's origin, which does have somewhere to store it.

Recording the keys as a sequence under the parent (reusing the existing sequences encoding, items addressable by name) makes each entry's location reachable by consumers that already read Origin.Sequences.

Object-valued mappings are unaffected: each of their values is itself a mapping that already carries its own __origin__, so isScalarValuedMapping gates them out to avoid redundant data.

Tests

TestOrigin_Map and TestOrigin_MapOfScalars are updated to reflect the new sequence section (the parent now records the scalar-map keys); TestOrigin_MapOfScalars gains a doc comment explaining the behavior. Full suite passes.

addOrigin already records per-item locations for sequence-valued fields
under a mapping's __origin__. Extend it to also record the keys of a
scalar-valued mapping (a map of atomic values) into the same sequence
slot, addressable by name.

Such a mapping decodes into a Go map type that carries no Origin field of
its own, so the per-key __origin__ injected on the nested mapping node is
lost on decode. Recording the keys on the parent's __origin__, which does
have somewhere to live, makes each entry's location reachable.

Object-valued mappings are unaffected: each of their values is a mapping
that already carries its own __origin__, so isScalarValuedMapping gates
them out to avoid redundant data.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BqJA1X6suZYtR3tRbX8sLj
@reuvenharrison reuvenharrison force-pushed the feat/origin-map-key-locations branch from c5c3ef2 to 06913e3 Compare June 29, 2026 12:07
This is a general-purpose YAML library, so its comments shouldn't lean on
a particular consumer's domain. Drop the issue-tracker URLs and the
endpoint/kin references from the origin comments, keeping the behavioral
description each one carried.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BqJA1X6suZYtR3tRbX8sLj
@reuvenharrison

Copy link
Copy Markdown
Collaborator Author

Superseded: no yaml3 change is needed. The per-map-entry key locations are already present in the OriginTree (verified against released v0.0.14); they were only being discarded downstream when a scalar-valued mapping decodes into a Go map with no Origin field. The fix belongs in kin-openapi's applyOrigins (the layer that knows a field is a map[string]scalar), which also avoids the over-firing this PR caused on schema objects. Closing in favor of the kin-side change.

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