openapi-sync 5.0.6 → 6.0.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/README.md +206 -2
- package/bin/cli.js +396 -27
- package/bin/mcp.js +36 -0
- package/dist/chunk-3VKPQNDD.mjs +22 -0
- package/dist/chunk-L52BXDAC.mjs +24 -0
- package/dist/chunk-TTLQP4UN.mjs +856 -0
- package/dist/chunk-VLACEFT4.mjs +1 -0
- package/dist/index.d.mts +351 -32
- package/dist/index.d.ts +351 -32
- package/dist/index.js +410 -365
- package/dist/index.mjs +1 -854
- package/dist/interactive-init-XBZJKJCH.mjs +1 -0
- package/dist/mcp/server.d.mts +1 -0
- package/dist/mcp/server.d.ts +1 -0
- package/dist/mcp/server.js +913 -0
- package/dist/mcp/server.mjs +4 -0
- package/dist/validate-3G3NZCPG.mjs +11 -0
- package/llms.txt +334 -0
- package/openapi.sync.schema.json +396 -0
- package/package.json +38 -17
- package/dist/chunk-PUWCZVB7.mjs +0 -1
- package/dist/interactive-init-OITE22SZ.mjs +0 -12
package/README.md
CHANGED
|
@@ -50,6 +50,124 @@ npx openapi-sync
|
|
|
50
50
|
|
|
51
51
|
> ⚠️ **macOS Big Sur Users:** If you encounter an esbuild error (`Symbol not found: _SecTrustCopyCertificateChain`), install `esbuild@0.17.19` first. See [Troubleshooting](#troubleshooting) for details.
|
|
52
52
|
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## 🤖 Using with AI Agents
|
|
56
|
+
|
|
57
|
+
All CLI commands and programmatic APIs are **agent-safe** — no interactive prompts, fully non-blocking. Use `--json` for machine-readable output and `--silent` to suppress logs.
|
|
58
|
+
|
|
59
|
+
> **Full agent reference:** [`llms.txt`](./llms.txt) — a structured discovery file for LLMs, Copilots, and MCP tools.
|
|
60
|
+
|
|
61
|
+
### Agent Quick-Start (no prompts)
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# 1. Create config (all settings as flags — no stdin required)
|
|
65
|
+
npx openapi-sync init --no-interactive \
|
|
66
|
+
--api-name petstore \
|
|
67
|
+
--api-url https://petstore3.swagger.io/api/v3/openapi.json \
|
|
68
|
+
--output-folder ./src/api \
|
|
69
|
+
--client-type react-query \
|
|
70
|
+
--validation-library zod \
|
|
71
|
+
--config-format typescript \
|
|
72
|
+
--json
|
|
73
|
+
|
|
74
|
+
# 2. Validate config + specs before writing any files
|
|
75
|
+
npx openapi-sync validate --json
|
|
76
|
+
|
|
77
|
+
# 3. Sync — generate types, endpoints, and schemas
|
|
78
|
+
npx openapi-sync --json
|
|
79
|
+
|
|
80
|
+
# 4. Generate a typed API client
|
|
81
|
+
npx openapi-sync generate-client --type react-query --json
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Machine-Readable Output (`--json`)
|
|
85
|
+
|
|
86
|
+
Every command emits a single JSON object when `--json` is passed:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
$ npx openapi-sync --json
|
|
90
|
+
{
|
|
91
|
+
"success": true,
|
|
92
|
+
"apis": ["petstore"],
|
|
93
|
+
"filesWritten": ["src/api/petstore/types.ts", "src/api/petstore/endpoints.ts"],
|
|
94
|
+
"endpointCount": 20,
|
|
95
|
+
"warnings": [],
|
|
96
|
+
"errors": []
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
$ npx openapi-sync validate --json
|
|
102
|
+
{
|
|
103
|
+
"valid": true,
|
|
104
|
+
"apis": { "petstore": { "valid": true, "endpointCount": 20 } },
|
|
105
|
+
"configErrors": []
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
$ npx openapi-sync list-endpoints --json
|
|
111
|
+
{
|
|
112
|
+
"petstore": [
|
|
113
|
+
{ "name": "getPetById", "method": "GET", "path": "/pet/{petId}", "tags": ["pet"], "summary": "Find pet by ID" },
|
|
114
|
+
{ "name": "addPet", "method": "POST", "path": "/pet", "tags": ["pet"], "summary": "Add a new pet" }
|
|
115
|
+
]
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Dry Run (preview without writing files)
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
npx openapi-sync --dry-run --json
|
|
123
|
+
npx openapi-sync generate-client --type fetch --dry-run --json
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Programmatic API (TypeScript)
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
import { ValidateConfig, Init, GenerateClient, ListEndpoints } from "openapi-sync";
|
|
130
|
+
|
|
131
|
+
// Pre-flight check — no files written
|
|
132
|
+
const validation = await ValidateConfig({ silent: true });
|
|
133
|
+
if (!validation.valid) throw new Error(JSON.stringify(validation));
|
|
134
|
+
|
|
135
|
+
// Inspect API surface
|
|
136
|
+
const endpoints = await ListEndpoints({ apiName: "petstore", silent: true });
|
|
137
|
+
console.log(endpoints.petstore.length, "endpoints found");
|
|
138
|
+
|
|
139
|
+
// Sync and get structured result
|
|
140
|
+
const syncResult = await Init({ silent: true });
|
|
141
|
+
if (!syncResult.success) throw new Error(JSON.stringify(syncResult));
|
|
142
|
+
console.log("Files written:", syncResult.filesWritten);
|
|
143
|
+
|
|
144
|
+
// Generate client
|
|
145
|
+
const clientResult = await GenerateClient({ type: "react-query", silent: true });
|
|
146
|
+
console.log(JSON.stringify(clientResult));
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Exit Codes
|
|
150
|
+
|
|
151
|
+
| Code | Meaning |
|
|
152
|
+
|------|---------|
|
|
153
|
+
| `0` | Success |
|
|
154
|
+
| `1` | Config error or validation failed |
|
|
155
|
+
| `2` | Network / spec fetch error |
|
|
156
|
+
| `3` | Generation / file write error |
|
|
157
|
+
|
|
158
|
+
### Agent-safe vs Interactive Commands
|
|
159
|
+
|
|
160
|
+
| Command | Agent-safe? |
|
|
161
|
+
|---------|------------|
|
|
162
|
+
| `npx openapi-sync` | ✅ |
|
|
163
|
+
| `npx openapi-sync validate` | ✅ |
|
|
164
|
+
| `npx openapi-sync list-endpoints` | ✅ |
|
|
165
|
+
| `npx openapi-sync generate-client` | ✅ |
|
|
166
|
+
| `npx openapi-sync init --no-interactive` | ✅ |
|
|
167
|
+
| `npx openapi-sync init` (no flag) | ❌ Requires stdin |
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
53
171
|
## Quick Start
|
|
54
172
|
|
|
55
173
|
### Option 1: Interactive Setup (Recommended) 🎯
|
|
@@ -345,6 +463,89 @@ For complete documentation including:
|
|
|
345
463
|
|
|
346
464
|
---
|
|
347
465
|
|
|
466
|
+
## 🔌 MCP Server (Model Context Protocol)
|
|
467
|
+
|
|
468
|
+
`openapi-sync` ships a built-in MCP server that exposes all operations as **structured tool calls**. AI agents (Claude Desktop, Cursor, Copilot, and any MCP-compatible host) can call sync, validate, and generate operations directly — no CLI parsing needed.
|
|
469
|
+
|
|
470
|
+
### Starting the server
|
|
471
|
+
|
|
472
|
+
```bash
|
|
473
|
+
# Via npx (no global install required — recommended)
|
|
474
|
+
npx openapi-sync-mcp
|
|
475
|
+
|
|
476
|
+
# Or if installed globally
|
|
477
|
+
openapi-sync-mcp
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
> The server uses **stdio transport** — it reads JSON-RPC from stdin and writes responses to stdout. The `cwd` of the process is used as the project root for all operations.
|
|
481
|
+
|
|
482
|
+
### Claude Desktop configuration
|
|
483
|
+
|
|
484
|
+
Edit `~/Library/Application Support/Claude/claude_desktop_config.json`:
|
|
485
|
+
|
|
486
|
+
```json
|
|
487
|
+
{
|
|
488
|
+
"mcpServers": {
|
|
489
|
+
"openapi-sync": {
|
|
490
|
+
"command": "npx",
|
|
491
|
+
"args": ["-y", "openapi-sync-mcp"],
|
|
492
|
+
"cwd": "/path/to/your/project"
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
### Cursor configuration
|
|
499
|
+
|
|
500
|
+
Create `.cursor/mcp.json` in your project root:
|
|
501
|
+
|
|
502
|
+
```json
|
|
503
|
+
{
|
|
504
|
+
"mcpServers": {
|
|
505
|
+
"openapi-sync": {
|
|
506
|
+
"command": "npx",
|
|
507
|
+
"args": ["-y", "openapi-sync-mcp"],
|
|
508
|
+
"cwd": "${workspaceFolder}"
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
### Available MCP tools
|
|
515
|
+
|
|
516
|
+
| Tool | Description |
|
|
517
|
+
|------|-------------|
|
|
518
|
+
| `openapi_sync_read_config` | Read the current config file — start here to understand what's configured |
|
|
519
|
+
| `openapi_sync_validate` | Validate config + specs without writing any files |
|
|
520
|
+
| `openapi_sync_list_endpoints` | List all endpoints from specs — inspect API surface before generating |
|
|
521
|
+
| `openapi_sync_sync` | Generate types, endpoints, and validation schemas |
|
|
522
|
+
| `openapi_sync_generate_client` | Generate a typed API client (fetch, axios, react-query, swr, rtk-query) |
|
|
523
|
+
| `openapi_sync_init` | Create an openapi.sync config file (non-interactive, no prompts) |
|
|
524
|
+
|
|
525
|
+
### Typical agent workflow via MCP
|
|
526
|
+
|
|
527
|
+
```
|
|
528
|
+
1. openapi_sync_read_config → check if config exists
|
|
529
|
+
2. openapi_sync_init → create config if needed (non-interactive)
|
|
530
|
+
3. openapi_sync_validate → confirm specs are reachable and valid
|
|
531
|
+
4. openapi_sync_list_endpoints → inspect endpoints, decide on filters
|
|
532
|
+
5. openapi_sync_sync → generate types + schemas
|
|
533
|
+
6. openapi_sync_generate_client type=react-query → generate typed client
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
### Tool input/output types
|
|
537
|
+
|
|
538
|
+
All tools return JSON-serialized versions of the same structured types used by the programmatic API:
|
|
539
|
+
|
|
540
|
+
- `openapi_sync_sync` → [`SyncResult`](#structured-return-types)
|
|
541
|
+
- `openapi_sync_generate_client` → [`SyncResult`](#structured-return-types)
|
|
542
|
+
- `openapi_sync_validate` → [`ValidationResult`](#structured-return-types)
|
|
543
|
+
- `openapi_sync_list_endpoints` → `Record<string, EndpointSummary[]>`
|
|
544
|
+
- `openapi_sync_init` → `{ success, configFile, message, errors }`
|
|
545
|
+
- `openapi_sync_read_config` → `{ found, file, path, content }`
|
|
546
|
+
|
|
547
|
+
---
|
|
548
|
+
|
|
348
549
|
## Troubleshooting
|
|
349
550
|
|
|
350
551
|
### macOS Big Sur (11.x) - esbuild Installation Error
|
|
@@ -395,6 +596,9 @@ A special thanks to the following contributors for their valuable work on this p
|
|
|
395
596
|
<a href="https://github.com/akintomiwaopemipo">
|
|
396
597
|
<img src="https://github.com/akintomiwaopemipo.png" width="50" height="50" alt="Opemipo Akintomiwa" style="border-radius: 50%;" />
|
|
397
598
|
</a>
|
|
599
|
+
<a href="https://github.com/ayotunde-codes">
|
|
600
|
+
<img src="https://github.com/ayotunde-codes.png" width="50" height="50" alt="Ayotunde Obasa" style="border-radius: 50%;" />
|
|
601
|
+
</a>
|
|
398
602
|
|
|
399
603
|
---
|
|
400
604
|
|
|
@@ -406,8 +610,8 @@ You can support the project in any of the following ways:
|
|
|
406
610
|
|
|
407
611
|
- Sponsor the maintainer on GitHub: https://github.com/sponsors/akintomiwa-fisayo
|
|
408
612
|
- Back the project on Open Collective (placeholder): https://opencollective.com/fisayo-akintomiwa
|
|
409
|
-
- Become a patron on Patreon (placeholder): https://patreon.com/openapi_sync
|
|
410
|
-
- One-time donation via PayPal (placeholder): https://paypal.me/yourname
|
|
613
|
+
<!-- - Become a patron on Patreon (placeholder): https://patreon.com/openapi_sync -->
|
|
614
|
+
<!-- - One-time donation via PayPal (placeholder): https://paypal.me/yourname -->
|
|
411
615
|
|
|
412
616
|
Thank you for considering supporting the project — every bit helps.
|
|
413
617
|
|