Skip to content

feat: add UnmarshalWithOriginTree — strip __origin__ before JSON conversion#16

Open
reuvenharrison wants to merge 28 commits intoinvopop:mainfrom
oasdiff:feat/origin-tree
Open

feat: add UnmarshalWithOriginTree — strip __origin__ before JSON conversion#16
reuvenharrison wants to merge 28 commits intoinvopop:mainfrom
oasdiff:feat/origin-tree

Conversation

@reuvenharrison
Copy link
Copy Markdown

Summary

  • Adds OriginTree type and extractOrigins function that strips __origin__ from the decoded map[string]any before JSON marshaling
  • New UnmarshalWithOriginTree API returns the extracted origin tree alongside the unmarshaled struct
  • Reduces intermediate JSON size by ~70% for large specs with origin tracking, eliminating the 5× overhead of carrying origin data through the JSON round-trip
  • Existing UnmarshalWithOrigin is preserved (calls new API, discards tree) for backward compatibility

Test plan

  • TestExtractOrigins_Map — verifies extraction from nested maps
  • TestExtractOrigins_Slice — verifies extraction from slices with mixed elements
  • TestExtractOrigins_Nil — verifies nil return for scalars and maps without origin
  • TestUnmarshalWithOriginTree — end-to-end: YAML decode + extraction + struct population
  • TestUnmarshalWithOriginTree_Disabled — nil tree when origin is disabled
  • Full existing test suite passes

🤖 Generated with Claude Code

reuvenharrison and others added 28 commits August 16, 2024 17:54
Pass source file path to yaml3 decoder so origin locations include
the file they were parsed from.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Includes both file parameter and sequence item origin tracking.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…diffs

Simplify UnmarshalWithOrigin: replace positional withOrigin/file params
with OriginOpt struct. Remove StripFromInterfaces logic from
convertToJSONableObject since all openapi3 types use custom unmarshalers
that bypass the yaml-level stripping anyway.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
fix: prevent duplicate __origin__ on YAML anchor alias expansion
Picks up the fix that skips __origin__ entries during alias expansion,
preventing spurious "excessive aliasing" errors on large specs with
many YAML aliases.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ersion

Adds OriginTree type and extractOrigins function that strips __origin__
from the decoded map[string]any before JSON marshaling. This reduces
intermediate JSON size by ~70% for large specs with origin tracking,
eliminating the 5x overhead of carrying origin data through the JSON
round-trip. Callers can apply the returned OriginTree to structs after
json.Unmarshal.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

8 participants