@asyncapi/diff

中文文档
0.6.1发布于 2026/11/02Apache-2.0TypeScriptCommonJS构建来源已验证近 30 天下载 31.3万

Library that compares two AsyncAPI documents and reports breaking, non-breaking, and unclassified changes.

原始使用文档
文档目录11 节
  1. Features
  2. Installation
  3. Usage
  4. Standard object
  5. Overriding the standard
  6. Example
  7. Output
  8. API
  9. Develop
  10. Contributing
  11. Contributors

AsyncAPI Diff

AsyncDiff is a library that compares two AsyncAPI files and provides information about the differences by pointing out explicitly information like breaking changes.

This package now lives in the asyncapi/cli monorepo under packages/diff/ and is released from there (same npm name @asyncapi/diff). The comparison rules are unchanged. AsyncAPIDiff is exported from the package entry, and the two input errors are TypeError subclasses with a stable .code. See the spec: docs/diff/spec.md.

npm npm

Features

  • Get explicit information about the changes you make to your AsyncAPI files, such as breaking, non-breaking and unclassified changes.
  • Different types of output such as JSON, YAML and Markdown.

Installation

npm install @asyncapi/diff

Usage

NOTE: The library doesn't have a built-in parser to parse the given AsyncAPI document. Thus, you have to make sure they provide the valid & dereferenced AsyncAPI document as an input. You can use the AsyncAPI parser to parse and validate the AsyncAPI file first. You can use other tools, but you must make sure that the document is valid and dereferenced.

import { diff } from "@asyncapi/diff"; // const { diff } = require('@asyncapi/diff');

const output = diff(firstDocument, secondDocument, {
  override: {
    // object to override the standard
  },
});

Standard object

This library has a pre-configured standard which marks a change as breaking, non-breaking or unclassified. This standard data is stored as an object inside the standard.ts file.

The format of this standard object is explained in this document.

Overriding the standard

To understand the format of overriding object, take a look at this document.

The overrides object must be passed in the following format:

{
    [jsonPointer]: {
        add: 'breaking' | 'non-breaking' | 'unclassified'
        remove: 'breaking' | 'non-breaking' | 'unclassified'
        edit: 'breaking' | 'non-breaking' | 'unclassified'
    }
}

Example

See the index document to get all the helper methods this library offers.

  1. Without any overrides
const output = diff(firstDocument, secondDocument);

output.getOutput(); // the whole output data
output.breaking(); // the breaking changes
output.nonBreaking(); // the non-breaking changes
output.unclassified(); // the unclassified changes
  1. With overrides
const output = diff(firstDocument, secondDocument, {
  override: {
    "/servers/*/protocol": {
      add: "non-breaking",
      remove: "breaking",
      edit: "unclassified",
    },
  },
});

Output

This library supports outputs:

  • JSON: json
  • YAML: yaml or yml
  • Markdown: markdown or md
const jsonOutput = diff(firstDocument, secondDocument, {
  outputType: "json",
});

const yamlOutput = diff(firstDocument, secondDocument, {
  outputType: "yaml" | "yml",
});

const markdownOutput = diff(firstDocument, secondDocument, {
  outputType: "markdown" | "md",
});

With markdown output, you can also choose subtypes of the changes as JSON(json) or YAML(yaml or yml).

const markdownOutput = diff(firstDocument, secondDocument, {
  outputType: "markdown" | "md",
  markdownSubtype: "json" | "yaml" | "yml",
});

API

Checkout the index document to see all the APIs this library offers.

Develop

  1. Write code and tests
  2. Make sure all tests pass npm run test
  3. Make sure code is well formatted and secure npm run lint

Contributing

Help us make this library more robust. Read CONTRIBUTING guide & start contributing.

Contributors

Thanks goes to these wonderful people (emoji key):


Aayush Kumar Sahu

💻 📖 🚧 🤔 👀 ⚠️

Lukasz Gornicki

🤔 👀 🚧

Maciej Urbańczyk

👀

Jonas Lagoni

👀

Vinit Shahdeo

👀

Anubhav Vats

👀

Shiven Sinha

💻 ⚠️

Debajyoti Halder

📖

This project follows the all-contributors specification. Contributions of any kind welcome!

版本与发布记录

@asyncapi/diff 共发布 12 个版本,首次发布于 2021/06/08;过去 12 个月发布了 4 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.6.1latest2026/11/025 天前
0.6.02026/10/1424 天前
0.5.22025/11/2411 个月前
0.5.12025/11/2411 个月前
0.5.02024/12/161.9 年前
0.4.12023/01/123 年前

关于 @asyncapi/diff 的常见问题

@asyncapi/diff 是什么?

Library that compares two AsyncAPI documents and reports breaking, non-breaking, and unclassified changes.

如何安装 @asyncapi/diff?

在项目目录运行 npm install @asyncapi/diff,或使用 pnpm add / yarn add / bun add。

@asyncapi/diff 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@asyncapi/diff 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@asyncapi/diff 可以商用吗?

@asyncapi/diff 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@asyncapi/diff 的下载量有多少?

根据 npm 官方下载统计,@asyncapi/diff 在 2026/10/07 – 2026/11/05 这 30 天内被下载 312,621 次,日均约 10,421 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@asyncapi/diff 还在维护吗?

最新版本 0.6.1 发布于 2026/11/02(5 天前);至今共发布 12 个版本,其中过去 12 个月发布了 4 个;首次发布于 2021/06/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。