openapi3: record scalar-valued map keys for origin location lookup#19
Open
reuvenharrison wants to merge 1 commit into
Open
openapi3: record scalar-valued map keys for origin location lookup#19reuvenharrison wants to merge 1 commit into
reuvenharrison wants to merge 1 commit into
Conversation
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
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.
What
Record the per-key locations of a scalar-valued map (e.g. an OAuth flow's
scopes) on the parent struct'sOrigin, so a consumer can locate an individual entry by key.Why
A scalar-valued map such as
decodes into a Go
map[string]string, which has noOriginfield of its own. The per-key locations are present in the OriginTree, butapplyOriginsToMapdiscards 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 ownOrigin.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 ownOriginvia the normal recursion. No yaml3 change is needed: the key locations are already in the OriginTree.Tests
TestOrigin_Securitynow assertsImplicit.Origin.Sequences["scopes"]resolvesread:pets/write:petsto their exact lines. Fullopenapi3suite passes.