Skip to content

NickCirv/schema-diff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

schema-diff — diff JSON and SQL schemas, catch breaking API changes before they reach production

Diff JSON Schemas and SQL schemas. Know exactly what changed — and whether it breaks your API contract.

license dependencies node formats


A schema change that looks minor can silently break consumers. schema-diff compares two versions of a JSON Schema or SQL schema file, classifies every change as breaking or non-breaking, and exits 1 if any breaking changes are found — making it safe to use as a CI gate.

schema-diff v1.json v2.json

schema-diff · User Schema
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

+ properties.phone         string (optional)
~ properties.email.format  "email" → "uri"    ⚠ breaking
- properties.username      removed             ⚠ breaking

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
2 breaking · 1 non-breaking

Install

No install, no npm account — run straight from GitHub with zero dependencies:

npx github:NickCirv/schema-diff

Usage

# diff two JSON Schema files
npx github:NickCirv/schema-diff v1.json v2.json

# diff two SQL schema files
npx github:NickCirv/schema-diff v1.sql v2.sql

# show only breaking changes
npx github:NickCirv/schema-diff v1.json v2.json --breaking

# machine-readable JSON output
npx github:NickCirv/schema-diff v1.json v2.json --format json

# RFC 6902 JSON Patch output
npx github:NickCirv/schema-diff v1.json v2.json --format patch

# ignore an internal path
npx github:NickCirv/schema-diff v1.json v2.json --ignore properties.internal

# AI-powered plain-English summary (requires ANTHROPIC_API_KEY)
npx github:NickCirv/schema-diff v1.json v2.json --ai
Flag Description
--breaking Show only breaking changes
--format table|json|patch Output format (default: table)
--ignore <path> Ignore a property path (repeatable)
--ai Print an AI plain-English summary via ANTHROPIC_API_KEY
-v, --version Show version
-h, --help Show help

What counts as breaking

Schema type Breaking changes detected
JSON Schema Field removed · type narrowed · required promoted · format changed · enum values removed · pattern made stricter · minimum/maximum tightened
SQL Column dropped · type changed · NOT NULL added without default · column size shrunk · foreign key reference removed · table dropped

Non-breaking changes (field added optional, enum values added, table added) are shown but do not trigger exit 1.

CI usage

Exit code 1 if any breaking change is detected — safe to fail your pipeline:

- name: Guard schema contract
  run: npx github:NickCirv/schema-diff schema-v1.json schema-v2.json

$ref resolution

JSON Schema $ref pointers (internal #/ references) are resolved before diffing, so $defs-based schemas work correctly.

What it is NOT

  • Not a migration generator. It tells you what changed — it does not write the migration SQL or code for you.
  • Not a JSON Schema validator. It diffs schemas against each other, not against instance data.
  • Not exhaustive on SQL. It parses CREATE TABLE statements. Complex SQL (views, triggers, stored procedures) is out of scope.

Zero dependencies · Node 18+ · MIT · by NickCirv

About

Diff JSON and SQL schemas. Catch breaking API changes before production — zero dependencies, CI-safe exit codes.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors