Skip to content

openapi3: record scalar-valued map keys for origin location lookup#19

Open
reuvenharrison wants to merge 1 commit into
masterfrom
feat/origin-scalar-map-keys
Open

openapi3: record scalar-valued map keys for origin location lookup#19
reuvenharrison wants to merge 1 commit into
masterfrom
feat/origin-scalar-map-keys

Conversation

@reuvenharrison

Copy link
Copy Markdown

What

Record the per-key locations of a scalar-valued map (e.g. an OAuth flow's scopes) on the parent struct's Origin, so a consumer can locate an individual entry by key.

Why

A scalar-valued map such as

scopes:
  read:pets: read your pets
  write:pets: modify pets in your account

decodes into a Go map[string]string, which has no Origin field of its own. The per-key locations are present in the OriginTree, but applyOriginsToMap discards them for such maps (the values are plain strings with nowhere to hang an origin). As a result there was no way to point at an individual scope.

How

In applyOriginsToStruct, when a struct field is a scalar-valued map, copy its keys' locations from the child subtree onto the struct's own Origin.Sequences[field] (the same shape already used for sequence items), addressable by key name. Consumers read them via the existing sequence-item lookup.

Gated by isScalarValuedMapField, so it fires only for maps whose element is a scalar (string/bool/number) — scopes, discriminator.mapping, x- string maps. Pointer- or struct-valued maps (e.g. properties: map[string]*SchemaRef) are untouched, because their values already carry their own Origin via the normal recursion. No yaml3 change is needed: the key locations are already in the OriginTree.

Tests

TestOrigin_Security now asserts Implicit.Origin.Sequences["scopes"] resolves read:pets/write:pets to their exact lines. Full openapi3 suite passes.

A scalar-valued map (e.g. OAuth flow scopes: map[string]string) decodes
into a Go map that has no Origin field of its own, so the per-key
locations present in the OriginTree are discarded by applyOriginsToMap.
Capture them on the parent struct's Origin as a named sequence
(Sequences[field]), addressable by key, so a consumer can locate an
individual entry.

Gated by isScalarValuedMapField, so it fires only for maps with scalar
elements; pointer/struct-valued maps (e.g. properties) are untouched
because their values already carry their own Origin. No yaml3 change is
needed: the key locations are already in the OriginTree.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BqJA1X6suZYtR3tRbX8sLj
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