Skip to content

openapi3: remove StringMap and its pre-OriginTree origin-stripping machinery#20

Open
reuvenharrison wants to merge 5 commits into
masterfrom
remove-pre-origintree-leftovers
Open

openapi3: remove StringMap and its pre-OriginTree origin-stripping machinery#20
reuvenharrison wants to merge 5 commits into
masterfrom
remove-pre-origintree-leftovers

Conversation

@reuvenharrison

@reuvenharrison reuvenharrison commented Jul 11, 2026

Copy link
Copy Markdown

The OriginTree rewrite (getkin#1142) moved origin tracking to a separate pass that extracts __origin__ before JSON conversion, so no unmarshaler sees it anymore. A whole family of StringMap / origin-stripping machinery was left behind. This removes it end to end.

Commits

  1. Remove origin-stripping leftovers — three dead delete(map, originKey) calls (Encoding, Webhooks, Server.Variables), the now-unused originKey const, and the stale StringMap doc comment. (TestOrigin_* already assert __origin__ never appears as a map key.)
  2. Simplify the StringMap decode — the two-step json -> map[string]any -> deepCast -> V (sorted keys) existed to strip __origin__ and control ordering; post-rewrite it equals a plain json.Unmarshal. Drop deepCast — also removes a float64 round-trip precision risk on large integers.
  3. Remove the StringMap type — its only custom behavior is gone, so its two fields become plain maps: Discriminator.Mapping -> map[string]MappingRef, OAuthFlow.Scopes -> map[string]string.
  4. Drop the helpers and their pass-through UnmarshalJSONunmarshalStringMap/unmarshalStringMapP are now trivial json.Unmarshal wrappers, and the 13 named map types that called them from a custom UnmarshalJSON were pure pass-throughs. Remove those methods so the types decode via default map unmarshalling (identical result), and delete the helpers (none of the types have a MarshalJSON, so marshalling was already default).
  5. Regenerate API docs (docs.sh) and add the changelog entry.

Notes

  • Breaking API change: removes the exported openapi3.StringMap[V] type. The one known downstream consumer (oasdiff) needs a one-line signature change (mappingToStringMap -> map[string]openapi3.MappingRef), which is backward-compatible with the current release. Recorded in the README changelog.
  • No behavior change; full openapi3 suite green, and oasdiff's full suite passes when wired to this branch via a local replace.
  • Independent of openapi3: record scalar-valued map keys for origin location lookup #19 (scalar-valued map key origins): the two branches auto-merge cleanly, and openapi3: record scalar-valued map keys for origin location lookup #19's reflection-based scalar-map handling is unaffected by the field-type changes here.

reuvenharrison and others added 5 commits July 11, 2026 12:53
The OriginTree rewrite (getkin#1142) moved origin tracking to a separate pass that
extracts __origin__ before JSON conversion, so no unmarshaler sees it anymore
(the 'if k == originKey' blocks were removed then; TestOrigin_* asserts
__origin__ never appears as a map key). Three delete(map, originKey) calls
-- Encoding, Webhooks, Server.Variables -- and the StringMap doc comment were
missed by that cleanup.

Remove the dead deletes and the now-unused originKey const, and correct the
StringMap comment: it is a generic map[string]V, and no longer filters origin
from the json representation.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BqJA1X6suZYtR3tRbX8sLj
The two-step decode (json -> map[string]any -> deepCast back into V, iterating
sorted keys via componentNames) existed to strip __origin__ and control ordering
before the OriginTree rewrite (getkin#1142). Post-rewrite there is no __origin__ in the
json and the result is an (unordered) map, so it is equivalent to a plain
json.Unmarshal -- verified by the full suite. The round-trip also forced every
value's numbers through float64; a direct decode avoids that precision risk.

Decode straight into the map and drop the now-unused deepCast. componentNames
stays (still used for deterministic validation ordering).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BqJA1X6suZYtR3tRbX8sLj
StringMap[V] was a map[string]V whose only custom behavior was the two-step
origin-aware decode, now gone (the previous commit made it a plain
json.Unmarshal). Its two fields decode identically as plain maps -- the same
json.Unmarshal target -- so use map[string]MappingRef (Discriminator.Mapping)
and map[string]string (OAuthFlow.Scopes) directly and drop the type. The
unmarshalStringMap/P helpers stay; other map types still call them.

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

With deepCast/componentNames gone from the decode, unmarshalStringMap and
unmarshalStringMapP are plain json.Unmarshal wrappers, and the 13 named map types
that called them from a custom UnmarshalJSON were pure pass-throughs. Remove those
UnmarshalJSON methods so the types decode via default map unmarshalling (identical
result), and delete the now-unused helpers (stringmap.go). None of the types have
a MarshalJSON, so marshalling was already default -- the change stays symmetric.
The existing TestOrigin_* assertions confirm __origin__ still never leaks into
these maps.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BqJA1X6suZYtR3tRbX8sLj
@reuvenharrison reuvenharrison changed the title openapi3: remove pre-OriginTree StringMap leftovers openapi3: remove StringMap and its pre-OriginTree origin-stripping machinery Jul 11, 2026
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