Docs / OpenAPI
OpenAPI
One command turns your models and routes into an OpenAPI 3.1 spec.
Added in 1.0
Hopak already knows your API: models declare fields, types, and constraints; CRUD routes are generated from models. hopak openapi turns that knowledge into an OpenAPI 3.1 document — zero annotations required.
hopak openapi # prints to stdout
hopak openapi --out api.json # writes a file
Pipe it straight into a client generator:
hopak openapi | bunx openapi-typescript /dev/stdin -o api.d.ts
What you get
- Model schemas — every model becomes two component schemas:
Post(response shape —password/secret/tokenfields stripped,id+ timestamps present) andPostInput(request body — sensitive fields included, noid). - Typed CRUD operations — routes built with
crud.*carry metadata linking them to their model, soGET /api/postsdocuments the real{ items, total, limit, offset }envelope,POSTdocuments the request body and201/400/409responses, and so on. - Path parameters —
[id]segments become{id}with path parameters filled in. - Constraints —
.min()/.max()/.pattern()/ enum values flow into the schemas.
Custom routes
Hand-written routes appear with a generic 200 response. To document one against a model, set openapi in defineRoute:
export const GET = defineRoute({
handler: async (ctx) => { /* ... */ },
openapi: { model: 'post', kind: 'read', summary: 'Fetch one post' },
});