feat(upgrade): new subcommand canonicalises 3.0 specs to the latest 3.x#922
Merged
Conversation
oasdiff upgrade spec.yaml [--format yaml|json] Wraps kin-openapi's openapi3conv.Upgrade walker, which rewrites schema-level constructs in place (nullable -> type array, boolean exclusiveMinimum/Maximum -> numeric, example -> examples) and bumps the openapi version string to the latest 3.x kin knows (currently 3.2.0). Transforms are idempotent: already-canonical specs pass through unchanged aside from the version bump. Mirrors `oasdiff flatten`'s CLI shape: positional spec argument, --format flag, support for stdin via '-', shared --allow-external-refs and --max-circular-dep handling. Default output format is yaml since most real-world OpenAPI specs are yaml and most users running upgrade want to commit the result; pass --format json for json. Bumps kin-openapi v0.137.0 -> v0.138.0 to pick up the openapi3conv package (Upgrade landed upstream there). This is step 1 of the OpenAPI 3.1 readiness bundle. The same upgrade helper will back the --auto-upgrade flag on diff/breaking/changelog/ summary in a follow-up; shipping standalone first shakes out any converter edge cases (lost comments, key reordering, weird-3.0 inputs) in the simplest context. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
CI runs 'go mod tidy' then 'git diff --exit-code' to verify the checksum file is canonical. The bump from v0.137.0 to v0.138.0 in the previous commit left the old version's checksums behind because 'go get' adds without removing.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #922 +/- ##
==========================================
- Coverage 90.68% 90.67% -0.02%
==========================================
Files 266 267 +1
Lines 16015 16053 +38
==========================================
+ Hits 14524 14556 +32
- Misses 956 959 +3
- Partials 535 538 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a standalone
oasdiff upgradesubcommand that canonicalises an OpenAPI 3.0 spec to the latest 3.x representation kin-openapi knows about (currently 3.2.0).What it does
Wraps
openapi3conv.Upgradefrom kin-openapi. The walker rewrites schema-level constructs in place and then bumps theopenapi:version string:nullable: trueontype: stringtype: ["string", "null"]exclusiveMinimum: true+minimum: 0exclusiveMinimum: 0example: 7examples: [7]Transforms are idempotent: an already-canonical spec is unchanged aside from the possible version-string bump.
CLI shape
Mirrors
oasdiff flatten:-for stdin.--format yaml|json. Defaultyaml(most real-world OpenAPI specs are yaml and most users running upgrade want to commit the result; pass--format jsonfor json).--allow-external-refs(default true) for SSRF control on untrusted input.--max-circular-depflag (existing pattern).Invalid specs surface through the existing load-error path, exit code 102. Flatten failures stay distinct from load failures (exit 122), unchanged by this PR.
Dependency bump
Bumps
github.com/getkin/kin-openapifromv0.137.0tov0.138.0to pick up theopenapi3convpackage (the walker landed upstream in 0.138.0).Tests
Five new tests in
internal/run_test.go:Test_UpgradeCmdOKTest_UpgradeCmdProducesCanonicalFormopenapi: 3.2.0,nullable: trueis gone,exclusiveMinimum: 0is present,examples:replacesexample:Test_UpgradeCmdAlreadyCurrentTest_UpgradeCmdJsonFormat--format jsonproduces valid JSON withopenapi: 3.2.0Test_UpgradeCmdInvalidFixtures live under
data/upgrade/.Why this PR alone
Step 1 of an OpenAPI 3.1 readiness bundle. The same upgrade helper will back a
--auto-upgradeflag ondiff/breaking/changelog/summaryin a follow-up. Shipping the standalone subcommand first shakes out any converter edge cases (lost comments, key reordering, weird-3.0 inputs) in the simplest context.