x-openapi-flow 1.3.5 → 1.3.7

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.
Files changed (2) hide show
  1. package/README.md +338 -306
  2. package/package.json +3 -1
package/README.md CHANGED
@@ -1,435 +1,467 @@
1
+ <!-- Auto-generated from /README.md via scripts/sync-package-readme.js. Do not edit directly. -->
2
+
3
+ ![x-openapi-flow logo](https://raw.githubusercontent.com/tiago-marques/x-openapi-flow/main/docs/assets/x-openapi-flow-logo.svg)
4
+
5
+ [![npm version](https://img.shields.io/npm/v/x-openapi-flow?label=npm%20version)](https://www.npmjs.com/package/x-openapi-flow)
6
+ [![npm downloads](https://img.shields.io/npm/dm/x-openapi-flow?label=npm%20downloads)](https://www.npmjs.com/package/x-openapi-flow)
7
+ ![node](https://img.shields.io/badge/node-%3E%3D18-339933)
8
+ ![license](https://img.shields.io/npm/l/x-openapi-flow)
9
+ [![CI](https://github.com/tiago-marques/x-openapi-flow/actions/workflows/x-openapi-flow-validate.yml/badge.svg)](https://github.com/tiago-marques/x-openapi-flow/actions/workflows/x-openapi-flow-validate.yml)
10
+ [![open issues](https://img.shields.io/github/issues/tiago-marques/x-openapi-flow)](https://github.com/tiago-marques/x-openapi-flow/issues)
11
+ [![last commit](https://img.shields.io/github/last-commit/tiago-marques/x-openapi-flow)](https://github.com/tiago-marques/x-openapi-flow/commits/main)
12
+ ![copilot ready](https://img.shields.io/badge/Copilot-Ready-00BFA5?logo=githubcopilot&logoColor=white)
13
+
1
14
  # x-openapi-flow
2
15
 
3
- ![x-openapi-flow logo](../docs/assets/x-openapi-flow-logo.svg)
16
+ **OpenAPI describes APIs.**
17
+ **x-openapi-flow describes how they actually work — for developers and AI.**
4
18
 
5
- CLI and extension contract for documenting and validating resource lifecycle workflows in OpenAPI using `x-openapi-flow`.
19
+ `x-openapi-flow` is an OpenAPI vendor extension and CLI for documenting and validating resource lifecycle workflows.
20
+ It adds explicit state-machine metadata (`x-openapi-flow`) to operations and validates both schema and lifecycle graph consistency.
6
21
 
7
- ## Overview
22
+ ---
8
23
 
9
- `x-openapi-flow` validates:
24
+ ## Why This Project Matters
10
25
 
11
- - Extension schema correctness
12
- - Lifecycle graph consistency
13
- - Optional quality checks for transitions and references
26
+ Most teams document endpoints but not lifecycle behavior. State transitions become implicit, inconsistent, and hard to validate in CI.
27
+ `x-openapi-flow` makes flows explicit, so teams can:
14
28
 
15
- It also supports a sidecar workflow (`init` + `apply`) so lifecycle metadata stays preserved when OpenAPI source files are regenerated.
29
+ - Validate lifecycle consistency early in CI
30
+ - Generate flow-aware docs and diagrams
31
+ - Build SDKs that reduce invalid API calls
16
32
 
17
- ## Installation
33
+ Result: faster onboarding, fewer integration regressions, and clearer contracts between API producers and consumers.
18
34
 
19
- ```bash
20
- npm install x-openapi-flow
21
- ```
35
+ ---
36
+
37
+ ## TL;DR / Quick Start
22
38
 
23
- Optional mirror on GitHub Packages (default usage remains unscoped on npm):
39
+ From your API project root:
24
40
 
25
41
  ```bash
26
- npm config set @tiago-marques:registry https://npm.pkg.github.com
27
- npm install @tiago-marques/x-openapi-flow
42
+ npx x-openapi-flow init
43
+ ```
44
+ or
45
+ ```bash
46
+ npx x-openapi-flow apply openapi.x.yaml
28
47
  ```
29
48
 
30
- If authentication is required, include this in your `.npmrc`:
49
+ Default adoption path:
31
50
 
32
- ```ini
33
- //npm.pkg.github.com/:_authToken=${GITHUB_PACKAGES_TOKEN}
34
- ```
51
+ 1. Generate or update your OpenAPI source.
52
+ 2. Run `init` to create/sync sidecar flow metadata.
53
+ 3. Run `apply` whenever the OpenAPI file is regenerated.
35
54
 
36
- Use a GitHub PAT with `read:packages` (install) and `write:packages` (publish).
55
+ Full rollout guide: [docs/wiki/Adoption-Playbook.md](https://github.com/tiago-marques/x-openapi-flow/blob/main/docs/wiki/Adoption-Playbook.md)
56
+ Troubleshooting: [docs/wiki/Troubleshooting.md](https://github.com/tiago-marques/x-openapi-flow/blob/main/docs/wiki/Troubleshooting.md)
57
+
58
+ ---
59
+
60
+ ## Day-to-Day Workflow (API Server Team)
61
+
62
+ Typical routine when your OpenAPI source changes frequently:
37
63
 
38
- ## Quick Start
64
+ 1. Bootstrap once per project.
39
65
 
40
66
  ```bash
41
67
  npx x-openapi-flow init
68
+ ```
69
+
70
+ 2. Re-apply sidecar metadata after each OpenAPI regeneration.
71
+
72
+ ```bash
42
73
  npx x-openapi-flow apply openapi.yaml
43
74
  ```
44
75
 
45
- Optional checks:
76
+ 3. Validate lifecycle quality before opening a PR.
46
77
 
47
78
  ```bash
48
- npx x-openapi-flow validate openapi.yaml --profile strict
49
- npx x-openapi-flow lint openapi.yaml
50
- npx x-openapi-flow graph openapi.yaml
79
+ npx x-openapi-flow validate openapi.flow.yaml --profile strict --strict-quality
51
80
  ```
52
81
 
53
- ## CLI Commands
82
+ 4. Optional diagnostics for review and troubleshooting.
54
83
 
55
84
  ```bash
56
- npx x-openapi-flow help [command]
57
- npx x-openapi-flow --help
58
- npx x-openapi-flow version
59
- npx x-openapi-flow --version
60
- npx x-openapi-flow validate <openapi-file> [--format pretty|json] [--profile core|relaxed|strict] [--strict-quality] [--config path]
61
- npx x-openapi-flow init [--flows path] [--force] [--dry-run]
62
- npx x-openapi-flow apply [openapi-file] [--flows path] [--out path]
63
- npx x-openapi-flow diff [openapi-file] [--flows path] [--format pretty|json]
64
- npx x-openapi-flow lint [openapi-file] [--format pretty|json] [--config path]
65
- npx x-openapi-flow analyze [openapi-file] [--format pretty|json] [--out path] [--merge] [--flows path]
66
- npx x-openapi-flow generate-sdk [openapi-file] --lang typescript [--output path]
67
- npx x-openapi-flow export-doc-flows [openapi-file] [--output path] [--format markdown|json]
68
- npx x-openapi-flow generate-postman [openapi-file] [--output path] [--with-scripts]
69
- npx x-openapi-flow generate-insomnia [openapi-file] [--output path]
70
- npx x-openapi-flow generate-redoc [openapi-file] [--output path]
71
- npx x-openapi-flow graph <openapi-file> [--format mermaid|json]
72
- npx x-openapi-flow doctor [--config path]
73
- npx x-openapi-flow completion [bash|zsh]
85
+ npx x-openapi-flow diff openapi.yaml --format pretty
86
+ npx x-openapi-flow lint openapi.flow.yaml
87
+ npx x-openapi-flow graph openapi.flow.yaml --format mermaid
74
88
  ```
75
89
 
76
- Helpful additions:
90
+ What this gives your team in practice:
77
91
 
78
- - Command-specific help: `x-openapi-flow <command> --help` (example: `x-openapi-flow validate --help`)
79
- - Verbose troubleshooting: `x-openapi-flow <command> --verbose`
80
- - Shell completion output: `x-openapi-flow completion bash` or `x-openapi-flow completion zsh`
92
+ - deterministic lifecycle checks in local dev and CI
93
+ - explicit transition contracts instead of implicit tribal knowledge
94
+ - safer API evolution with fewer integration regressions
81
95
 
82
- ## Output Adapters
96
+ ---
83
97
 
84
- `x-openapi-flow` now supports modular output adapters that reuse the same internal flow graph:
98
+ ## Integration Experience (What You See)
85
99
 
86
- - OpenAPI + `x-openapi-flow` -> parser -> graph builder -> adapters
87
- - Adapters: docs (`export-doc-flows`), SDK (`generate-sdk`), Postman (`generate-postman`), Insomnia (`generate-insomnia`)
88
- and Redoc package (`generate-redoc`)
100
+ ### Swagger UI
89
101
 
90
- ### Redoc/Docs Adapter (`export-doc-flows`)
102
+ Use this when you want interactive docs with lifecycle context on each operation.
91
103
 
92
104
  ```bash
93
- npx x-openapi-flow export-doc-flows openapi.yaml --output ./docs/api-flows.md
94
- npx x-openapi-flow export-doc-flows openapi.yaml --format json --output ./docs/api-flows.json
105
+ cd example/swagger-ui
106
+ npm install
107
+ npm run apply
108
+ npm start
95
109
  ```
96
110
 
97
- Generates a lifecycle page (or JSON model) with:
111
+ Experience outcome:
112
+
113
+ - operation docs enriched with `x-openapi-flow` fields
114
+ - visual lifecycle context while navigating endpoints
115
+
116
+ Demo media:
117
+
118
+ - GIF slot: `docs/assets/demo-swagger-ui.gif`
119
+ - Image slot: `docs/assets/demo-swagger-ui.png`
98
120
 
99
- - Flow/Lifecycle panel per resource
100
- - Mermaid diagram per resource
101
- - Current state, prerequisites (`prerequisite_operation_ids`), next operations (`next_operation_id`)
121
+ ### Redoc
102
122
 
103
- ### Redoc Package Adapter (`generate-redoc`)
123
+ Use this when you want a static docs bundle to share internally or publish.
104
124
 
105
125
  ```bash
106
- npx x-openapi-flow generate-redoc openapi.yaml --output ./redoc-flow
126
+ cd example/redoc
127
+ npm install
128
+ npm run apply
129
+ npm run generate
107
130
  ```
108
131
 
109
- Generates a ready-to-open Redoc bundle with:
132
+ Experience outcome:
110
133
 
111
- - `index.html` (Redoc + Flow/Lifecycle panel)
112
- - `x-openapi-flow-redoc-plugin.js` (DOM enhancer)
113
- - `flow-model.json` (flow graph model)
114
- - copied OpenAPI spec (`openapi.yaml`/`openapi.json`)
134
+ - portable `redoc-flow/` package with lifecycle panel
135
+ - stable documentation artifact for teams and portals
115
136
 
116
- ### Postman Adapter (`generate-postman`)
137
+ Demo media:
138
+
139
+ - GIF slot: `docs/assets/demo-redoc.gif`
140
+ - Image slot: `docs/assets/demo-redoc.png`
141
+
142
+ ### Postman
143
+
144
+ Use this when you want collections aligned with lifecycle transitions.
117
145
 
118
146
  ```bash
119
- npx x-openapi-flow generate-postman openapi.yaml --output ./x-openapi-flow.postman_collection.json --with-scripts
147
+ cd example/postman
148
+ npm install
149
+ npm run apply
150
+ npm run generate
120
151
  ```
121
152
 
122
- Generates lifecycle-oriented folders/journeys and optional scripts for:
153
+ Experience outcome:
154
+
155
+ - flow-oriented Postman collection
156
+ - request execution closer to real transition paths
123
157
 
124
- - prerequisite enforcement before request execution
125
- - propagated operation tracking and ID persistence in collection variables
158
+ Demo media:
126
159
 
127
- ### Insomnia Adapter (`generate-insomnia`)
160
+ - GIF slot: `docs/assets/demo-postman.gif`
161
+ - Image slot: `docs/assets/demo-postman.png`
162
+
163
+ ### Insomnia
164
+
165
+ Use this when your team runs API scenarios in Insomnia workspaces.
128
166
 
129
167
  ```bash
130
- npx x-openapi-flow generate-insomnia openapi.yaml --output ./x-openapi-flow.insomnia.json
168
+ cd example/insomnia
169
+ npm install
170
+ npm run apply
171
+ npm run generate
131
172
  ```
132
173
 
133
- Generates an Insomnia export organized by resource flow groups and ordered requests.
174
+ Experience outcome:
175
+
176
+ - generated workspace export with grouped lifecycle requests
177
+ - faster onboarding to operation prerequisites and flow order
178
+
179
+ Demo media:
180
+
181
+ - GIF slot: `docs/assets/demo-insomnia.gif`
182
+ - Image slot: `docs/assets/demo-insomnia.png`
183
+
184
+ More integration details:
185
+
186
+ - [docs/wiki/Swagger-UI-Integration.md](https://github.com/tiago-marques/x-openapi-flow/blob/main/docs/wiki/Swagger-UI-Integration.md)
187
+ - [docs/wiki/Redoc-Integration.md](https://github.com/tiago-marques/x-openapi-flow/blob/main/docs/wiki/Redoc-Integration.md)
188
+ - [docs/wiki/Postman-Integration.md](https://github.com/tiago-marques/x-openapi-flow/blob/main/docs/wiki/Postman-Integration.md)
189
+ - [docs/wiki/Insomnia-Integration.md](https://github.com/tiago-marques/x-openapi-flow/blob/main/docs/wiki/Insomnia-Integration.md)
190
+
191
+ ---
134
192
 
135
- ## SDK Generator (`generate-sdk`)
193
+ ## CLI in Practice (Server Workflow)
136
194
 
137
- Generate a flow-aware SDK from OpenAPI + `x-openapi-flow` metadata.
195
+ Use this sequence as your default lifecycle guardrail in backend projects:
138
196
 
139
197
  ```bash
140
- npx x-openapi-flow generate-sdk openapi.yaml --lang typescript --output ./sdk
141
- ```
198
+ # 1) Bootstrap sidecar from OpenAPI source
199
+ npx x-openapi-flow init
142
200
 
143
- MVP output (TypeScript):
201
+ # 2) Merge sidecar into flow-aware OpenAPI output
202
+ npx x-openapi-flow apply openapi.yaml --out openapi.flow.yaml
144
203
 
145
- - `src/resources/<Resource>.ts`: resource client + state classes (`PaymentAuthorized`, `PaymentCaptured`, etc.)
146
- - `src/index.ts`: root `FlowApiClient`
147
- - `src/http-client.ts`: pluggable HTTP client interface and fetch implementation
148
- - `src/flow-helpers.ts`: `runFlow("authorize -> capture")`
149
- - `flow-model.json`: intermediate model `{ resource, operations, prerequisites, nextOperations, states }`
204
+ # 3) Detect drift before commit
205
+ npx x-openapi-flow diff openapi.yaml --format pretty
150
206
 
151
- SDK layers (resource-centric):
207
+ # 4) Enforce lifecycle quality gates
208
+ npx x-openapi-flow validate openapi.flow.yaml --profile strict --strict-quality
209
+ npx x-openapi-flow lint openapi.flow.yaml
210
+
211
+ # 5) Generate graph artifact for PR discussion
212
+ npx x-openapi-flow graph openapi.flow.yaml --format mermaid
213
+ ```
152
214
 
153
- - Collection/service layer: `api.payments.create()`, `api.payments.retrieve(id)`, `api.payments.list()`
154
- - Resource instance/state layer: objects expose valid lifecycle transitions (`payment.capture()`, etc.)
155
- - Optional lifecycle helper methods at service level (`api.payments.capture(id, params, { autoPrerequisites: true })`)
215
+ CLI quick references for daily usage:
156
216
 
157
- Pipeline used by the generator:
217
+ ```bash
218
+ npx x-openapi-flow help [command]
219
+ npx x-openapi-flow <command> --help
220
+ npx x-openapi-flow <command> --verbose
221
+ npx x-openapi-flow completion [bash|zsh]
222
+ ```
158
223
 
159
- - OpenAPI -> parser -> flow graph -> state machine -> templates -> SDK
160
- - Reuses lifecycle graph logic from the validator to stay consistent with `validate`, `graph`, and `diff`
161
- - Transition ordering uses `next_operation_id`, `prerequisite_operation_ids`, and state transitions from `x-openapi-flow`
224
+ ---
162
225
 
163
- ## Flow Analyzer (`analyze`)
226
+ ## SDK Generation Experience (TypeScript)
164
227
 
165
- Use `analyze` to bootstrap a sidecar from OpenAPI paths/operation names.
228
+ Generate a flow-aware SDK directly from your OpenAPI + `x-openapi-flow` metadata:
166
229
 
167
230
  ```bash
168
- npx x-openapi-flow analyze openapi.yaml --out openapi.x.yaml
169
- npx x-openapi-flow analyze openapi.yaml --format json
170
- npx x-openapi-flow analyze openapi.yaml --merge --flows openapi.x.yaml
231
+ npx x-openapi-flow generate-sdk openapi.flow.yaml --lang typescript --output ./sdk
171
232
  ```
172
233
 
173
- Notes:
174
-
175
- - The output is heuristic and intended as a starting point.
176
- - Inferred states/transitions should be reviewed and adjusted by API/domain owners.
177
- - Default output format is `pretty`; without `--out`, the suggested sidecar is printed to stdout.
178
- - `--merge` merges inferred data into an existing sidecar (default path or `--flows`) while preserving existing operation fields.
179
- - In `json`, inferred transition confidence is available in `analysis.transitionConfidence`.
180
-
181
- `diff` now reports field-level changes for operations that already exist in the sidecar.
182
- In `pretty` format, this appears under `Changed details` with changed paths per operation (for example, `current_state` or `transitions[0].target_state`).
183
- In `json` format, this appears in `diff.changedOperationDetails`:
184
-
185
- ```json
186
- {
187
- "diff": {
188
- "changedOperationDetails": [
189
- {
190
- "operationId": "listItems",
191
- "changedPaths": ["current_state"]
192
- }
193
- ]
194
- }
195
- }
234
+ What you get:
235
+
236
+ - resource-centric classes with lifecycle-safe methods
237
+ - operation transition awareness (`next_operation_id`, prerequisites, propagated fields)
238
+ - reusable client layer for application services
239
+
240
+ Typical integration snippet:
241
+
242
+ ```ts
243
+ import { FlowApiClient } from "./sdk/src";
244
+
245
+ const api = new FlowApiClient({ baseUrl: process.env.API_BASE_URL });
246
+
247
+ const payment = await api.payments.create({ amount: 1000 });
248
+ await payment.authorize();
249
+ await payment.capture();
196
250
  ```
197
251
 
198
- ### CI usage (`diff` as a gate)
252
+ Demo media:
199
253
 
200
- Fail the pipeline when sidecar drift is detected:
254
+ - GIF slot: `docs/assets/demo-sdk-generation.gif`
255
+ - Image slot: `docs/assets/demo-sdk-generation.png`
201
256
 
202
- ```bash
203
- npx x-openapi-flow diff openapi.yaml --format json | node -e '
204
- const fs = require("fs");
205
- const payload = JSON.parse(fs.readFileSync(0, "utf8"));
206
- const diff = payload.diff || {};
207
- const changes = (diff.added || 0) + (diff.removed || 0) + (diff.changed || 0);
208
- if (changes > 0) {
209
- console.error("x-openapi-flow diff detected changes. Run init/apply and commit sidecar updates.");
210
- process.exit(1);
211
- }
212
- '
257
+ ---
258
+
259
+ ## Example: Payment Flow
260
+
261
+ ```mermaid
262
+ graph TD
263
+ CreatePayment --> AuthorizePayment
264
+ AuthorizePayment --> CapturePayment
265
+ CapturePayment --> RefundPayment
213
266
  ```
214
267
 
215
- This keeps `.x` sidecar data aligned with the OpenAPI source in pull requests.
268
+ ### Flow-aware SDK Example (TypeScript)
216
269
 
217
- ## Semantic lint (`lint`)
270
+ ```ts
271
+ const payment = await sdk.payments.create({ amount: 1000 });
272
+ await payment.authorize();
273
+ await payment.capture();
274
+ await payment.refund();
275
+ ```
276
+
277
+ At each stage, only valid lifecycle actions should be available.
278
+
279
+ ---
280
+
281
+ ## Installation
218
282
 
219
- Use `lint` to run semantic checks focused on flow modeling quality.
283
+ Install from npm (default):
220
284
 
221
285
  ```bash
222
- npx x-openapi-flow lint openapi.yaml
223
- npx x-openapi-flow lint openapi.yaml --format json
286
+ npm install x-openapi-flow
224
287
  ```
225
288
 
226
- MVP semantic rules:
227
-
228
- - `next_operation_id_exists`
229
- - `prerequisite_operation_ids_exist`
230
- - `duplicate_transitions`
231
- - `terminal_path` (states without path to terminal)
232
-
233
- Disable individual rules with config (`x-openapi-flow.config.json`):
234
-
235
- ```json
236
- {
237
- "lint": {
238
- "rules": {
239
- "next_operation_id_exists": true,
240
- "prerequisite_operation_ids_exist": true,
241
- "duplicate_transitions": false,
242
- "terminal_path": true
243
- }
244
- }
245
- }
246
- ```
289
+ Optional mirror from GitHub Packages:
247
290
 
248
- ## Graph JSON contract (`graph --format json`)
249
-
250
- `graph --format json` returns a stable contract for CI/pipeline integrations:
251
-
252
- - `format_version`: output contract version (currently `"1.0"`).
253
- - `flowCount`: number of operations with `x-openapi-flow`.
254
- - `nodes`: sorted state names (deterministic order).
255
- - `edges`: sorted transitions by `from`, `to`, `next_operation_id`, and prerequisites.
256
- - `mermaid`: deterministic Mermaid rendering of the same graph.
257
-
258
- Example:
259
-
260
- ```json
261
- {
262
- "format_version": "1.0",
263
- "flowCount": 3,
264
- "nodes": ["CONFIRMED", "CREATED", "SHIPPED"],
265
- "edges": [
266
- {
267
- "from": "CONFIRMED",
268
- "to": "SHIPPED",
269
- "next_operation_id": "shipOrder",
270
- "prerequisite_operation_ids": []
271
- }
272
- ],
273
- "mermaid": "stateDiagram-v2\n state CONFIRMED\n state CREATED\n state SHIPPED\n CONFIRMED --> SHIPPED: next:shipOrder"
274
- }
291
+ ```bash
292
+ npm config set @tiago-marques:registry https://npm.pkg.github.com
293
+ npm install @tiago-marques/x-openapi-flow
275
294
  ```
276
295
 
277
- ## HTTP Methods Support
296
+ If authentication is required, add to `.npmrc`:
278
297
 
279
- `init`, `apply`, and `graph` support all OpenAPI 3 HTTP operation methods:
298
+ ```ini
299
+ //npm.pkg.github.com/:_authToken=${GITHUB_PACKAGES_TOKEN}
300
+ ```
280
301
 
281
- - `get`
282
- - `put`
283
- - `post`
284
- - `delete`
285
- - `options`
286
- - `head`
287
- - `patch`
288
- - `trace`
302
+ Use a GitHub PAT with `read:packages` (install) and `write:packages` (publish).
289
303
 
290
- ## Sidecar Workflow
304
+ ---
291
305
 
292
- Behavior summary:
306
+ ## CLI Reference (Selected Commands)
293
307
 
294
- - `init` works on an existing OpenAPI source file in your repository.
295
- - `init` creates/synchronizes `{context}.x.(json|yaml)` as a persistent sidecar for `x-openapi-flow` data.
296
- - If `{context}.flow.(json|yaml)` does not exist, `init` generates it automatically (same merge result as `apply`).
297
- - If `{context}.flow.(json|yaml)` already exists, `init` asks in interactive mode whether to recreate it.
298
- - On confirmation (or with `--force`), `init` creates a sidecar backup as `{context}.x.(json|yaml).backup-N` before regenerating `{context}.flow.(json|yaml)`.
299
- - In non-interactive mode, `init` fails when flow output already exists unless `--force` is provided.
300
- - With `--dry-run`, `init` prints a summary of sidecar/flow behavior without writing files.
301
- - Use `apply` to inject sidecar flows back into regenerated OpenAPI source files.
302
- - If no OpenAPI/Swagger source file exists yet, generate one first with your framework's official tooling.
308
+ ```bash
309
+ npx x-openapi-flow help [command]
310
+ npx x-openapi-flow --help
311
+ npx x-openapi-flow version
312
+ npx x-openapi-flow --version
313
+ npx x-openapi-flow validate <openapi-file> [--profile core|relaxed|strict] [--strict-quality]
314
+ npx x-openapi-flow init [--flows path] [--force] [--dry-run]
315
+ npx x-openapi-flow apply [openapi-file] [--flows path] [--out path]
316
+ npx x-openapi-flow analyze [openapi-file] [--format pretty|json] [--out path] [--merge] [--flows path]
317
+ npx x-openapi-flow generate-sdk [openapi-file] --lang typescript [--output path]
318
+ npx x-openapi-flow export-doc-flows [openapi-file] [--output path] [--format markdown|json]
319
+ npx x-openapi-flow generate-postman [openapi-file] [--output path] [--with-scripts]
320
+ npx x-openapi-flow generate-insomnia [openapi-file] [--output path]
321
+ npx x-openapi-flow generate-redoc [openapi-file] [--output path]
322
+ npx x-openapi-flow graph <openapi-file> [--format mermaid|json]
323
+ npx x-openapi-flow doctor [--config path]
324
+ npx x-openapi-flow completion [bash|zsh]
325
+ ```
303
326
 
304
- ### Recommended Sequence
327
+ Global flag for troubleshooting:
305
328
 
306
329
  ```bash
307
- npx x-openapi-flow init
308
- npx x-openapi-flow init --dry-run
309
- # edit {context}.x.(json|yaml)
310
- npx x-openapi-flow diff openapi.yaml
311
- npx x-openapi-flow apply openapi.yaml
330
+ npx x-openapi-flow <command> --verbose
312
331
  ```
313
332
 
314
- ## Sidecar File Contract (all supported fields)
315
-
316
- Sidecar top-level shape:
317
-
318
- ```yaml
319
- version: "1.0"
320
- operations:
321
- - operationId: createOrder
322
- x-openapi-flow:
323
- version: "1.0"
324
- id: create-order
325
- current_state: CREATED
326
- description: Creates an order and starts its lifecycle
327
- idempotency:
328
- header: Idempotency-Key
329
- required: true
330
- transitions:
331
- - target_state: PAID
332
- trigger_type: synchronous
333
- condition: Payment approved
334
- next_operation_id: payOrder
335
- prerequisite_operation_ids:
336
- - createOrder
337
- prerequisite_field_refs:
338
- - createOrder:request.body.customer_id
339
- propagated_field_refs:
340
- - createOrder:response.201.body.order_id
333
+ Full command details:
334
+
335
+ - [docs/wiki/CLI-Reference.md](https://github.com/tiago-marques/x-openapi-flow/blob/main/docs/wiki/CLI-Reference.md)
336
+ - [x-openapi-flow/README.md](https://github.com/tiago-marques/x-openapi-flow/blob/main/x-openapi-flow/README.md)
337
+
338
+ ---
339
+
340
+ ## Initialization Behavior
341
+
342
+ Running `init`:
343
+
344
+ - Auto-detects OpenAPI source files (`openapi.yaml`, `openapi.json`, `swagger.yaml`, etc.)
345
+ - Creates or syncs `{context}.x.(json|yaml)` (sidecar with lifecycle metadata)
346
+ - Generates `{context}.flow.(json|yaml)` automatically when missing
347
+ - In interactive mode, asks before recreating existing flow files
348
+ - In non-interactive mode, requires `--force` to recreate when flow file already exists
349
+
350
+ Recommended quality gate:
351
+
352
+ ```bash
353
+ npx x-openapi-flow validate openapi.yaml --profile strict
341
354
  ```
342
355
 
343
- Top-level (sidecar document):
356
+ ---
357
+
358
+ ## Validation Profiles
359
+
360
+ - `strict` (default): schema + advanced graph checks as errors; quality as warnings (or errors with `--strict-quality`)
361
+ - `relaxed`: schema and orphan checks as errors; advanced/quality checks as warnings
362
+ - `core`: schema and orphan checks only
363
+
364
+ Validation covers:
365
+
366
+ - Schema contract correctness
367
+ - Orphan states
368
+ - Initial/terminal state structure
369
+ - Cycles and unreachable states
370
+ - Quality findings (duplicate transitions, invalid refs, non-terminating states)
371
+
372
+ ---
373
+
374
+ ## Integrations
344
375
 
345
- - `version` (optional, string): sidecar contract version. Default is `"1.0"`.
346
- - `operations` (optional, array): entries keyed by operation.
376
+ - Swagger UI: flow overview + operation-level extension panels
377
+ - Redoc: generated package with flow panel
378
+ - Postman and Insomnia: generated lifecycle-aware collections/workspaces
379
+ - SDK generator: TypeScript available, other languages planned
347
380
 
348
- Per operation entry:
381
+ Example images:
349
382
 
350
- - `operationId` (recommended, string): target operation identifier in OpenAPI.
351
- - `x-openapi-flow` (object): lifecycle metadata for that operation.
352
- - `key` (optional, legacy): backward-compatibility fallback key used by apply.
383
+ ![Guided graph example](https://raw.githubusercontent.com/tiago-marques/x-openapi-flow/main/docs/assets/x-openapi-flow-overview.png)
384
+ ![Swagger UI integration result](https://raw.githubusercontent.com/tiago-marques/x-openapi-flow/main/docs/assets/x-openapi-flow-extension.png)
353
385
 
354
- `x-openapi-flow` fields:
386
+ Integration docs:
355
387
 
356
- - Required:
357
- - `version` (string): currently `"1.0"`.
358
- - `id` (string): unique flow id.
359
- - `current_state` (string): state represented by this operation.
360
- - Optional:
361
- - `description` (string): human-readable purpose.
362
- - `idempotency` (object):
363
- - `header` (required, string)
364
- - `required` (optional, boolean)
365
- - `transitions` (array of transition objects)
388
+ - [docs/wiki/Swagger-UI-Integration.md](https://github.com/tiago-marques/x-openapi-flow/blob/main/docs/wiki/Swagger-UI-Integration.md)
389
+ - [docs/wiki/Redoc-Integration.md](https://github.com/tiago-marques/x-openapi-flow/blob/main/docs/wiki/Redoc-Integration.md)
390
+ - [docs/wiki/Postman-Integration.md](https://github.com/tiago-marques/x-openapi-flow/blob/main/docs/wiki/Postman-Integration.md)
391
+ - [docs/wiki/Insomnia-Integration.md](https://github.com/tiago-marques/x-openapi-flow/blob/main/docs/wiki/Insomnia-Integration.md)
366
392
 
367
- Transition object fields:
393
+ ---
368
394
 
369
- - Required:
370
- - `target_state` (string)
371
- - `trigger_type` (enum): `synchronous`, `webhook`, `polling`
372
- - Optional:
373
- - `condition` (string)
374
- - `next_operation_id` (string)
375
- - `prerequisite_operation_ids` (array of strings)
376
- - `prerequisite_field_refs` (array of strings)
377
- - `propagated_field_refs` (array of strings)
395
+ ## Copilot Ready (AI Sidecar Authoring)
378
396
 
379
- Field refs format:
397
+ Use [llm.txt](https://github.com/tiago-marques/x-openapi-flow/blob/main/llm.txt) as authoring guidance for sidecar population.
380
398
 
381
- - `operationId:request.body.field`
382
- - `operationId:request.path.paramName`
383
- - `operationId:response.<status>.body.field`
399
+ Typical AI-assisted loop:
384
400
 
385
- ## Configuration
401
+ 1. `init`
402
+ 2. AI fills `{context}.x.(json|yaml)`
403
+ 3. `apply`
404
+ 4. `validate --profile strict`
386
405
 
387
- Create `x-openapi-flow.config.json` in your project directory:
406
+ Prompt template:
388
407
 
389
- ```json
390
- {
391
- "profile": "strict",
392
- "format": "pretty",
393
- "strictQuality": false
394
- }
408
+ ```text
409
+ Use llm.txt from this repository as authoring rules.
410
+ Populate {context}.x.(json|yaml) per operationId with coherent lifecycle states and transitions,
411
+ including next_operation_id, prerequisite_field_refs, and propagated_field_refs when applicable.
412
+ Do not change endpoint paths or HTTP methods.
395
413
  ```
396
414
 
397
- ## Compatibility
415
+ ---
398
416
 
399
- - OpenAPI input in `.yaml`, `.yml`, and `.json`
400
- - Validation processes OAS content with the `x-openapi-flow` extension
417
+ ## Regeneration Workflow
401
418
 
402
- ## Transition Guidance Fields
419
+ ```bash
420
+ # 1) Generate or update OpenAPI source
421
+ # 2) Initialize sidecar metadata
422
+ npx x-openapi-flow init
423
+ # 3) Edit {context}.x.(json|yaml)
424
+ # 4) Re-apply after each OpenAPI regeneration
425
+ npx x-openapi-flow apply openapi.x.yaml
426
+ ```
403
427
 
404
- - `next_operation_id`: operationId usually called for the next state transition
405
- - `prerequisite_operation_ids`: operationIds expected before a transition
406
- - `prerequisite_field_refs`: required field refs before transition
407
- - `propagated_field_refs`: field refs used by downstream flows
428
+ ---
408
429
 
409
- Field reference format:
430
+ ## Included Examples
410
431
 
411
- - `operationId:request.body.field`
412
- - `operationId:response.<status>.body.field`
432
+ - `payment-api.yaml` (financial)
433
+ - `order-api.yaml` (e-commerce/logistics)
434
+ - `ticket-api.yaml` (support)
435
+ - `quality-warning-api.yaml` (quality warnings)
436
+ - `non-terminating-api.yaml` (non-terminating states)
413
437
 
414
- ## Visualization
438
+ More examples: [docs/wiki/Real-Examples.md](https://github.com/tiago-marques/x-openapi-flow/blob/main/docs/wiki/Real-Examples.md)
415
439
 
416
- ### Swagger UI
440
+ ---
441
+
442
+ ## Repository Structure
443
+
444
+ - [x-openapi-flow/schema/flow-schema.json](https://github.com/tiago-marques/x-openapi-flow/blob/main/x-openapi-flow/schema/flow-schema.json): extension JSON Schema contract
445
+ - [x-openapi-flow/lib/validator.js](https://github.com/tiago-marques/x-openapi-flow/blob/main/x-openapi-flow/lib/validator.js): schema + graph validation engine
446
+ - [x-openapi-flow/bin/x-openapi-flow.js](https://github.com/tiago-marques/x-openapi-flow/blob/main/x-openapi-flow/bin/x-openapi-flow.js): CLI entrypoint
447
+ - `x-openapi-flow/examples/*.yaml`: sample OpenAPI files
448
+ - [.github/workflows/x-openapi-flow-validate.yml](https://github.com/tiago-marques/x-openapi-flow/blob/main/.github/workflows/x-openapi-flow-validate.yml): CI validation example
449
+
450
+ ---
417
451
 
418
- - UI plugin behavior is covered by tests in `tests/plugins/plugin-ui.test.js`.
419
- - For UI interpretation of `x-openapi-flow`, use `showExtensions: true` with the plugin at `adapters/ui/swagger-ui/x-openapi-flow-plugin.js`.
420
- - A ready HTML example is available at `../example/openapi-swagger-ui/examples/swagger-ui/index.html`.
421
- - The plugin renders a global **Flow Overview** (Mermaid image) near the top of the docs, plus operation-level flow cards.
452
+ ## Changelog
422
453
 
423
- ![Swagger UI integration result](../docs/assets/x-openapi-flow-extension.png)
454
+ Version history: [CHANGELOG.md](https://github.com/tiago-marques/x-openapi-flow/blob/main/CHANGELOG.md)
455
+ Release notes: [RELEASE_NOTES_v1.3.7.md](https://github.com/tiago-marques/x-openapi-flow/blob/main/RELEASE_NOTES_v1.3.7.md)
424
456
 
425
- ### Graph Output Example
457
+ ---
426
458
 
427
- `x-openapi-flow graph` includes transition guidance labels in Mermaid output when present (`next_operation_id`, `prerequisite_operation_ids`).
428
- The `graph` command accepts both full OpenAPI source files and sidecar files (`{context}.x.(json|yaml)` and legacy `{context}-openapi-flow.(json|yaml)`).
459
+ ## Documentation Language Policy
429
460
 
430
- ![Guided graph example](../docs/assets/x-openapi-flow-overview.png)
461
+ All project documentation must be written in English, including:
431
462
 
432
- ## Repository and Documentation
463
+ - Repository Markdown files
464
+ - Wiki pages
465
+ - Release notes and changelog entries
433
466
 
434
- - Repository: https://github.com/tiago-marques/x-openapi-flow
435
- - Full guide and changelog are available in the root repository.
467
+ If a contribution includes non-English documentation content, it should be translated to English before merge.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x-openapi-flow",
3
- "version": "1.3.5",
3
+ "version": "1.3.7",
4
4
  "description": "OpenAPI extension for resource workflow and lifecycle management",
5
5
  "main": "lib/validator.js",
6
6
  "repository": {
@@ -31,6 +31,8 @@
31
31
  "x-openapi-flow": "bin/x-openapi-flow.js"
32
32
  },
33
33
  "scripts": {
34
+ "sync:readme": "node ../scripts/sync-package-readme.js",
35
+ "prepack": "npm run sync:readme",
34
36
  "test": "npm run test:cli && npm run test:ui && npm run test:integration && npm run test:smoke",
35
37
  "test:cli": "node --test tests/cli/cli.test.js",
36
38
  "test:ui": "node --test tests/plugins/plugin-ui.test.js",