@subhamxcod/apiguard 1.0.2
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 +21 -0
- package/README.md +141 -0
- package/dist/chunk-RQVNHPHC.js +3848 -0
- package/dist/cli/main.cjs +4336 -0
- package/dist/cli/main.d.cts +1 -0
- package/dist/cli/main.d.ts +1 -0
- package/dist/cli/main.js +406 -0
- package/dist/index.cjs +336 -0
- package/dist/index.d.cts +204 -0
- package/dist/index.d.ts +204 -0
- package/dist/index.js +22 -0
- package/dist/markdown-J2EC3VFS.js +74 -0
- package/package.json +84 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 API Guard contributors
|
|
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,141 @@
|
|
|
1
|
+
# API Guard
|
|
2
|
+
|
|
3
|
+
> Detect breaking changes between OpenAPI specifications (3.0 & 3.1) so API contracts never
|
|
4
|
+
> silently break downstream consumers.
|
|
5
|
+
|
|
6
|
+
[](./.github/workflows/test.yml)
|
|
7
|
+
[](./.github/workflows/lint.yml)
|
|
8
|
+
|
|
9
|
+
**API Guard** diffs two OpenAPI specs — a _baseline_ and a _current_ — and classifies every
|
|
10
|
+
difference as **breaking** (an existing conformant client will fail), **non-breaking but
|
|
11
|
+
notable**, or **informational**. It ships as a CLI, a TypeScript library, and a GitHub Action.
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- **81 detection rules** across operations, parameters, request/response bodies, headers,
|
|
16
|
+
schemas, security, callbacks, and webhooks — see the [generated rule reference](./docs/rules.md)
|
|
17
|
+
- **Semantic, not textual**: YAML formatting, key order, enum order, and `$ref` aliasing are
|
|
18
|
+
never false positives; `nullable: true` (3.0) equals `type: ["string","null"]` (3.1)
|
|
19
|
+
- **Deterministic**: same inputs → byte-identical output, on any machine, any locale
|
|
20
|
+
- **Configurable**: per-rule severities, per-context overrides (`ruleId@context`), path/
|
|
21
|
+
operation/schema/rule ignore lists in `apiguard.yaml`
|
|
22
|
+
- **Semver advice**: suggests major/minor/patch from the detected change kinds
|
|
23
|
+
- **Three output formats**: terminal (color), JSON (machine contract), markdown (PR-friendly)
|
|
24
|
+
- **GitHub Action**: merge-base baseline by default, PR summary, `fail-on` policy
|
|
25
|
+
|
|
26
|
+
## Quick start
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pnpm add -D @subhamxcod/apiguard
|
|
30
|
+
apiguard init # scaffold apiguard.yaml
|
|
31
|
+
apiguard diff openapi.v1.yaml openapi.yaml
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Example output:
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
ERROR /users/{id} removed-method
|
|
38
|
+
operation DELETE was removed; existing clients calling it will get 404s
|
|
39
|
+
→ keep the operation and mark it deprecated instead
|
|
40
|
+
|
|
41
|
+
2 breaking, 3 non-breaking, 12 info — suggest major
|
|
42
|
+
verdict: FAIL (exit 1)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## The GitHub Action (recommended)
|
|
46
|
+
|
|
47
|
+
```yaml
|
|
48
|
+
# .github/workflows/api-guard.yml
|
|
49
|
+
name: API Guard
|
|
50
|
+
on: [pull_request]
|
|
51
|
+
jobs:
|
|
52
|
+
guard:
|
|
53
|
+
runs-on: ubuntu-latest
|
|
54
|
+
steps:
|
|
55
|
+
- uses: actions/checkout@v4
|
|
56
|
+
with: { fetch-depth: 0 } # merge-base needs history
|
|
57
|
+
- uses: apiguard/action@v1
|
|
58
|
+
with:
|
|
59
|
+
current: openapi.yaml # default; the PR's spec
|
|
60
|
+
# baseline: omitted → the spec at the merge-base with origin/main
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The Action posts a job summary table, emits `breaking` / `warnings` / `verdict` /
|
|
64
|
+
`suggested-version` outputs, and fails the step when breaking changes exist
|
|
65
|
+
(`fail-on: never` to only report). Full input/output reference:
|
|
66
|
+
[GitHub Action guide](./docs/github-action.md).
|
|
67
|
+
|
|
68
|
+
## CLI
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
apiguard diff <old-spec> <new-spec> # the core command
|
|
72
|
+
apiguard validate <spec> # load + semantic validation
|
|
73
|
+
apiguard init [dir] # scaffold a config
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Useful `diff` flags: `--json`, `--markdown`, `--fail-on warning|never`, `--strict`,
|
|
77
|
+
`--include-non-breaking`, `--show-ignored`, `--suggest-version`, `--output <file>`,
|
|
78
|
+
`--quiet`, `--no-color`. Full flag semantics: [CLI guide](./docs/cli.md).
|
|
79
|
+
|
|
80
|
+
**Exit codes:** `0` pass · `1` changes met the fail-on policy · `2` usage/config error ·
|
|
81
|
+
`3` invalid spec · `4` internal error (please report).
|
|
82
|
+
|
|
83
|
+
## Library
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import { analyze } from '@subhamxcod/apiguard';
|
|
87
|
+
|
|
88
|
+
const { report, ignored } = await analyze('openapi.v1.yaml', 'openapi.yaml');
|
|
89
|
+
if (report.summary.bySeverity.error > 0) {
|
|
90
|
+
console.log(report.semver.bump); // 'major' | 'minor' | 'patch' | 'none'
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The engine is pure: no stdout, no process.exit, no timestamps in report bodies.
|
|
95
|
+
[Library guide](./docs/library.md).
|
|
96
|
+
|
|
97
|
+
## Configuration
|
|
98
|
+
|
|
99
|
+
```yaml
|
|
100
|
+
# apiguard.yaml
|
|
101
|
+
schemaVersion: 1
|
|
102
|
+
rules:
|
|
103
|
+
property-removed: warning # downgrade a rule
|
|
104
|
+
description-changed@operation: off # per-context override
|
|
105
|
+
ignore:
|
|
106
|
+
paths: ['/internal/**']
|
|
107
|
+
operations: ['GET /users']
|
|
108
|
+
schemas: ['LegacyUser']
|
|
109
|
+
changes: ['description-changed']
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
[Configuration guide](./docs/configuration.md) · [Ignoring changes](./docs/ignoring.md)
|
|
113
|
+
|
|
114
|
+
## How it works
|
|
115
|
+
|
|
116
|
+
1. **Load** — `@apidevtools/swagger-parser` behind a swappable `SpecLoader`; remote `$ref`s
|
|
117
|
+
denied by default
|
|
118
|
+
2. **Normalize** — 3.0/3.1 unified: type arrays, nullable, exclusive bounds (§11.2)
|
|
119
|
+
3. **Index** — paths/methods/parameters/components, sorted
|
|
120
|
+
4. **Diff** — ref-aware pairwise schema comparison with cycle protection (10k-deep chains OK)
|
|
121
|
+
5. **Classify** — rules map facts → severities with per-context doctrine
|
|
122
|
+
6. **Report** — dedupe by stable id, deterministic sort, render
|
|
123
|
+
|
|
124
|
+
## Docs
|
|
125
|
+
|
|
126
|
+
- [Getting started](./docs/getting-started.md)
|
|
127
|
+
- [Configuration](./docs/configuration.md)
|
|
128
|
+
- [CLI reference](./docs/cli.md)
|
|
129
|
+
- [GitHub Action](./docs/github-action.md)
|
|
130
|
+
- [Ignoring changes](./docs/ignoring.md)
|
|
131
|
+
- [Rule reference (generated)](./docs/rules.md)
|
|
132
|
+
|
|
133
|
+
## Contributing
|
|
134
|
+
|
|
135
|
+
See [CONTRIBUTING.md](./CONTRIBUTING.md). Milestone-by-milestone build decisions live in
|
|
136
|
+
[DECISIONS.md](./DECISIONS.md). Security issues: [SECURITY.md](./SECURITY.md) — do not open
|
|
137
|
+
public issues.
|
|
138
|
+
|
|
139
|
+
## License
|
|
140
|
+
|
|
141
|
+
[MIT](./LICENSE)
|