@stackwright-pro/openapi 0.0.0-beta-20260417191149
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 +399 -0
- package/dist/index.d.mts +981 -0
- package/dist/index.d.ts +981 -0
- package/dist/index.js +8733 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +8709 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
# @stackwright-pro/openapi
|
|
2
|
+
|
|
3
|
+
**Transform OpenAPI specifications into type-safe, runtime-validated Stackwright applications**
|
|
4
|
+
|
|
5
|
+
> "Point at an API spec, get production-ready code in minutes, not weeks"
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
`@stackwright-pro/openapi` is the cornerstone of Stackwright Pro's value proposition: automatic code generation from OpenAPI 3.x specifications. It generates Zod validation schemas, TypeScript types, typed API clients, and Stackwright CollectionProviders - all with mathematical correctness guarantees.
|
|
10
|
+
|
|
11
|
+
**For government and enterprise teams:** This means taking existing API specifications (which you already have) and getting type-safe, runtime-validated UIs without manual coding. Hours to first working application. Days to production deployment.
|
|
12
|
+
|
|
13
|
+
## What Gets Generated
|
|
14
|
+
|
|
15
|
+
From a single OpenAPI spec, this package generates:
|
|
16
|
+
|
|
17
|
+
1. **Zod Validation Schemas** - Runtime validation that can't be bypassed
|
|
18
|
+
2. **TypeScript Types** - Compile-time type safety
|
|
19
|
+
3. **CollectionProviders** - Integration with Stackwright content system
|
|
20
|
+
4. **Typed API Clients** - Fully typed fetch functions (coming soon)
|
|
21
|
+
|
|
22
|
+
All code is generated at build time via the prebuild plugin system.
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# Private package - contact Per Aspera LLC for access
|
|
28
|
+
pnpm add @stackwright-pro/openapi
|
|
29
|
+
|
|
30
|
+
# Peer dependencies (already in Stackwright projects)
|
|
31
|
+
pnpm add @stackwright/types @stackwright/build-scripts zod
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Quick Start
|
|
35
|
+
|
|
36
|
+
### 1. Configure Integration
|
|
37
|
+
|
|
38
|
+
Add to your `stackwright.yml`:
|
|
39
|
+
|
|
40
|
+
```yaml
|
|
41
|
+
theme:
|
|
42
|
+
id: my-app
|
|
43
|
+
name: My Application
|
|
44
|
+
|
|
45
|
+
integrations:
|
|
46
|
+
- type: openapi
|
|
47
|
+
name: logistics
|
|
48
|
+
spec: ./specs/logistics-api.yaml
|
|
49
|
+
auth:
|
|
50
|
+
type: bearer
|
|
51
|
+
token: $API_TOKEN
|
|
52
|
+
collections:
|
|
53
|
+
- endpoint: /equipment
|
|
54
|
+
slug_field: id
|
|
55
|
+
- endpoint: /supplies
|
|
56
|
+
slug_field: id
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### 2. Register Plugin
|
|
60
|
+
|
|
61
|
+
Create `scripts/prebuild.js`:
|
|
62
|
+
|
|
63
|
+
```javascript
|
|
64
|
+
const { runPrebuild } = require('@stackwright/build-scripts');
|
|
65
|
+
const { createOpenAPIPlugin } = require('@stackwright-pro/openapi');
|
|
66
|
+
|
|
67
|
+
async function main() {
|
|
68
|
+
await runPrebuild({
|
|
69
|
+
plugins: [createOpenAPIPlugin()],
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
main().catch(console.error);
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Update `package.json`:
|
|
77
|
+
|
|
78
|
+
```json
|
|
79
|
+
{
|
|
80
|
+
"scripts": {
|
|
81
|
+
"prebuild": "node scripts/prebuild.js",
|
|
82
|
+
"predev": "node scripts/prebuild.js",
|
|
83
|
+
"dev": "next dev",
|
|
84
|
+
"build": "next build"
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 3. Generate Code
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
pnpm prebuild
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
This generates code to `src/generated/logistics/`:
|
|
96
|
+
- `schemas.ts` - Zod validation schemas
|
|
97
|
+
- `types.ts` - TypeScript type definitions
|
|
98
|
+
- `provider.ts` - CollectionProvider implementations
|
|
99
|
+
- `client.ts` - Typed API client (coming soon)
|
|
100
|
+
|
|
101
|
+
### 4. Use Generated Code
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
import { EquipmentSchema } from '@/generated/logistics/schemas';
|
|
105
|
+
import type { Equipment } from '@/generated/logistics/types';
|
|
106
|
+
|
|
107
|
+
// Runtime validation (mathematically proven safe)
|
|
108
|
+
const validated = EquipmentSchema.parse(untrustedData);
|
|
109
|
+
|
|
110
|
+
// Compile-time type safety
|
|
111
|
+
const equipment: Equipment = {
|
|
112
|
+
id: '123',
|
|
113
|
+
name: 'HMMWV',
|
|
114
|
+
status: 'operational', // TypeScript error if invalid
|
|
115
|
+
};
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### 5. Integrate with Stackwright
|
|
119
|
+
|
|
120
|
+
The generated CollectionProvider automatically integrates with Stackwright:
|
|
121
|
+
|
|
122
|
+
```yaml
|
|
123
|
+
# pages/equipment/content.yml
|
|
124
|
+
content:
|
|
125
|
+
content_items:
|
|
126
|
+
- type: collection_list
|
|
127
|
+
label: equipment-list
|
|
128
|
+
source: logistics-equipment # Auto-generated from OpenAPI
|
|
129
|
+
card:
|
|
130
|
+
heading: "{{name}}"
|
|
131
|
+
description: "{{description}}"
|
|
132
|
+
metadata:
|
|
133
|
+
- label: "Status"
|
|
134
|
+
value: "{{status}}"
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Architecture
|
|
138
|
+
|
|
139
|
+
### The Zod Schema Generator (Core Engine)
|
|
140
|
+
|
|
141
|
+
The `ZodSchemaGenerator` is the mathematical proof engine that ensures runtime validation:
|
|
142
|
+
|
|
143
|
+
**Supported OpenAPI Features:**
|
|
144
|
+
- ✅ All primitive types (string, number, boolean, integer, null)
|
|
145
|
+
- ✅ Objects (required/optional properties, additionalProperties)
|
|
146
|
+
- ✅ Arrays (with item validation, constraints)
|
|
147
|
+
- ✅ Enums (string and number)
|
|
148
|
+
- ✅ String formats (email, url, uuid, date-time, date, time, ipv4, ipv6)
|
|
149
|
+
- ✅ Number constraints (minimum, maximum, multipleOf, exclusiveMinimum/Maximum)
|
|
150
|
+
- ✅ String constraints (minLength, maxLength, pattern regex)
|
|
151
|
+
- ✅ Array constraints (minItems, maxItems, uniqueItems)
|
|
152
|
+
- ✅ Object constraints (minProperties, maxProperties)
|
|
153
|
+
- ✅ Composition (allOf, oneOf, anyOf)
|
|
154
|
+
- ✅ $ref resolution (local and external references)
|
|
155
|
+
- ✅ Nullable types (`nullable: true` or `type: ["string", "null"]`)
|
|
156
|
+
- ✅ Default values
|
|
157
|
+
- ✅ Read-only and write-only properties
|
|
158
|
+
|
|
159
|
+
**27 comprehensive tests** ensure correctness.
|
|
160
|
+
|
|
161
|
+
### The OpenAPI Parser
|
|
162
|
+
|
|
163
|
+
Parses OpenAPI 3.0.x and 3.1.x specifications:
|
|
164
|
+
- Supports local files and remote URLs
|
|
165
|
+
- Validates spec structure
|
|
166
|
+
- Extracts paths, schemas, operations
|
|
167
|
+
- Resolves $ref pointers (including circular references)
|
|
168
|
+
|
|
169
|
+
### The Type Generator
|
|
170
|
+
|
|
171
|
+
Converts OpenAPI schemas to TypeScript interfaces:
|
|
172
|
+
- Proper optional vs required property handling
|
|
173
|
+
- Union types for oneOf/anyOf
|
|
174
|
+
- Intersection types for allOf
|
|
175
|
+
- Type inference from Zod schemas
|
|
176
|
+
|
|
177
|
+
### The CollectionProvider Generator
|
|
178
|
+
|
|
179
|
+
Generates typed Stackwright CollectionProviders:
|
|
180
|
+
- Fetches data from API endpoints
|
|
181
|
+
- Applies schema validation automatically
|
|
182
|
+
- Handles authentication (bearer, apiKey)
|
|
183
|
+
- Error handling and retries
|
|
184
|
+
- Integrates with Stackwright content system
|
|
185
|
+
|
|
186
|
+
### The Prebuild Plugin
|
|
187
|
+
|
|
188
|
+
Runs automatically during `pnpm dev` and `pnpm build`:
|
|
189
|
+
- Reads integration config from `stackwright.yml`
|
|
190
|
+
- Parses OpenAPI specs
|
|
191
|
+
- Generates all code files
|
|
192
|
+
- Writes to `src/generated/{integrationName}/`
|
|
193
|
+
|
|
194
|
+
## Authentication
|
|
195
|
+
|
|
196
|
+
### Bearer Token
|
|
197
|
+
|
|
198
|
+
```yaml
|
|
199
|
+
integrations:
|
|
200
|
+
- type: openapi
|
|
201
|
+
name: api
|
|
202
|
+
spec: ./spec.yaml
|
|
203
|
+
auth:
|
|
204
|
+
type: bearer
|
|
205
|
+
token: $API_TOKEN # Environment variable
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### API Key
|
|
209
|
+
|
|
210
|
+
```yaml
|
|
211
|
+
integrations:
|
|
212
|
+
- type: openapi
|
|
213
|
+
name: api
|
|
214
|
+
spec: ./spec.yaml
|
|
215
|
+
auth:
|
|
216
|
+
type: apiKey
|
|
217
|
+
name: X-API-Key
|
|
218
|
+
in: header # or 'query'
|
|
219
|
+
value: $API_KEY
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### OAuth2 (Coming Soon)
|
|
223
|
+
|
|
224
|
+
OAuth2 flows will be supported in a future release.
|
|
225
|
+
|
|
226
|
+
## Collections
|
|
227
|
+
|
|
228
|
+
Map OpenAPI endpoints to Stackwright collections:
|
|
229
|
+
|
|
230
|
+
```yaml
|
|
231
|
+
integrations:
|
|
232
|
+
- type: openapi
|
|
233
|
+
name: logistics
|
|
234
|
+
spec: ./specs/logistics-api.yaml
|
|
235
|
+
collections:
|
|
236
|
+
- endpoint: /equipment
|
|
237
|
+
method: get # default
|
|
238
|
+
slug_field: id
|
|
239
|
+
|
|
240
|
+
- endpoint: /supplies
|
|
241
|
+
slug_field: item_id
|
|
242
|
+
|
|
243
|
+
- endpoint: /personnel
|
|
244
|
+
slug_field: employee_id
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
Each collection generates:
|
|
248
|
+
- Zod schema for validation
|
|
249
|
+
- TypeScript type for compile-time safety
|
|
250
|
+
- CollectionProvider for data fetching
|
|
251
|
+
|
|
252
|
+
## Examples
|
|
253
|
+
|
|
254
|
+
### Government Logistics API
|
|
255
|
+
|
|
256
|
+
See `examples/marine-logistics-demo/` for a complete working example integrating with a Marine Corps logistics API.
|
|
257
|
+
|
|
258
|
+
### E-Commerce Product Catalog
|
|
259
|
+
|
|
260
|
+
```yaml
|
|
261
|
+
integrations:
|
|
262
|
+
- type: openapi
|
|
263
|
+
name: products
|
|
264
|
+
spec: https://api.example.com/openapi.json
|
|
265
|
+
auth:
|
|
266
|
+
type: bearer
|
|
267
|
+
token: $SHOPIFY_TOKEN
|
|
268
|
+
collections:
|
|
269
|
+
- endpoint: /products
|
|
270
|
+
slug_field: sku
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### Multi-API Integration
|
|
274
|
+
|
|
275
|
+
```yaml
|
|
276
|
+
integrations:
|
|
277
|
+
- type: openapi
|
|
278
|
+
name: users
|
|
279
|
+
spec: ./specs/users-api.yaml
|
|
280
|
+
collections:
|
|
281
|
+
- endpoint: /users
|
|
282
|
+
slug_field: id
|
|
283
|
+
|
|
284
|
+
- type: openapi
|
|
285
|
+
name: orders
|
|
286
|
+
spec: ./specs/orders-api.yaml
|
|
287
|
+
collections:
|
|
288
|
+
- endpoint: /orders
|
|
289
|
+
slug_field: order_id
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## API Reference
|
|
293
|
+
|
|
294
|
+
### OpenAPIPlugin
|
|
295
|
+
|
|
296
|
+
```typescript
|
|
297
|
+
import { createOpenAPIPlugin } from '@stackwright-pro/openapi';
|
|
298
|
+
|
|
299
|
+
const plugin = createOpenAPIPlugin();
|
|
300
|
+
|
|
301
|
+
await runPrebuild({
|
|
302
|
+
plugins: [plugin],
|
|
303
|
+
});
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
### OpenAPIParser
|
|
307
|
+
|
|
308
|
+
```typescript
|
|
309
|
+
import { OpenAPIParser } from '@stackwright-pro/openapi';
|
|
310
|
+
|
|
311
|
+
const parser = new OpenAPIParser();
|
|
312
|
+
const { document } = await parser.parse('./spec.yaml');
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### ZodSchemaGenerator
|
|
316
|
+
|
|
317
|
+
```typescript
|
|
318
|
+
import { ZodSchemaGenerator } from '@stackwright-pro/openapi';
|
|
319
|
+
|
|
320
|
+
const generator = new ZodSchemaGenerator();
|
|
321
|
+
const zodCode = generator.generate(schema, { schemaName: 'UserSchema' });
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### TypeGenerator
|
|
325
|
+
|
|
326
|
+
```typescript
|
|
327
|
+
import { TypeGenerator } from '@stackwright-pro/openapi';
|
|
328
|
+
|
|
329
|
+
const generator = new TypeGenerator();
|
|
330
|
+
const typeCode = generator.generate(schema, { typeName: 'User' });
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### CollectionProviderGenerator
|
|
334
|
+
|
|
335
|
+
```typescript
|
|
336
|
+
import { CollectionProviderGenerator } from '@stackwright-pro/openapi';
|
|
337
|
+
|
|
338
|
+
const generator = new CollectionProviderGenerator(openAPIDocument);
|
|
339
|
+
const providerCode = generator.generate(collectionConfig);
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
## Testing
|
|
343
|
+
|
|
344
|
+
The package includes comprehensive test coverage:
|
|
345
|
+
|
|
346
|
+
```bash
|
|
347
|
+
cd packages/openapi
|
|
348
|
+
pnpm test
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
**Test suites:**
|
|
352
|
+
- `parser.test.ts` - OpenAPI parsing and $ref resolution
|
|
353
|
+
- `zod-generator.test.ts` - 27 tests covering all schema features
|
|
354
|
+
- `type-generator.test.ts` - TypeScript type generation
|
|
355
|
+
- `collection-provider-generator.test.ts` - Provider generation
|
|
356
|
+
- `prebuild-plugin.test.ts` - Plugin integration
|
|
357
|
+
|
|
358
|
+
## Troubleshooting
|
|
359
|
+
|
|
360
|
+
### "Integration not found in stackwright.yml"
|
|
361
|
+
|
|
362
|
+
Ensure your `integrations` section is at the root level of `stackwright.yml`, not nested under `theme` or other properties.
|
|
363
|
+
|
|
364
|
+
### "Failed to parse OpenAPI spec"
|
|
365
|
+
|
|
366
|
+
- Validate your spec at https://editor.swagger.io
|
|
367
|
+
- Ensure the spec version is 3.0.x or 3.1.x (not Swagger 2.0)
|
|
368
|
+
- Check for $ref resolution errors
|
|
369
|
+
|
|
370
|
+
### "Generated code not found"
|
|
371
|
+
|
|
372
|
+
- Verify `pnpm prebuild` runs successfully
|
|
373
|
+
- Check `src/generated/{integrationName}/` exists
|
|
374
|
+
- Ensure build scripts are configured in `package.json`
|
|
375
|
+
|
|
376
|
+
### TypeScript errors in generated code
|
|
377
|
+
|
|
378
|
+
- Run `pnpm build:openapi` to regenerate
|
|
379
|
+
- Check for breaking changes in your OpenAPI spec
|
|
380
|
+
- Verify zod is installed as a dependency
|
|
381
|
+
|
|
382
|
+
## License
|
|
383
|
+
|
|
384
|
+
**Proprietary** - Commercial license. See [LICENSE](../../LICENSE) for terms.
|
|
385
|
+
|
|
386
|
+
The open-source Stackwright framework is MIT licensed at [github.com/Per-Aspera-LLC/stackwright](https://github.com/Per-Aspera-LLC/stackwright).
|
|
387
|
+
|
|
388
|
+
## Support
|
|
389
|
+
|
|
390
|
+
For enterprise support, custom integrations, or government procurement inquiries:
|
|
391
|
+
|
|
392
|
+
- **Email:** support@peraspera.llc
|
|
393
|
+
- **GitHub Issues:** [stackwright-pro/issues](https://github.com/Per-Aspera-LLC/stackwright-pro/issues)
|
|
394
|
+
- **Documentation:** [stackwright-pro/docs](https://github.com/Per-Aspera-LLC/stackwright-pro/tree/main/docs)
|
|
395
|
+
|
|
396
|
+
---
|
|
397
|
+
|
|
398
|
+
**Built by [Per Aspera LLC](https://github.com/Per-Aspera-LLC)**
|
|
399
|
+
*"Through hardship to the stars"*
|