CtrlK
BlogDocsLog inGet started
Tessl Logo
PluginPublic

trysac/openapi-diff

Compare two OpenAPI 3.0/3.1 JSON specs and classify each change as breaking, warning or info with ten rules. Use when reviewing an API contract change, checking for breaking changes before a release, or gating CI on API compatibility.

Quality

95%

Does it follow best practices?

Run evals on this skill

Adds up to 20 points to the overall score

View guide
SecuritybySnyk

Low

Low-risk findings worth noting

Overview
Quality
Evals
Security
Files

SKILL.md

name:
openapi-diff
description:
Compare two OpenAPI 3.0/3.1 JSON specs and classify each change as breaking, warning or info with ten rules. Use when reviewing an API contract change, checking for breaking changes before a release, or gating CI on API compatibility.
license:
MIT
compatibility:
Needs Python 3 only (standard library). No network access. Reads only the two spec files you name.

openapi-diff

Find out whether a change to an OpenAPI contract breaks existing clients. The bundled script compares a base spec with a head spec and labels every difference breaking, warning or info using ten fixed rules. It works on its own: nothing to install or build.

When to use

  • A pull request edits an OpenAPI file and you must say whether clients will break.
  • Before a release: list removed operations, new required parameters, narrowed enums.
  • A CI job should fail when the contract gets a breaking change.

Workflow

  1. Get the two specs as JSON files: base (the released contract) and head (the proposed one). For a branch, write the base from version control, for example git show origin/main:openapi.json > /tmp/base.json. If the specs are YAML, convert them to JSON first; the script reads JSON only.

  2. Run the comparison:

    python3 scripts/openapi_diff.py /tmp/base.json openapi.json

    Options: --format text|json (default text) and --fail-on breaking|warning|none (default breaking).

  3. Read the output. Each line is [severity] rule METHOD path: message (json-pointer), followed by a summary such as 3 breaking, 1 warning, 2 info. The pointer locates the change in the head spec (in the base spec for removals).

  4. Report to the user, grouped by severity. Explain each breaking change in one sentence from the client's point of view and suggest a non-breaking alternative when one exists (keep the old operation, add an optional parameter, add a new field instead of changing a type).

  5. Use the exit code in automation: 0 nothing at or above --fail-on, 1 at least one change reaches it, 2 usage or input error (unreadable file, invalid JSON, unsupported version, external $ref, input over 10 MiB).

The ten rules, their severities and the matching logic are in references/rules.md. Read it before explaining a result that looks odd.

Interpreting results

  • breaking means an existing, correct client can fail: remove or rename an operation, add a required parameter, require a request property, remove a request enum value, remove a response property, narrow a request type or widen a response type.
  • warning needs a human look: a removed parameter, a response enum that gained a value (strict clients may reject it), or a changed allOf/oneOf/anyOf/not, which is reported as one warning and not analysed further.
  • info is backward compatible: a new operation or a new optional parameter.
  • A path rename such as /pets/{petId} to /pets/{id} is not a change: templates are matched with every {name} treated as {}. A trailing slash does make a different path.

Limits

State these when they matter to the answer:

  • Only OpenAPI 3.0.x and 3.1.x. Swagger 2.0 is rejected.
  • Only local references (#/...). An external $ref stops the run with an error.
  • Only JSON media types (application/json and +json) are compared, and only for response statuses present in both specs.
  • Response status codes, security schemes, examples and descriptions are not compared.
  • The script never writes files, never uses the network and never reads environment variables.

Source

This skill bundles a standard-library port of the rules implemented by the openapi-diff package: https://github.com/Trysac/u057-openapi-diff

SKILL.md

tile.json