Skip to content

feat: support git revision syntax for spec paths#799

Merged
reuvenharrison merged 4 commits intomainfrom
feature/git-revision-source
Mar 9, 2026
Merged

feat: support git revision syntax for spec paths#799
reuvenharrison merged 4 commits intomainfrom
feature/git-revision-source

Conversation

@reuvenharrison
Copy link
Collaborator

@reuvenharrison reuvenharrison commented Mar 9, 2026

Summary

  • Adds SourceTypeGitRevision to the load package so that paths like origin/main:openapi.yaml or HEAD~1:spec.yaml are recognised natively
  • NewSource() detects the <ref>:<path> pattern — excluded URLs (://) and Windows drive letters (single uppercase letter before :)
  • loadFromGitRevision() runs git show <ref>:<path> and loads the output via LoadFromDataWithPath, passing the spec path as the URL so that relative $refs resolve correctly — no temp file needed
  • Clear error messages include the git stderr when the ref or path doesn't exist

Motivation

Previously, using oasdiff in GitHub Actions required an extra manual step:

- run: git show origin/${{ github.base_ref }}:openapi.yaml > /tmp/base.yaml
- uses: oasdiff/oasdiff-action/[email protected]
  with:
    base: /tmp/base.yaml
    revision: openapi.yaml

After this change, the workflow collapses to:

- uses: oasdiff/oasdiff-action/[email protected]
  with:
    base: 'origin/${{ github.base_ref }}:openapi.yaml'
    revision: 'HEAD:openapi.yaml'

Test plan

  • TestSource_IsGitRevision — detection of valid git revision patterns
  • TestSource_IsNotGitRevision — non-git paths (files, URLs, Windows drive letters) are not misclassified
  • TestLoadInfo_GitRevision — end-to-end: real git repo, committed spec, loaded via HEAD:openapi.yaml
  • TestLoadInfo_GitRevisionNotFound — clear error when ref or path doesn't exist
  • Full ./load/... test suite passes with no regressions

🤖 Generated with Claude Code

@codecov-commenter
Copy link

codecov-commenter commented Mar 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.57%. Comparing base (adcd2c5) to head (3c691ef).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #799      +/-   ##
==========================================
+ Coverage   89.54%   89.57%   +0.02%     
==========================================
  Files         239      239              
  Lines       12154    12179      +25     
==========================================
+ Hits        10883    10909      +26     
+ Misses        841      840       -1     
  Partials      430      430              
Flag Coverage Δ
unittests 89.57% <100.00%> (+0.02%) ⬆️

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.

reuvenharrison and others added 2 commits March 9, 2026 12:40
Allow oasdiff to accept git revision specs like "origin/main:openapi.yaml"
or "HEAD~1:spec.yaml" directly as base/revision arguments, without needing
a separate "git show" step in CI workflows.

NewSource() detects the <ref>:<path> pattern (excluding URLs with "://"
and Windows drive letters) and categorises it as SourceTypeGitRevision.
The loader runs "git show <ref>:<path>", writes the content to a temp file
in the spec's directory (preserving relative $ref resolution), and loads
from that file.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…g temp file

Now that the Loader interface is gone (PR #800), use *openapi3.Loader directly
and call LoadFromDataWithPath so relative $refs resolve against the spec path
without needing a temporary file on disk.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@reuvenharrison reuvenharrison force-pushed the feature/git-revision-source branch from f9f95e1 to fae321e Compare March 9, 2026 10:41
reuvenharrison and others added 2 commits March 9, 2026 12:55
Document the new git revision syntax (<ref>:<path>) with usage examples,
a reference table, explanation of how it works, and a GitHub Actions snippet.
Update the README feature bullet to link to the new doc.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@reuvenharrison reuvenharrison merged commit 30adfba into main Mar 9, 2026
14 checks passed
@reuvenharrison reuvenharrison deleted the feature/git-revision-source branch March 9, 2026 11:03
@reuvenharrison reuvenharrison restored the feature/git-revision-source branch March 9, 2026 18:53
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.

2 participants