@@ -17,6 +17,7 @@ OpenAPI Spec → [CLI] → Generated Server Interface → [Your API Implementati
1717```
1818
1919Key insight: Your handler return values mirror OpenAPI response structure:
20+
2021``` typescript
2122return {
2223 content: {
@@ -32,6 +33,7 @@ return {
3233### Generated Code Pattern
3334
3435CLI generates per-operation:
36+
3537- ` <OperationId>Args<Req, Res> ` interface with typed parameters, requestBody, and framework objects
3638- ` <OperationId>Result ` type union of all response variants
3739- ` <OperationId>Unimplemented() ` stub throwing ` NotImplementedError `
@@ -49,19 +51,21 @@ CLI generates per-operation:
4951## Development Workflow
5052
5153### Initial Setup (Required Order)
54+
5255``` bash
5356node --version # Must be >= 23.6.0
5457npm ci # 30 seconds - NEVER CANCEL
5558npm run build:packages # 5 seconds - builds .cjs files
5659npm run gen:examples # 5 seconds - validates CLI works
5760npm run format:check # 2 seconds
58- npm run typecheck # 3 seconds
61+ npm run typecheck # 3 seconds
5962npm test # 1 second
6063```
6164
6265** NEVER** run ` npm ci ` with short timeout. Set to 60+ minutes or it will fail.
6366
6467### After Code Changes (Validation Sequence)
68+
6569``` bash
6670npm run format # Auto-fix formatting (required before commit)
6771npm run build:packages # Re-build if CLI or adapters changed
@@ -71,6 +75,7 @@ npm test # All tests must pass
7175```
7276
7377### Testing Generated Code Locally
78+
7479``` bash
7580cd examples/docs
7681npm run start # Runs: node --watch cmd/index.ts (port 8080)
@@ -83,6 +88,7 @@ curl -X POST http://localhost:8080/api/v3/speak/123 \
8388```
8489
8590### Regenerating After OpenAPI Changes
91+
8692``` bash
8793# In example directory or your project:
8894openapi-typescript ./openapi.yaml --output ./gen/schema.d.ts
@@ -113,9 +119,9 @@ openapi-typescript-server ./openapi.yaml --types ./schema.d.ts --output ./gen/se
113119 ``` typescript
114120 registerRoutes (routes , app , {
115121 serializers: {
116- " application/xml" : (content ) => json2xml (JSON .stringify (content ))
117- }
118- })
122+ " application/xml" : (content ) => json2xml (JSON .stringify (content )),
123+ },
124+ });
119125 ```
120126
121127### Error Handling Patterns
@@ -136,6 +142,7 @@ See `examples/docs/api.ts` for error pattern with `"default"` response variant.
136142- Run: ` npm test ` at root (runs across all workspaces) or per-package
137143
138144Example pattern (` examples/docs/app.test.ts ` ):
145+
139146``` typescript
140147import { describe , it } from " node:test" ;
141148import assert from " node:assert" ;
@@ -163,12 +170,12 @@ packages/
163170 index.ts # Entry point, arg parsing
164171 generate.ts # Core codegen logic (creates Server interface)
165172 bin/cli/index.cjs # Built binary (created by build:packages)
166-
173+
167174 openapi-typescript-server-runtime/ # Shared types (Route, errors)
168175 src/
169176 route.ts # Route, HandlerInput, HandlerResponse types
170177 errors.ts # NotImplementedError
171-
178+
172179 openapi-typescript-server-express/ # Express adapter
173180 src/
174181 index.ts # registerRoutes() function
@@ -189,19 +196,22 @@ examples/
189196## Key Workflows for Common Tasks
190197
191198### Adding Support for New Response Pattern
199+
1922001 . Update ` packages/openapi-typescript-server/src/cli/generate.ts ` response variant logic
1932012 . Update ` packages/openapi-typescript-server-express/src/index.ts ` to handle new variant
1942023 . Add test case to ` packages/openapi-typescript-server-express/src/index.test.ts `
1952034 . Run ` npm run build:packages && npm run gen:examples && npm test `
196204
197205### Adding New Framework Adapter
206+
1982071 . Create ` packages/openapi-typescript-server-<framework>/ `
199- 2 . Implement ` registerRoutes(routes: Route[], app: FrameworkApp) `
208+ 2 . Implement ` registerRoutes(routes: Route[], app: FrameworkApp) `
2002093 . Handle parameter extraction, content negotiation, serialization per framework conventions
2012104 . Reference ` openapi-typescript-server-express ` as template
2022115 . Add integration tests using framework's test utilities
203212
204213### Debugging Type Errors After Regeneration
214+
2052151 . Check OpenAPI spec changed: Compare old/new ` openapi.yaml `
2062162 . Check generated types: ` git diff gen/schema.d.ts gen/server.ts `
2072173 . Restart TS Server: VS Code may cache old types
@@ -211,6 +221,7 @@ examples/
211221## CI/CD Pipeline (` .github/workflows/test.yaml ` )
212222
213223Runs on every commit:
224+
214225``` yaml
215226npm ci
216227npm run format:check # Fails if code not formatted
@@ -235,7 +246,7 @@ npm test
235246## Common Mistakes
236247
237248- ❌ Forgetting to run ` npm run build:packages ` after CLI changes (tests import stale code)
238- - ❌ Not regenerating examples after CLI changes (CI will fail on diff check)
249+ - ❌ Not regenerating examples after CLI changes (CI will fail on diff check)
239250- ❌ Using structural typing instead of explicit ` Server<Req, Res> ` type (loses inference)
240251- ❌ Mounting routes without base path (OpenAPI ` servers.url ` ignored by adapter)
241252- ❌ Returning ` "default" ` response without ` status ` field (throws error at runtime)
0 commit comments