Skip to content

About

CodeMirror-based diff viewer for JSON-based API documents, including OpenAPI, AsyncAPI, and JsonSchema specifications.

Topics

Resources

Stars

46 stars

Watchers

1 watching

Forks

Repository files navigation

api-diff-viewer

npm npm downloads types license docs

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

Features

  • 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
  • ready and error events, including unsupported documents and comparison problems
  • Plain DOM and CodeMirror: works in any framework or none; UMD global ApiDiffViewer

Install

npm install api-diff-viewer

api-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.

Usage

<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).

Documentation

Development

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 demo

See Contributing for all commands.

License

MIT

About

CodeMirror-based diff viewer for JSON-based API documents, including OpenAPI, AsyncAPI, and JsonSchema specifications.

Topics

Resources

Stars

46 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages