Skip to content

feat(upgrade): new subcommand canonicalises 3.0 specs to the latest 3.x#922

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

feat(upgrade): new subcommand canonicalises 3.0 specs to the latest 3.x#922
reuvenharrison merged 2 commits into
mainfrom
feat/upgrade-subcommand

Conversation

@reuvenharrison
Copy link
Copy Markdown
Collaborator

Summary

Add a standalone oasdiff upgrade subcommand that canonicalises an OpenAPI 3.0 spec to the latest 3.x representation kin-openapi knows about (currently 3.2.0).

oasdiff upgrade spec.yaml [--format yaml|json]

What it does

Wraps openapi3conv.Upgrade from kin-openapi. The walker rewrites schema-level constructs in place and then bumps the openapi: version string:

Before (3.0) After (3.1+)
nullable: true on type: string type: ["string", "null"]
exclusiveMinimum: true + minimum: 0 exclusiveMinimum: 0
example: 7 examples: [7]

Transforms are idempotent: an already-canonical spec is unchanged aside from the possible version-string bump.

CLI shape

Mirrors oasdiff flatten:

  • Positional spec argument; accepts file path, URL, or - for stdin.
  • --format yaml|json. Default yaml (most real-world OpenAPI specs are yaml and most users running upgrade want to commit the result; pass --format json for json).
  • --allow-external-refs (default true) for SSRF control on untrusted input.
  • Hidden --max-circular-dep flag (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-openapi from v0.137.0 to v0.138.0 to pick up the openapi3conv package (the walker landed upstream in 0.138.0).

Tests

Five new tests in internal/run_test.go:

Test Asserts
Test_UpgradeCmdOK exit 0 on a valid 3.0 spec
Test_UpgradeCmdProducesCanonicalForm output contains openapi: 3.2.0, nullable: true is gone, exclusiveMinimum: 0 is present, examples: replaces example:
Test_UpgradeCmdAlreadyCurrent already-3.1 spec passes through cleanly with only the version-string bump
Test_UpgradeCmdJsonFormat --format json produces valid JSON with openapi: 3.2.0
Test_UpgradeCmdInvalid exit 102 + clear error for a non-OpenAPI input

Fixtures 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-upgrade flag on diff / breaking / changelog / summary in 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.

reuvenharrison and others added 2 commits May 10, 2026 23:52
    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-commenter
Copy link
Copy Markdown

codecov-commenter commented May 10, 2026

Codecov Report

❌ Patch coverage is 84.21053% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.67%. Comparing base (bc8f99b) to head (9077d18).

Files with missing lines Patch % Lines
internal/upgrade.go 83.78% 3 Missing and 3 partials ⚠️
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     
Flag Coverage Δ
unittests 90.67% <84.21%> (-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 reuvenharrison merged commit e0964a8 into main May 10, 2026
14 checks passed
@reuvenharrison reuvenharrison deleted the feat/upgrade-subcommand branch May 10, 2026 21:09
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