You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(diff/breaking/changelog/summary): --auto-upgrade for cross-version specs (#923)
* feat(diff/breaking/changelog/summary): --auto-upgrade for cross-version 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>
* docs(3.1): document --auto-upgrade for cross-version comparison
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.
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
A team migrating their spec from 3.0 to 3.1 has two problems oasdiff can help with: producing the migrated spec, and verifying the migration doesn't break clients.
54
+
55
+
### Converting a spec with `oasdiff upgrade`
56
+
57
+
The `upgrade` subcommand rewrites a 3.0 spec into the latest 3.x canonical form (currently 3.2.0). The transforms are idempotent, so running it on an already-canonical spec just bumps the version string.
The output goes to stdout; redirect to a file to keep it. The default output format is `yaml`; pass `--format json` for JSON.
66
+
67
+
The walker handles 3.0 → 3.x only. Swagger 2.0 → 3.0 is out of scope.
68
+
69
+
Available since `v1.16.0`.
70
+
71
+
### Comparing across versions with `--auto-upgrade`
72
+
73
+
`diff`, `breaking`, `changelog`, and `summary` accept an `--auto-upgrade` flag that runs the same canonicalisation on both specs in-memory right after load. 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.
Without the flag, the diff surfaces the 3.0→3.1 dialect rewrites (`nullable` becomes `type: ["string", "null"]`, etc.) as if they were schema changes. With the flag, both sides are canonicalised first, so only the genuine schema-level differences remain.
84
+
85
+
The flag is off by default; opt in per invocation. Safe to set even when both specs are already the same version: the walker is idempotent on already-canonical input.
86
+
87
+
Available since `v1.16.0`.
88
+
43
89
## Caveats
44
90
45
91
The following 3.1 features are not yet fully supported by [`kin-openapi`](https://github.com/getkin/kin-openapi) (the parser oasdiff uses) and therefore do not appear in oasdiff diffs:
cmd.PersistentFlags().Bool("case-insensitive-headers", false, "case-insensitive header name comparison")
23
23
cmd.PersistentFlags().StringSlice("exclude-extensions", nil, "OpenAPI Extension names to exclude from diff (e.g., x-internal)")
24
24
cmd.PersistentFlags().Bool("allow-external-refs", true, "allow external $refs in specs; disable to prevent SSRF when processing untrusted specs")
25
+
cmd.PersistentFlags().Bool("auto-upgrade", false, "canonicalize both specs to the latest OpenAPI 3.x before diffing; useful for cross-version comparisons (e.g. 3.0 vs 3.1)")
0 commit comments