@ir-kit/spec-diff 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ahmed Rowaihi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # `@ir-kit/spec-diff`
2
+
3
+ Cross-family API spec diff. Normalizes both inputs to OpenAPI 3 via `@ir-kit/spec-convert`, then delegates classification to [`api-smart-diff`](https://github.com/udamir/api-smart-diff) — community-standard breaking / non-breaking / annotation / unclassified / deprecated buckets.
4
+
5
+ Part of [ir-kit](https://github.com/ir-kit/ir-kit).
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install @ir-kit/spec-diff
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { diffSpecs } from "@ir-kit/spec-diff";
17
+
18
+ const result = await diffSpecs({
19
+ before: "./prod.yaml",
20
+ after: "./staging.proto", // mix any two supported formats
21
+ });
22
+
23
+ console.log(result.summary);
24
+ // { total: 12, breaking: 3, nonBreaking: 4, annotation: 5, unclassified: 0, deprecated: 0 }
25
+
26
+ for (const diff of result.diffs.filter((d) => d.type === "breaking")) {
27
+ console.log(diff.action, diff.path.join("/"), diff.description);
28
+ }
29
+ ```
30
+
31
+ ## API
32
+
33
+ | Export | Description |
34
+ | ---------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
35
+ | `diffSpecs(opts)` | Run a cross-family diff, return diffs + summary + the two normalized OpenAPI documents |
36
+ | `DiffSummary`, `DiffSpecsOptions`, `DiffSpecsResult`, `DiffType` | Public types |
37
+ | `Diff` (re-export from `api-smart-diff`) | Single change record — `{ action, path, type, description?, before?, after? }` |
38
+
39
+ ## CLI
40
+
41
+ ```sh
42
+ ir spec diff ./before.yaml --after ./after.proto
43
+ ir spec diff ./prod.yaml --after ./staging.yaml --failOnBreaking --out report.json
44
+ ```
45
+
46
+ `--failOnBreaking` exits non-zero when any `breaking` diff is found — drop into CI to gate merges on contract stability.
@@ -0,0 +1,38 @@
1
+ import type { ConvertSpecInput, SpecDocument, SpecFormat } from "@ir-kit/spec-convert";
2
+ import { type Diff } from "api-smart-diff";
3
+ export type { Diff };
4
+ export type DiffType = "breaking" | "non-breaking" | "annotation" | "unclassified" | "deprecated";
5
+ export interface DiffSummary {
6
+ total: number;
7
+ breaking: number;
8
+ nonBreaking: number;
9
+ annotation: number;
10
+ unclassified: number;
11
+ deprecated: number;
12
+ }
13
+ export interface DiffSpecsOptions {
14
+ before: ConvertSpecInput;
15
+ after: ConvertSpecInput;
16
+ fromBefore?: SpecFormat;
17
+ fromAfter?: SpecFormat;
18
+ cwd?: string;
19
+ }
20
+ export interface DiffSpecsResult {
21
+ diffs: Diff[];
22
+ summary: DiffSummary;
23
+ before: {
24
+ from: SpecFormat;
25
+ openapi: SpecDocument;
26
+ };
27
+ after: {
28
+ from: SpecFormat;
29
+ openapi: SpecDocument;
30
+ };
31
+ }
32
+ /**
33
+ * Cross-family API spec diff. Converts both inputs to OpenAPI 3 via
34
+ * `@ir-kit/spec-convert`, then runs `api-smart-diff`'s `compareOpenApi`.
35
+ * Returns the raw diff list plus a breaking/non-breaking summary.
36
+ */
37
+ export declare function diffSpecs(opts: DiffSpecsOptions): Promise<DiffSpecsResult>;
38
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACX,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAkB,KAAK,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAE3D,YAAY,EAAE,IAAI,EAAE,CAAC;AAErB,MAAM,MAAM,QAAQ,GAChB,UAAU,GACV,cAAc,GACd,YAAY,GACZ,cAAc,GACd,YAAY,CAAC;AAEjB,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,gBAAgB,CAAC;IACzB,KAAK,EAAE,gBAAgB,CAAC;IACxB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,SAAS,CAAC,EAAE,UAAU,CAAC;IACvB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,OAAO,EAAE,WAAW,CAAC;IACrB,MAAM,EAAE;QAAE,IAAI,EAAE,UAAU,CAAC;QAAC,OAAO,EAAE,YAAY,CAAA;KAAE,CAAC;IACpD,KAAK,EAAE;QAAE,IAAI,EAAE,UAAU,CAAC;QAAC,OAAO,EAAE,YAAY,CAAA;KAAE,CAAC;CACpD;AAED;;;;GAIG;AACH,wBAAsB,SAAS,CAC7B,IAAI,EAAE,gBAAgB,GACrB,OAAO,CAAC,eAAe,CAAC,CAc1B"}
package/dist/index.js ADDED
@@ -0,0 +1,58 @@
1
+ import { convertSpec } from "@ir-kit/spec-convert";
2
+ import { compareOpenApi } from "api-smart-diff";
3
+ /**
4
+ * Cross-family API spec diff. Converts both inputs to OpenAPI 3 via
5
+ * `@ir-kit/spec-convert`, then runs `api-smart-diff`'s `compareOpenApi`.
6
+ * Returns the raw diff list plus a breaking/non-breaking summary.
7
+ */
8
+ export async function diffSpecs(opts) {
9
+ const [before, after] = await Promise.all([
10
+ normalizeToOpenApi(opts.before, opts.fromBefore, opts.cwd),
11
+ normalizeToOpenApi(opts.after, opts.fromAfter, opts.cwd),
12
+ ]);
13
+ const { diffs } = compareOpenApi(before.openapi, after.openapi);
14
+ return {
15
+ diffs,
16
+ summary: summarize(diffs),
17
+ before,
18
+ after,
19
+ };
20
+ }
21
+ async function normalizeToOpenApi(input, from, cwd) {
22
+ const result = await convertSpec({ input, from, to: "openapi3", cwd });
23
+ if (result.output.kind !== "document") {
24
+ throw new Error(`Unexpected converter output kind '${result.output.kind}' for openapi3 target`);
25
+ }
26
+ return { from: result.from, openapi: result.output.document };
27
+ }
28
+ function summarize(diffs) {
29
+ const summary = {
30
+ total: diffs.length,
31
+ breaking: 0,
32
+ nonBreaking: 0,
33
+ annotation: 0,
34
+ unclassified: 0,
35
+ deprecated: 0,
36
+ };
37
+ for (const diff of diffs) {
38
+ switch (diff.type) {
39
+ case "breaking":
40
+ summary.breaking++;
41
+ break;
42
+ case "non-breaking":
43
+ summary.nonBreaking++;
44
+ break;
45
+ case "annotation":
46
+ summary.annotation++;
47
+ break;
48
+ case "unclassified":
49
+ summary.unclassified++;
50
+ break;
51
+ case "deprecated":
52
+ summary.deprecated++;
53
+ break;
54
+ }
55
+ }
56
+ return summary;
57
+ }
58
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAa,MAAM,gBAAgB,CAAC;AAmC3D;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,IAAsB;IAEtB,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACxC,kBAAkB,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,GAAG,CAAC;QAC1D,kBAAkB,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC;KACzD,CAAC,CAAC;IAEH,MAAM,EAAE,KAAK,EAAE,GAAG,cAAc,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAEhE,OAAO;QACL,KAAK;QACL,OAAO,EAAE,SAAS,CAAC,KAAK,CAAC;QACzB,MAAM;QACN,KAAK;KACN,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,kBAAkB,CAC/B,KAAuB,EACvB,IAA4B,EAC5B,GAAuB;IAEvB,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC;IACvE,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CACb,qCAAqC,MAAM,CAAC,MAAM,CAAC,IAAI,uBAAuB,CAC/E,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;AAChE,CAAC;AAED,SAAS,SAAS,CAAC,KAAa;IAC9B,MAAM,OAAO,GAAgB;QAC3B,KAAK,EAAE,KAAK,CAAC,MAAM;QACnB,QAAQ,EAAE,CAAC;QACX,WAAW,EAAE,CAAC;QACd,UAAU,EAAE,CAAC;QACb,YAAY,EAAE,CAAC;QACf,UAAU,EAAE,CAAC;KACd,CAAC;IACF,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;YAClB,KAAK,UAAU;gBACb,OAAO,CAAC,QAAQ,EAAE,CAAC;gBACnB,MAAM;YACR,KAAK,cAAc;gBACjB,OAAO,CAAC,WAAW,EAAE,CAAC;gBACtB,MAAM;YACR,KAAK,YAAY;gBACf,OAAO,CAAC,UAAU,EAAE,CAAC;gBACrB,MAAM;YACR,KAAK,cAAc;gBACjB,OAAO,CAAC,YAAY,EAAE,CAAC;gBACvB,MAAM;YACR,KAAK,YAAY;gBACf,OAAO,CAAC,UAAU,EAAE,CAAC;gBACrB,MAAM;QACV,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@ir-kit/spec-diff",
3
+ "version": "0.2.0",
4
+ "description": "Cross-family API spec diff. Converts any supported spec to OpenAPI 3, then runs `api-smart-diff` — breaking / non-breaking / annotation classification.",
5
+ "keywords": [
6
+ "openapi",
7
+ "asyncapi",
8
+ "typespec",
9
+ "protobuf",
10
+ "postman",
11
+ "diff",
12
+ "breaking-change",
13
+ "ir-kit"
14
+ ],
15
+ "homepage": "https://github.com/ir-kit/ir-kit/tree/main/packages/shared/spec-diff",
16
+ "bugs": {
17
+ "url": "https://github.com/ir-kit/ir-kit/issues"
18
+ },
19
+ "license": "MIT",
20
+ "author": {
21
+ "name": "Ahmed Rowaihi",
22
+ "email": "ahmedrowaihi@gmail.com"
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/ir-kit/ir-kit.git",
27
+ "directory": "packages/shared/spec-diff"
28
+ },
29
+ "type": "module",
30
+ "sideEffects": false,
31
+ "main": "./dist/index.js",
32
+ "types": "./dist/index.d.ts",
33
+ "exports": {
34
+ ".": {
35
+ "types": "./dist/index.d.ts",
36
+ "import": "./dist/index.js"
37
+ },
38
+ "./package.json": "./package.json"
39
+ },
40
+ "files": [
41
+ "dist",
42
+ "README.md",
43
+ "LICENSE.md"
44
+ ],
45
+ "publishConfig": {
46
+ "access": "public",
47
+ "provenance": true
48
+ },
49
+ "dependencies": {
50
+ "api-smart-diff": "^1.0.6",
51
+ "@ir-kit/spec-convert": "0.2.0"
52
+ },
53
+ "devDependencies": {
54
+ "@types/node": "^22",
55
+ "vitest": "^4.0.0",
56
+ "@ir-kit/tsconfig": "0.0.0"
57
+ },
58
+ "engines": {
59
+ "node": ">=20.19.0"
60
+ },
61
+ "scripts": {
62
+ "build": "tsc -p tsconfig.build.json",
63
+ "dev": "tsc -p tsconfig.build.json --watch",
64
+ "typecheck": "tsc --noEmit",
65
+ "test": "vitest run --passWithNoTests"
66
+ }
67
+ }