Skip to content

fix: eliminate false positive diffs on identical files (issue #806)#807

Merged
reuvenharrison merged 2 commits intomainfrom
fix/issue-806-origin-false-positive
Mar 16, 2026
Merged

fix: eliminate false positive diffs on identical files (issue #806)#807
reuvenharrison merged 2 commits intomainfrom
fix/issue-806-origin-false-positive

Conversation

@reuvenharrison
Copy link
Collaborator

@reuvenharrison reuvenharrison commented Mar 16, 2026

Summary

  • Fixes False positive diffs on identical files since version 1.12.0 #806: oasdiff reports spurious diffs when comparing byte-identical YAML files loaded from different paths
  • Root cause: the origin-tracking YAML loader injects `origin` metadata as a real key into typed Go maps (`map[string]*Encoding`, `map[string]*ServerVariable`), which contains the file path. When files are at different paths, this entry differs.
  • Fix applied in `oasdiff/kin-openapi` fork (`fix/issue-806` branch): introduce named types `Encodings` and `ServerVariables` with their own `UnmarshalJSON` using `unmarshalStringMapP`, consistent with how `Content`, `Schemas`, `Headers`, etc. already handle origin stripping

Affected maps (3 total)

Map Fix
`MediaType.Encoding map[string]*Encoding` new `Encodings` type with `unmarshalStringMapP[Encoding]`
`Server.Variables map[string]*ServerVariable` new `ServerVariables` type with `unmarshalStringMapP[ServerVariable]`
`T.Webhooks map[string]*PathItem` (OpenAPI 3.1) fixed in `feat/openapi-3.1-support` fork branch

All other component maps (`Content`, `Schemas`, `Headers`, `Links`, etc.) were already handled via `unmarshalStringMapP`/`popOrigin` or `maplike.go`.

Test plan

  • `TestDiff_IdenticalFilesNoDiff`: new regression test that loads `openapi-test1.yaml` twice from different paths and asserts the diff is nil
  • All existing tests pass: `go test ./...`
  • Manual verification: `oasdiff diff /tmp/test1.yaml /tmp/test2.yaml` (identical files at different paths) now produces empty output

🤖 Generated with Claude Code

@codecov-commenter
Copy link

codecov-commenter commented Mar 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.28%. Comparing base (324ce3d) to head (2d831b9).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #807   +/-   ##
=======================================
  Coverage   89.28%   89.28%           
=======================================
  Files         240      240           
  Lines       12715    12715           
=======================================
  Hits        11352    11352           
  Misses        907      907           
  Partials      456      456           
Flag Coverage Δ
unittests 89.28% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Identical YAML files loaded from different paths produced spurious diffs
because the origin-tracking YAML loader injects __origin__ metadata as a
real key into typed Go maps (map[string]*Encoding, map[string]*ServerVariable).
When the two file paths differ, __origin__.key.file differs, causing the
diff engine to report the encoding (or variables) as changed.

Fix by using oasdiff/kin-openapi fork with a minimal patch that deletes
originKey from MediaType.Encoding and Server.Variables after JSON
unmarshaling, mirroring the pattern already used for Extensions and the
unmarshalStringMapP helper used by Content, Schemas, etc.

Adds regression test TestDiff_IdenticalFilesNoDiff to prevent recurrence.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@reuvenharrison reuvenharrison force-pushed the fix/issue-806-origin-false-positive branch from e4bc939 to 50cc6bb Compare March 16, 2026 15:24
@reuvenharrison reuvenharrison merged commit 8e14055 into main Mar 16, 2026
14 checks passed
@reuvenharrison reuvenharrison deleted the fix/issue-806-origin-false-positive branch March 16, 2026 15:56
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.

False positive diffs on identical files since version 1.12.0

2 participants