Skip to content

feat(diff/breaking/changelog/summary): --auto-upgrade for cross-version specs#923

Merged
reuvenharrison merged 2 commits into
mainfrom
feat/auto-upgrade-flag
May 10, 2026
Merged

feat(diff/breaking/changelog/summary): --auto-upgrade for cross-version specs#923
reuvenharrison merged 2 commits into
mainfrom
feat/auto-upgrade-flag

Conversation

@reuvenharrison
Copy link
Copy Markdown
Collaborator

Stacks on top of #922. Once #922 merges to main, this PR rebases onto main automatically and the base flips.

Summary

Adds an --auto-upgrade flag to diff, breaking, changelog, and summary that canonicalises both specs to the latest OpenAPI 3.x before diffing. Solves the cross-version comparison problem (a 3.0 base against a 3.1 revision) which today produces a noisy diff dominated by dialect-level differences.

How it works

After both specs are loaded (and before the diff runs), the same openapi3conv.Upgrade helper introduced in #922 runs on each spec. The walker is idempotent on already-canonical specs, so a same-version pair is a safe no-op (it just bumps the version string).

oasdiff breaking old-3.0.yaml new-3.1.yaml --auto-upgrade
oasdiff changelog old-3.0.yaml new-3.1.yaml --auto-upgrade
oasdiff summary   old-3.0.yaml new-3.1.yaml --auto-upgrade
oasdiff diff      old-3.0.yaml new-3.1.yaml --auto-upgrade

Off by default; opt in per invocation. Default behaviour for all four subcommands is unchanged.

Smoke test (a 3.0 spec vs its 3.1 canonical form)

Without --auto-upgrade With --auto-upgrade
No breaking changes to report, but the specs are different (dialect noise) No changes detected

Plumbing

  • One new flag in addCommonDiffFlags (covers all four subcommands).
  • One new accessor flags.getAutoUpgrade().
  • One new field on the viper Config struct (AutoUpgrade).
  • One new helper autoUpgradeSpecs(enabled bool, specs ...*load.SpecInfo) in internal/upgrade.go.
  • Two call sites: normalDiff (single-spec each side) and composedDiff (glob, applies per spec in each set).

Tests

Test Asserts
Test_AutoUpgradeBreaking_CrossVersionEquivalent A 3.0 spec compared against its 3.1 canonical form produces No changes detected with --auto-upgrade
Test_AutoUpgradeChangelog_CrossVersionEquivalent Same, on changelog
Test_AutoUpgradeDiff_SameVersionIsHarmless Same-version pair: summary output is byte-identical with and without the flag

What this PR deliberately does NOT do

  • No annotation in the output indicating the upgrade fired. v1 is silent; a follow-up can add a stderr note and a structured auto_upgraded field in JSON/YAML outputs if telemetry shows users want it.
  • No automatic detection: --auto-upgrade is opt-in. v2 may promote to default if it tests well.

This is step 2 of the OpenAPI 3.1 readiness bundle. Step 1 was #922 (standalone oasdiff upgrade). Step 3 will be the validate subcommand (PR #894) once the kin replace directive is stripped.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 10, 2026

Codecov Report

❌ Patch coverage is 64.28571% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.65%. Comparing base (e0964a8) to head (effb23e).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/diff.go 25.00% 2 Missing and 1 partial ⚠️
internal/upgrade.go 71.42% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #923      +/-   ##
==========================================
- Coverage   90.67%   90.65%   -0.03%     
==========================================
  Files         267      267              
  Lines       16053    16067      +14     
==========================================
+ Hits        14556    14565       +9     
- Misses        959      962       +3     
- Partials      538      540       +2     
Flag Coverage Δ
unittests 90.65% <64.28%> (-0.03%) ⬇️

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.

Base automatically changed from feat/upgrade-subcommand to main May 10, 2026 21:09
@reuvenharrison reuvenharrison force-pushed the feat/auto-upgrade-flag branch from 0e0a03a to 3daf0f8 Compare May 10, 2026 21:10
reuvenharrison and others added 2 commits May 11, 2026 00:11
…on specs

When --auto-upgrade is set, both base and revision are canonicalised
to the latest OpenAPI 3.x (via the same openapi3conv.Upgrade helper
the new 'oasdiff upgrade' subcommand uses) right after load and before
diff. This makes cross-version comparisons (e.g. a 3.0 base against a
3.1 revision) produce a meaningful result instead of a noisy diff
dominated by dialect-level differences (nullable shape, type arrays,
exclusiveMinimum, example/examples).

The walker is idempotent on already-canonical specs, so calling it on
a same-version pair is a safe no-op. Off by default; opt in per
invocation. Applies to diff, breaking, changelog, and summary because
all four flow through normalDiff / composedDiff.

Tests cover the cross-version-equivalent case (a 3.0 spec and its 3.1
canonical form produce 'No changes detected' under --auto-upgrade) and
the same-version idempotency case (output unchanged whether the flag
is set or not).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Extend the 'Migrating from 3.0 to 3.1' section with a 'Comparing
across versions with --auto-upgrade' subsection covering the new
flag on diff/breaking/changelog/summary.

Explains the use case (cross-version diff produces dialect-level
noise without the flag) and that the walker is idempotent so
setting the flag is safe even for same-version pairs.
@reuvenharrison reuvenharrison force-pushed the feat/auto-upgrade-flag branch from 8fc81fb to effb23e Compare May 10, 2026 21:13
@reuvenharrison reuvenharrison merged commit effffd7 into main May 10, 2026
13 checks passed
@reuvenharrison reuvenharrison deleted the feat/auto-upgrade-flag branch May 10, 2026 21:14
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