Convert an OpenAPI specification into a fully working, tested API server through an automated 10-phase pipeline.
| Phase | Name | Description |
|---|---|---|
| 1 | Schema Intake | Parse and validate the OpenAPI spec, extract models and endpoints |
| 2 | Database Design | Generate Drizzle ORM table schemas with relations and indexes |
| 3 | Migration Generation | Create timestamped SQL migration files from Drizzle schemas |
| 4 | TDD Test Writing | Write integration tests for every endpoint before implementation |
| 5 | Route Generation | Scaffold Hono route handlers matching the OpenAPI paths |
| 6 | Service Layer | Build business logic services called by route handlers |
| 7 | Validation Layer | Generate Zod schemas for request/response validation |
| 8 | Auth & Security | Wire authentication middleware, CORS, rate limiting |
| 9 | Documentation | Generate API docs, Swagger UI config, example responses |
| 10 | Deployment Config | Produce Wrangler TOML, Dockerfile, or both |
What it does: Parses the OpenAPI YAML or JSON file, validates it against the OpenAPI 3.0/3.1 specification, and extracts a normalized model of all schemas, paths, parameters, and responses.
- Inputs: OpenAPI spec file (YAML or JSON)
- Outputs:
pipeline-state.jsonwith parsed models, endpoints, and dependency graph - Tools:
@apidevtools/swagger-parserfor validation, custom AST walker for extraction - Config:
pipeline.config.json--schemaPath,strictValidation
What it does: Converts OpenAPI component schemas into Drizzle ORM table definitions. Infers relations from $ref pointers and naming conventions. Adds appropriate indexes based on query patterns implied by endpoint parameters.
- Inputs: Parsed models from Phase 1
- Outputs:
api/src/db/schema/*.tsfiles (one per resource) - Tools: Drizzle ORM schema builder,
database-designskill - Config:
pipeline.config.json--database.provider(pg, d1),database.naming(snake_case)
What it does: Generates SQL migration files from the Drizzle schema diff. Each migration is timestamped and includes both up and down operations.
- Inputs: Drizzle schema files from Phase 2
- Outputs:
api/src/db/migrations/YYYYMMDD_HHMMSS_*.sql - Tools:
drizzle-kit generate, custom rollback generator - Config:
pipeline.config.json--database.migrationsDir
What it does: Writes integration tests for every endpoint defined in the OpenAPI spec. Tests cover success paths, validation errors, 404s, auth failures, and edge cases. This phase runs before route implementation -- the TDD gate is enforced.
- Inputs: Endpoint definitions from Phase 1, schemas from Phase 2
- Outputs:
api/tests/integration/*.test.tsfiles - Tools: Vitest, supertest,
tdd-from-schemaskill - Config:
pipeline.config.json--testing.minCoverage,testing.includeLoadTests
What it does: Scaffolds Hono route handlers for each OpenAPI path. Groups routes by resource using Hono.route(). Wires middleware chains for auth, validation, and error handling.
- Inputs: Endpoint definitions, test expectations from Phase 4
- Outputs:
api/src/routes/*.tsfiles (one per resource) - Tools: Hono router,
route-generationskill - Config:
pipeline.config.json--routes.prefix,routes.versioning
What it does: Generates service classes that contain business logic. Routes delegate to services, which handle database queries, transformations, and transaction management.
- Inputs: Route handlers from Phase 5, Drizzle schemas from Phase 2
- Outputs:
api/src/services/*.tsfiles - Tools: Drizzle query builder, transaction helpers
- Config:
pipeline.config.json--services.transactionIsolation
What it does: Generates Zod schemas from Drizzle table types and OpenAPI request/response definitions. Wires zValidator middleware into route chains.
- Inputs: Drizzle schemas, OpenAPI request/response bodies
- Outputs:
api/src/types/validators/*.ts, updated route middleware - Tools:
drizzle-zod,@hono/zod-validator,api-validationskill - Config:
pipeline.config.json--validation.stripUnknown,validation.coerceTypes
What it does: Configures authentication middleware (JWT, API key, or both), role-based access control, CORS policies, rate limiting, and security headers.
- Inputs: OpenAPI security schemes, route definitions
- Outputs:
api/src/middleware/auth.ts,api/src/middleware/security.ts, updated routes - Tools:
hono/jwt, custom RBAC middleware,api-authenticationandapi-securityskills - Config:
pipeline.config.json--auth.strategy,auth.jwtSecret,security.rateLimit
What it does: Generates enriched API documentation including Swagger UI configuration, example request/response payloads, and error code references.
- Inputs: Finalized routes, Zod schemas, auth configuration
- Outputs:
api/src/routes/docs.ts(Swagger UI route), updated OpenAPI spec - Tools:
@hono/swagger-ui,api-documentationskill - Config:
pipeline.config.json--docs.title,docs.version,docs.servers
What it does: Produces deployment configuration files matching the target platform. For Cloudflare Workers: wrangler.toml with D1 bindings. For Node.js: Dockerfile with multi-stage build and docker-compose.yml.
- Inputs: Project structure, database config, environment variables
- Outputs:
wrangler.tomland/orDockerfile+docker-compose.yml - Tools:
deployment-config-generatorskill - Config:
pipeline.config.json--deployment.target(cloudflare, node, both)
All pipeline behavior is controlled by pipeline.config.json in the project root:
{
"schemaPath": "./openapi.yaml",
"strictValidation": true,
"database": {
"provider": "pg",
"naming": "snake_case",
"migrationsDir": "api/src/db/migrations"
},
"routes": {
"prefix": "/api/v1",
"versioning": true
},
"testing": {
"minCoverage": 80,
"includeLoadTests": false,
"contractTestsEnabled": true
},
"validation": {
"stripUnknown": true,
"coerceTypes": true
},
"auth": {
"strategy": "jwt",
"jwtSecret": "${JWT_SECRET}"
},
"security": {
"rateLimit": { "max": 100, "window": "1m" },
"cors": { "origins": ["*"] }
},
"docs": {
"title": "My API",
"version": "1.0.0",
"servers": [{ "url": "http://localhost:8787" }]
},
"deployment": {
"target": "cloudflare"
}
}The pipeline writes progress to pipeline-state.json after each phase completes. If a build is interrupted:
/build-from-schema openapi-spec.yaml --resume
This reads the state file and resumes from the last completed phase. To force a restart from a specific phase:
/build-from-schema openapi-spec.yaml --from-phase 4
To re-run only a single phase:
/build-from-schema openapi-spec.yaml --only-phase 7
| Issue | Cause | Solution |
|---|---|---|
| "Invalid OpenAPI spec" in Phase 1 | Malformed YAML or missing required fields | Run ./scripts/validate-openapi.sh spec.yaml for detailed errors |
| Phase 4 tests fail immediately | Database not running or migrations not applied | Run ./scripts/run-migrations.sh before re-running Phase 4 |
| "Cannot resolve $ref" | Circular or broken schema references | Split circular refs into separate schemas with explicit IDs |
| Route conflicts in Phase 5 | Duplicate paths in OpenAPI spec | Check for overlapping path patterns (e.g., /{id} vs /me) |
| Auth middleware errors in Phase 8 | Missing JWT_SECRET environment variable | Set JWT_SECRET in .env or wrangler.toml secrets |
| D1 binding errors | Wrangler not configured for D1 | Run npx wrangler d1 create <db-name> and update wrangler.toml |
| Docker build fails | Missing dependencies in Dockerfile | Ensure pnpm-lock.yaml is not in .dockerignore |
Given this OpenAPI spec (todo-api.yaml):
openapi: "3.1.0"
info:
title: Todo API
version: "1.0.0"
paths:
/todos:
get:
summary: List all todos
responses:
"200":
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/Todo"
post:
summary: Create a todo
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/CreateTodo"
responses:
"201":
content:
application/json:
schema:
$ref: "#/components/schemas/Todo"
/todos/{id}:
get:
summary: Get a todo by ID
put:
summary: Update a todo
delete:
summary: Delete a todo
components:
schemas:
Todo:
type: object
properties:
id:
type: string
format: uuid
title:
type: string
completed:
type: boolean
createdAt:
type: string
format: date-time
CreateTodo:
type: object
required: [title]
properties:
title:
type: stringRun the pipeline:
/build-from-schema todo-api.yaml
The pipeline produces:
api/src/db/schema/todos.ts-- Drizzle table withid,title,completed,createdAtapi/src/db/migrations/20260329_120000_create_todos.sql-- CREATE TABLE migrationapi/tests/integration/todos.test.ts-- Tests for GET/POST/PUT/DELETEapi/src/routes/todos.ts-- Hono route handlersapi/src/services/todo-service.ts-- CRUD business logicapi/src/types/validators/todo.ts-- Zod schemas for validation- Deployment config matching your target platform
All tests pass against the generated implementation, and the API matches the OpenAPI contract exactly.