A framework-free CodeMirror 6 component that renders the difference between two versions of an API document, side by side or inline, with every change classified by api-smart-diff 2.x as breaking, risky, non-breaking, deprecated, annotation or unclassified. It supports OpenAPI 3.0 / 3.1 / 3.2, AsyncAPI 2.x / 3.0, GraphApi 1.0 (GraphQL), ProtoApi (gRPC / Protocol Buffers) and JSON Schema documents.
Documentation · Getting started · Live demo · API reference · Migration from 1.1
- Side-by-side (two aligned editors) or inline view, YAML or JSON output
- Six change types with colour-coded gutter bars, fold counters and change badges, filterable
- Word- or character-level highlights inside changed lines
- Navigation API: next / previous change by type, go to a path, search keys and values
- Light and dark themes with colour overrides
readyanderrorevents, including unsupported documents and comparison problems- Plain DOM and CodeMirror: works in any framework or none; UMD global
ApiDiffViewer
npm install api-diff-viewerapi-smart-diff 2.x and CodeMirror are installed with the package (the UMD build bundles them); no stylesheet import is needed. See Installation for the browser build and the requirements.
<div id="diff" style="height: 600px"></div>import { createDiffViewer } from "api-diff-viewer";
const before = { openapi: "3.1.0", info: { title: "Pets", version: "1.0.0" }, paths: {} };
const after = { openapi: "3.1.0", info: { title: "Pets", version: "1.1.0", description: "Pet store" }, paths: {} };
const viewer = createDiffViewer(document.getElementById("diff")!, before, after, {
mode: "side-by-side",
showClassification: true,
});
viewer.on("ready", ({ summary }) => console.log(`${summary.total} changes, ${summary.breaking} breaking`));
viewer.on("error", ({ kind, message }) => console.error(kind, message)); // e.g. Swagger 2.0: "unsupported-spec"The documents are parsed objects or JSON strings; parse YAML yourself (for example with js-yaml).
- Introduction and Installation
- Getting started and Usage
- Options
- Change types and colours and Theming
- Events and errors
- Web Worker, CodeMirror extensions and Navigation API
- API reference, Migration from 1.1 and Changelog
Requires Node.js 22.18 or later and pnpm 10 (corepack enable). The toolchain is Vite+ (vp).
pnpm install
pnpm run test --project unit # unit tests
pnpm run check # format, lint and type check (vp check)
pnpm run build # library build (vp pack)
pnpm run docs:dev # documentation portal and live demoSee Contributing for all commands.
MIT