@arpixel/api-contract 0.1.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 +21 -0
- package/README.md +699 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +56 -0
- package/dist/commands/diff.d.ts +1 -0
- package/dist/commands/diff.js +15 -0
- package/dist/commands/generate.d.ts +1 -0
- package/dist/commands/generate.js +19 -0
- package/dist/commands/init.d.ts +1 -0
- package/dist/commands/init.js +33 -0
- package/dist/diff/comparator.d.ts +3 -0
- package/dist/diff/comparator.js +416 -0
- package/dist/diff/reporter.d.ts +2 -0
- package/dist/diff/reporter.js +32 -0
- package/dist/generator/api.d.ts +1 -0
- package/dist/generator/api.js +106 -0
- package/dist/generator/typescript.d.ts +1 -0
- package/dist/generator/typescript.js +14 -0
- package/dist/openapi/loader.d.ts +2 -0
- package/dist/openapi/loader.js +4 -0
- package/dist/types/diff.d.ts +161 -0
- package/dist/types/diff.js +1 -0
- package/integrations/vscode/api-contract-generate.agent.md +161 -0
- package/integrations/vscode/api-contract-generate.prompt.md +172 -0
- package/integrations/vscode/api-contract-impact.agent.md +193 -0
- package/integrations/vscode/api-contract-impact.prompt.md +285 -0
- package/package.json +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 api-contract 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,699 @@
|
|
|
1
|
+
# api-contract
|
|
2
|
+
|
|
3
|
+
> **Generate API clients. Compare contracts. Analyze frontend impact.**
|
|
4
|
+
|
|
5
|
+
`api-contract` is a deterministic CLI for frontend developers who consume evolving OpenAPI specifications.
|
|
6
|
+
|
|
7
|
+
It provides three capabilities that work together across the API lifecycle:
|
|
8
|
+
|
|
9
|
+
```text
|
|
10
|
+
┌─────────────────────────────────────────────────────────┐
|
|
11
|
+
│ api-contract │
|
|
12
|
+
├──────────────────┬──────────────────┬───────────────────┤
|
|
13
|
+
│ GENERATE │ COMPARE │ ANALYZE │
|
|
14
|
+
│ │ │ │
|
|
15
|
+
│ OpenAPI → │ OpenAPI → │ Contract changes │
|
|
16
|
+
│ TypeScript │ structured diff │ → frontend impact │
|
|
17
|
+
│ API client │ │ │
|
|
18
|
+
└──────────────────┴──────────────────┴───────────────────┘
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
* **Generate** — Generate frontend-ready TypeScript API clients from OpenAPI.
|
|
22
|
+
* **Compare** — Compare OpenAPI versions and identify structural and breaking changes.
|
|
23
|
+
* **Analyze** — Use AI coding agents to trace contract changes into the frontend repository and identify actual consumers.
|
|
24
|
+
|
|
25
|
+
The deterministic CLI provides the contract data. AI coding agents provide repository-aware impact analysis.
|
|
26
|
+
|
|
27
|
+
**No LLM or API key is required by the CLI.**
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
# Why
|
|
32
|
+
|
|
33
|
+
API contracts evolve continuously.
|
|
34
|
+
|
|
35
|
+
When a backend team publishes a new OpenAPI specification, frontend teams typically need to answer three different questions:
|
|
36
|
+
|
|
37
|
+
### 1. What do I need to integrate?
|
|
38
|
+
|
|
39
|
+
Generate a TypeScript representation of the API:
|
|
40
|
+
|
|
41
|
+
```text
|
|
42
|
+
OpenAPI
|
|
43
|
+
↓
|
|
44
|
+
TypeScript API client
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 2. What changed?
|
|
48
|
+
|
|
49
|
+
Compare the previous and current contract:
|
|
50
|
+
|
|
51
|
+
```text
|
|
52
|
+
OpenAPI v1
|
|
53
|
+
+
|
|
54
|
+
OpenAPI v2
|
|
55
|
+
↓
|
|
56
|
+
Contract diff
|
|
57
|
+
↓
|
|
58
|
+
Added / Removed / Modified
|
|
59
|
+
↓
|
|
60
|
+
Breaking / Non-breaking
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 3. What does it mean for my frontend?
|
|
64
|
+
|
|
65
|
+
Take those deterministic changes and trace them through the repository:
|
|
66
|
+
|
|
67
|
+
```text
|
|
68
|
+
Contract change
|
|
69
|
+
↓
|
|
70
|
+
API client / type
|
|
71
|
+
↓
|
|
72
|
+
Service
|
|
73
|
+
↓
|
|
74
|
+
Hook / Query / Mutation
|
|
75
|
+
↓
|
|
76
|
+
Component / Page
|
|
77
|
+
↓
|
|
78
|
+
Actual frontend impact
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`api-contract` brings these three workflows together without making the CLI dependent on AI.
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
# Three Core Capabilities
|
|
86
|
+
|
|
87
|
+
## 1. Generate
|
|
88
|
+
|
|
89
|
+
Generate frontend-ready TypeScript from an OpenAPI specification:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
npx api-contract generate openapi.yaml
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The default output is:
|
|
96
|
+
|
|
97
|
+
```text
|
|
98
|
+
api-contract/generated/
|
|
99
|
+
├── types.ts
|
|
100
|
+
└── api.ts
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The output directory is resolved relative to the current working directory.
|
|
104
|
+
|
|
105
|
+
### Custom output
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
npx api-contract generate openapi.yaml --output src/api/generated
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Produces:
|
|
112
|
+
|
|
113
|
+
```text
|
|
114
|
+
src/api/generated/
|
|
115
|
+
├── types.ts
|
|
116
|
+
└── api.ts
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
An explicitly provided `--output` directory takes precedence over the default.
|
|
120
|
+
|
|
121
|
+
### Generated files
|
|
122
|
+
|
|
123
|
+
#### `types.ts`
|
|
124
|
+
|
|
125
|
+
Generated using `openapi-typescript`.
|
|
126
|
+
|
|
127
|
+
It contains TypeScript representations of the OpenAPI contract, including schemas, parameters, responses, and enums.
|
|
128
|
+
|
|
129
|
+
#### `api.ts`
|
|
130
|
+
|
|
131
|
+
Contains a lightweight generated API-method contract based on OpenAPI `operationId`, parameters, and response schemas.
|
|
132
|
+
|
|
133
|
+
For example:
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
export interface ApiMethods {
|
|
137
|
+
getDevice(id: string): Promise<Device>;
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## 2. Compare
|
|
144
|
+
|
|
145
|
+
Compare two OpenAPI specifications:
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
npx api-contract diff old.yaml new.yaml
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
The comparison identifies structural contract changes including:
|
|
152
|
+
|
|
153
|
+
* endpoint additions and removals
|
|
154
|
+
* parameter additions and removals
|
|
155
|
+
* required/optional parameter changes
|
|
156
|
+
* parameter type changes
|
|
157
|
+
* request body changes
|
|
158
|
+
* request body property changes
|
|
159
|
+
* response changes
|
|
160
|
+
* response property changes
|
|
161
|
+
* schema additions and removals
|
|
162
|
+
* property additions and removals
|
|
163
|
+
* required/optional property changes
|
|
164
|
+
* enum changes
|
|
165
|
+
* type changes
|
|
166
|
+
|
|
167
|
+
Changes are classified as **breaking** or **non-breaking** according to the supported compatibility rules.
|
|
168
|
+
|
|
169
|
+
### Human-readable output
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
npx api-contract diff examples/old.yaml examples/new.yaml
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Example:
|
|
176
|
+
|
|
177
|
+
```text
|
|
178
|
+
API Contract Changes
|
|
179
|
+
|
|
180
|
+
Added: 4
|
|
181
|
+
Removed: 1
|
|
182
|
+
Modified: 1
|
|
183
|
+
Breaking: 2
|
|
184
|
+
|
|
185
|
+
BREAKING
|
|
186
|
+
DELETE /devices/{id} was removed.
|
|
187
|
+
Device.status changed from optional to required.
|
|
188
|
+
|
|
189
|
+
NON-BREAKING
|
|
190
|
+
POST /devices was added.
|
|
191
|
+
Device.serialNumber was added.
|
|
192
|
+
DeviceStatus enum value "suspended" was added.
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Machine-readable output
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
npx api-contract diff examples/old.yaml examples/new.yaml --format json
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
The JSON output provides a stable V1 structure:
|
|
202
|
+
|
|
203
|
+
```text
|
|
204
|
+
version
|
|
205
|
+
summary
|
|
206
|
+
changes
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Each change contains deterministic information such as:
|
|
210
|
+
|
|
211
|
+
* change type
|
|
212
|
+
* contract location
|
|
213
|
+
* endpoint
|
|
214
|
+
* HTTP method
|
|
215
|
+
* schema
|
|
216
|
+
* property
|
|
217
|
+
* previous value
|
|
218
|
+
* new value
|
|
219
|
+
* breaking status
|
|
220
|
+
* human-readable detail
|
|
221
|
+
|
|
222
|
+
The JSON format is intentionally suitable for automation and AI-agent consumption.
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## 3. Analyze
|
|
227
|
+
|
|
228
|
+
Contract comparison tells you **what changed**.
|
|
229
|
+
|
|
230
|
+
It does not tell you whether the frontend actually uses the changed contract.
|
|
231
|
+
|
|
232
|
+
The AI-assisted impact workflow takes the deterministic diff and analyzes the frontend repository.
|
|
233
|
+
|
|
234
|
+
```text
|
|
235
|
+
api-contract diff
|
|
236
|
+
↓
|
|
237
|
+
Contract changes
|
|
238
|
+
↓
|
|
239
|
+
AI coding agent
|
|
240
|
+
↓
|
|
241
|
+
Frontend repository
|
|
242
|
+
↓
|
|
243
|
+
Search + dependency tracing
|
|
244
|
+
↓
|
|
245
|
+
Actual consumers
|
|
246
|
+
↓
|
|
247
|
+
Impact report
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
For example:
|
|
251
|
+
|
|
252
|
+
```text
|
|
253
|
+
DELETE /devices/{id}
|
|
254
|
+
↓
|
|
255
|
+
deleteDevice()
|
|
256
|
+
↓
|
|
257
|
+
useDeleteDevice()
|
|
258
|
+
↓
|
|
259
|
+
DeviceActions.tsx
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
The workflow can trace relationships such as:
|
|
263
|
+
|
|
264
|
+
```text
|
|
265
|
+
Endpoint
|
|
266
|
+
↓
|
|
267
|
+
API client
|
|
268
|
+
↓
|
|
269
|
+
Service
|
|
270
|
+
↓
|
|
271
|
+
Hook / Query / Mutation
|
|
272
|
+
↓
|
|
273
|
+
Component / Page
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
and:
|
|
277
|
+
|
|
278
|
+
```text
|
|
279
|
+
Schema
|
|
280
|
+
↓
|
|
281
|
+
Generated TypeScript
|
|
282
|
+
↓
|
|
283
|
+
Request / Response model
|
|
284
|
+
↓
|
|
285
|
+
Service / Hook
|
|
286
|
+
↓
|
|
287
|
+
Component / Page
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
The analysis distinguishes between:
|
|
291
|
+
|
|
292
|
+
| Classification | Meaning |
|
|
293
|
+
| --------------- | ---------------------------------------------------------- |
|
|
294
|
+
| `DIRECT` | Application code directly consumes the changed contract |
|
|
295
|
+
| `INDIRECT` | The change reaches application code through an abstraction |
|
|
296
|
+
| `CONTRACT_ONLY` | Only generated/contract artifacts are related |
|
|
297
|
+
| `NONE_FOUND` | No relevant frontend usage was found |
|
|
298
|
+
|
|
299
|
+
These classifications describe the relationship between the contract and the frontend, not severity ratings.
|
|
300
|
+
|
|
301
|
+
Generated API clients and TypeScript types are not treated as application consumers.
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
# The Complete Workflow
|
|
306
|
+
|
|
307
|
+
The three capabilities can be used independently or together.
|
|
308
|
+
|
|
309
|
+
```text
|
|
310
|
+
OpenAPI
|
|
311
|
+
│
|
|
312
|
+
┌─────────────────┼─────────────────┐
|
|
313
|
+
│ │ │
|
|
314
|
+
▼ ▼ ▼
|
|
315
|
+
GENERATE COMPARE ANALYZE
|
|
316
|
+
│ │ │
|
|
317
|
+
▼ ▼ │
|
|
318
|
+
TypeScript client What changed? │
|
|
319
|
+
types.ts + api.ts Breaking? │
|
|
320
|
+
│ │
|
|
321
|
+
▼ │
|
|
322
|
+
Structured diff ─────────┘
|
|
323
|
+
│
|
|
324
|
+
▼
|
|
325
|
+
AI agent
|
|
326
|
+
│
|
|
327
|
+
▼
|
|
328
|
+
Frontend repository
|
|
329
|
+
│
|
|
330
|
+
▼
|
|
331
|
+
Impact report
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
A typical API evolution workflow becomes:
|
|
335
|
+
|
|
336
|
+
```text
|
|
337
|
+
1. Backend publishes OpenAPI
|
|
338
|
+
↓
|
|
339
|
+
2. Generate/update frontend API client
|
|
340
|
+
↓
|
|
341
|
+
3. Compare previous vs current contract
|
|
342
|
+
↓
|
|
343
|
+
4. Identify breaking changes
|
|
344
|
+
↓
|
|
345
|
+
5. Analyze frontend consumers
|
|
346
|
+
↓
|
|
347
|
+
6. Understand what actually needs attention
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
352
|
+
# AI-Assisted Workflows
|
|
353
|
+
|
|
354
|
+
AI is deliberately kept outside the deterministic CLI.
|
|
355
|
+
|
|
356
|
+
The architecture is:
|
|
357
|
+
|
|
358
|
+
```text
|
|
359
|
+
api-contract
|
|
360
|
+
│
|
|
361
|
+
├── generate
|
|
362
|
+
├── diff
|
|
363
|
+
│
|
|
364
|
+
└── deterministic contract data
|
|
365
|
+
│
|
|
366
|
+
▼
|
|
367
|
+
AI agent
|
|
368
|
+
│
|
|
369
|
+
▼
|
|
370
|
+
repository-aware analysis
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
This means:
|
|
374
|
+
|
|
375
|
+
* the CLI does not require an LLM
|
|
376
|
+
* contract comparison remains deterministic
|
|
377
|
+
* generated output remains reproducible
|
|
378
|
+
* AI is used where repository context and reasoning are valuable
|
|
379
|
+
|
|
380
|
+
The AI workflows can be used with supported coding-agent hosts such as VS Code/Copilot and other agent environments.
|
|
381
|
+
|
|
382
|
+
---
|
|
383
|
+
|
|
384
|
+
# VS Code / Copilot Integration
|
|
385
|
+
|
|
386
|
+
The repository includes integration artifacts:
|
|
387
|
+
|
|
388
|
+
```text
|
|
389
|
+
integrations/vscode/
|
|
390
|
+
├── api-contract-generate.prompt.md
|
|
391
|
+
├── api-contract-generate.agent.md
|
|
392
|
+
├── api-contract-impact.prompt.md
|
|
393
|
+
└── api-contract-impact.agent.md
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
Install these integrations for your user account with:
|
|
397
|
+
|
|
398
|
+
```bash
|
|
399
|
+
npx api-contract init --host vscode
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
This installs the prompts under `~/.api-contract/prompts/` and the agents under
|
|
403
|
+
`~/.copilot/agents/`. The command does not modify VS Code settings.
|
|
404
|
+
|
|
405
|
+
### Prompt usage
|
|
406
|
+
|
|
407
|
+
Choose one of these options for the prompts:
|
|
408
|
+
|
|
409
|
+
1. **Repository-local** — Copy `~/.api-contract/prompts/` into
|
|
410
|
+
`<repository>/.github/prompts/` to make the prompts available to that repository.
|
|
411
|
+
2. **Global** — Add `~/.api-contract/prompts` as a directory in VS Code's
|
|
412
|
+
`chat.promptFilesLocations` setting. Add the directory, not individual file paths.
|
|
413
|
+
|
|
414
|
+
The agents installed under `~/.copilot/agents/` can be selected from the VS Code Chat agent experience.
|
|
415
|
+
|
|
416
|
+
## API Contract Generate
|
|
417
|
+
|
|
418
|
+
Allows an AI coding agent to invoke the deterministic generation workflow based on user input.
|
|
419
|
+
|
|
420
|
+
For example:
|
|
421
|
+
|
|
422
|
+
```text
|
|
423
|
+
Generate TypeScript from openapi.yaml
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
The agent runs:
|
|
427
|
+
|
|
428
|
+
```bash
|
|
429
|
+
api-contract generate openapi.yaml
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
If the user specifies:
|
|
433
|
+
|
|
434
|
+
```text
|
|
435
|
+
Generate TypeScript from openapi.yaml and put it in src/api/generated.
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
the agent runs:
|
|
439
|
+
|
|
440
|
+
```bash
|
|
441
|
+
api-contract generate openapi.yaml --output src/api/generated
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
The agent does not manually reproduce the OpenAPI-to-TypeScript generation logic.
|
|
445
|
+
|
|
446
|
+
## API Contract Impact
|
|
447
|
+
|
|
448
|
+
Uses the deterministic `api-contract diff` output as the source of truth and then analyzes the frontend repository.
|
|
449
|
+
|
|
450
|
+
```text
|
|
451
|
+
api-contract diff
|
|
452
|
+
↓
|
|
453
|
+
contract changes
|
|
454
|
+
↓
|
|
455
|
+
repository analysis
|
|
456
|
+
↓
|
|
457
|
+
frontend consumers
|
|
458
|
+
↓
|
|
459
|
+
impact report
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
The analysis is read-only by default and does not modify source code unless explicitly requested.
|
|
463
|
+
|
|
464
|
+
---
|
|
465
|
+
|
|
466
|
+
# Architecture
|
|
467
|
+
|
|
468
|
+
```text
|
|
469
|
+
OpenAPI
|
|
470
|
+
│
|
|
471
|
+
OpenAPI parser
|
|
472
|
+
│
|
|
473
|
+
┌─────────────────┼─────────────────┐
|
|
474
|
+
│ │ │
|
|
475
|
+
▼ ▼ ▼
|
|
476
|
+
GENERATE COMPARE ANALYZE*
|
|
477
|
+
│ │ │
|
|
478
|
+
▼ ▼ │
|
|
479
|
+
TypeScript Structured diff │
|
|
480
|
+
client │ │
|
|
481
|
+
│ │ │
|
|
482
|
+
│ ▼ │
|
|
483
|
+
│ AI coding agent ◄────┘
|
|
484
|
+
│ │
|
|
485
|
+
│ ▼
|
|
486
|
+
│ Frontend repository
|
|
487
|
+
│ │
|
|
488
|
+
│ ▼
|
|
489
|
+
│ Impact analysis
|
|
490
|
+
│
|
|
491
|
+
▼
|
|
492
|
+
types.ts + api.ts
|
|
493
|
+
|
|
494
|
+
* Analyze is an AI-assisted workflow built on top of
|
|
495
|
+
the deterministic CLI output.
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
### Design principles
|
|
499
|
+
|
|
500
|
+
**Deterministic core**
|
|
501
|
+
|
|
502
|
+
OpenAPI parsing, validation, generation, and comparison are performed without an LLM.
|
|
503
|
+
|
|
504
|
+
**AI at the reasoning layer**
|
|
505
|
+
|
|
506
|
+
AI agents are used for repository-aware analysis where code relationships and application context matter.
|
|
507
|
+
|
|
508
|
+
**Separation of concerns**
|
|
509
|
+
|
|
510
|
+
```text
|
|
511
|
+
api-contract
|
|
512
|
+
= generate + compare
|
|
513
|
+
|
|
514
|
+
AI agent workflow
|
|
515
|
+
= analyze frontend impact
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
**Evidence over assumptions**
|
|
519
|
+
|
|
520
|
+
Impact analysis should prefer concrete repository evidence over assumptions based solely on names or generated artifacts.
|
|
521
|
+
|
|
522
|
+
---
|
|
523
|
+
|
|
524
|
+
# Installation
|
|
525
|
+
|
|
526
|
+
## Use with npx
|
|
527
|
+
|
|
528
|
+
No global installation is required:
|
|
529
|
+
|
|
530
|
+
```bash
|
|
531
|
+
npx api-contract --help
|
|
532
|
+
```
|
|
533
|
+
|
|
534
|
+
Generate:
|
|
535
|
+
|
|
536
|
+
```bash
|
|
537
|
+
npx api-contract generate openapi.yaml
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
Compare:
|
|
541
|
+
|
|
542
|
+
```bash
|
|
543
|
+
npx api-contract diff old.yaml new.yaml
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
Install the optional VS Code/Copilot integration:
|
|
547
|
+
|
|
548
|
+
```bash
|
|
549
|
+
npx api-contract init --host vscode
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
## Requirements
|
|
553
|
+
|
|
554
|
+
* Node.js 22.12+
|
|
555
|
+
* npm
|
|
556
|
+
|
|
557
|
+
The CLI bundles its OpenAPI parser and generator as npm dependencies.
|
|
558
|
+
|
|
559
|
+
---
|
|
560
|
+
|
|
561
|
+
# Development
|
|
562
|
+
|
|
563
|
+
Install dependencies:
|
|
564
|
+
|
|
565
|
+
```bash
|
|
566
|
+
npm install
|
|
567
|
+
```
|
|
568
|
+
|
|
569
|
+
Build:
|
|
570
|
+
|
|
571
|
+
```bash
|
|
572
|
+
npm run build
|
|
573
|
+
```
|
|
574
|
+
|
|
575
|
+
Run tests:
|
|
576
|
+
|
|
577
|
+
```bash
|
|
578
|
+
npm test
|
|
579
|
+
```
|
|
580
|
+
|
|
581
|
+
Run the CLI locally without linking:
|
|
582
|
+
|
|
583
|
+
```bash
|
|
584
|
+
npm run dev -- generate examples/old.yaml
|
|
585
|
+
```
|
|
586
|
+
|
|
587
|
+
```bash
|
|
588
|
+
npm run dev -- diff examples/old.yaml examples/new.yaml
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
---
|
|
592
|
+
|
|
593
|
+
# Project Structure
|
|
594
|
+
|
|
595
|
+
```text
|
|
596
|
+
api-contract/
|
|
597
|
+
├── src/
|
|
598
|
+
│ ├── cli.ts
|
|
599
|
+
│ ├── commands/
|
|
600
|
+
│ │ ├── generate.ts
|
|
601
|
+
│ │ └── diff.ts
|
|
602
|
+
│ ├── openapi/
|
|
603
|
+
│ │ └── loader.ts
|
|
604
|
+
│ ├── generator/
|
|
605
|
+
│ │ ├── typescript.ts
|
|
606
|
+
│ │ └── api.ts
|
|
607
|
+
│ ├── diff/
|
|
608
|
+
│ │ ├── comparator.ts
|
|
609
|
+
│ │ └── reporter.ts
|
|
610
|
+
│ └── types/
|
|
611
|
+
│ └── diff.ts
|
|
612
|
+
│
|
|
613
|
+
├── tests/
|
|
614
|
+
│ ├── diff/
|
|
615
|
+
│ └── generate/
|
|
616
|
+
│
|
|
617
|
+
├── examples/
|
|
618
|
+
│ ├── old.yaml
|
|
619
|
+
│ └── new.yaml
|
|
620
|
+
│
|
|
621
|
+
└── integrations/
|
|
622
|
+
└── vscode/
|
|
623
|
+
├── api-contract-generate.prompt.md
|
|
624
|
+
├── api-contract-generate.agent.md
|
|
625
|
+
├── api-contract-impact.prompt.md
|
|
626
|
+
└── api-contract-impact.agent.md
|
|
627
|
+
```
|
|
628
|
+
|
|
629
|
+
---
|
|
630
|
+
|
|
631
|
+
# V1 Scope
|
|
632
|
+
|
|
633
|
+
### Generate
|
|
634
|
+
|
|
635
|
+
* OpenAPI parsing and validation
|
|
636
|
+
* TypeScript type generation
|
|
637
|
+
* Lightweight API-method generation
|
|
638
|
+
|
|
639
|
+
### Compare
|
|
640
|
+
|
|
641
|
+
* OpenAPI contract comparison
|
|
642
|
+
* Structural change detection
|
|
643
|
+
* Breaking/non-breaking classification
|
|
644
|
+
* Human-readable diff
|
|
645
|
+
* Machine-readable JSON diff
|
|
646
|
+
|
|
647
|
+
### Analyze
|
|
648
|
+
|
|
649
|
+
* AI-assisted frontend repository analysis
|
|
650
|
+
* API consumer discovery
|
|
651
|
+
* Dependency tracing
|
|
652
|
+
* `DIRECT` / `INDIRECT` / `CONTRACT_ONLY` / `NONE_FOUND` classification
|
|
653
|
+
* Evidence-based impact reporting
|
|
654
|
+
|
|
655
|
+
---
|
|
656
|
+
|
|
657
|
+
# V1 Non-Goals
|
|
658
|
+
|
|
659
|
+
* Full HTTP client runtime generation
|
|
660
|
+
* React hooks
|
|
661
|
+
* TanStack Query hooks
|
|
662
|
+
* runtime validation
|
|
663
|
+
* mock generation
|
|
664
|
+
* LLM/API-key management inside the CLI
|
|
665
|
+
* direct repository modification by the CLI
|
|
666
|
+
* host-specific agent installation
|
|
667
|
+
|
|
668
|
+
The goal of V1 is to provide a small, deterministic, composable foundation for working with evolving API contracts and connecting contract changes to frontend code.
|
|
669
|
+
|
|
670
|
+
---
|
|
671
|
+
|
|
672
|
+
# Security
|
|
673
|
+
|
|
674
|
+
OpenAPI `$ref` resolution can reference external files or URLs.
|
|
675
|
+
|
|
676
|
+
Treat untrusted OpenAPI specifications carefully.
|
|
677
|
+
|
|
678
|
+
Future versions may expose an explicit safe-resolution policy rather than blindly dereferencing arbitrary references.
|
|
679
|
+
|
|
680
|
+
---
|
|
681
|
+
|
|
682
|
+
# Roadmap
|
|
683
|
+
|
|
684
|
+
Potential future capabilities include:
|
|
685
|
+
|
|
686
|
+
* richer OpenAPI compatibility analysis
|
|
687
|
+
* additional breaking-change rules
|
|
688
|
+
* improved API client generation
|
|
689
|
+
* additional AI-agent host integrations
|
|
690
|
+
* repository initialization/install commands
|
|
691
|
+
* broader frontend framework support
|
|
692
|
+
|
|
693
|
+
The roadmap is intentionally exploratory. The current focus is keeping the three core workflows — **Generate, Compare, Analyze** — deterministic, composable, and useful.
|
|
694
|
+
|
|
695
|
+
---
|
|
696
|
+
|
|
697
|
+
# License
|
|
698
|
+
|
|
699
|
+
MIT
|
package/dist/cli.d.ts
ADDED