API Specification Diff Tool

1.0.6 · active · verified Tue Apr 21

api-smart-diff is a JavaScript/TypeScript library designed to compute detailed differences between two JSON-based API specifications. It currently supports OpenAPI 3.0, AsyncAPI 2.x, JSON Schema, and GraphQL via GraphApi. Version 1.0.6 is the current stable release, offering a robust set of features for API versioning and changelog generation. Key differentiators include its ability to classify changes into 'breaking', 'non-breaking', 'deprecated', and 'annotation' types, generate human-readable descriptions for each change, and resolve `$ref` pointers (with external bundling). It provides extensive customization options for comparison rules, classification, and output annotation, making it highly adaptable for various CI/CD pipelines and documentation generation tasks. The library works seamlessly in both Node.js and browser environments and ships with full TypeScript support.

Common errors

Warnings

Install

Imports

Quickstart

Compares two OpenAPI 3.0 specifications, detailing the changes and providing a merged document.

import { apiCompare } from 'api-smart-diff';

const beforeSpec = {
  openapi: '3.0.0',
  info: { title: 'My API', version: '1.0.0' },
  paths: {
    '/users': {
      get: { summary: 'Get all users', operationId: 'getUsers' }
    }
  }
};

const afterSpec = {
  openapi: '3.0.0',
  info: { title: 'My API', version: '1.0.1', description: 'Added new endpoint' },
  paths: {
    '/users': {
      get: { summary: 'Retrieve users', operationId: 'getUsers' }
    },
    '/products': {
      post: { summary: 'Create a product', operationId: 'createProduct' }
    }
  }
};

const { diffs, merged } = apiCompare(beforeSpec, afterSpec);

console.log('Detected Diffs:', JSON.stringify(diffs, null, 2));
console.log('Merged Specification with Metadata:', JSON.stringify(merged, null, 2));

view raw JSON →