Files
core/website/src/content/docs/guides/openapi.md
T
chrnx 2db5de6858
CI / build (push) Has been cancelled
feat: per-route body limits, custom error rendering, OpenAPI generation
Three capabilities that share the same request/route metadata:

- **Per-route upload limits** — `@Post('/x', { maxBodyBytes, maxParts })`
  overrides the server-wide `limits` for one route (falls back to the
  global default), mirroring the existing per-route `duplicates`.

- **Custom error rendering** — `createApp({ onError })` takes over how any
  error becomes a response (HTML, RFC 7807, content-negotiated), covering
  the whole surface: handler/step throws, 404, 405, 413, 400. Returns a
  response or undefined to fall back to the default JSON. Also wires the
  previously-unused `HttpError` `body` field so `throw new HttpError(409,
  'conflict', { code })` renders a structured payload. Default behavior is
  unchanged when no hook is set.

- **OpenAPI 3.1** — `app.openapi(info?)` projects the route graph into a
  structural spec (paths, methods, path/query/header params, request-body
  presence, systematic error responses); opt-in `GET /__openapi__` via
  `devOpenapi`. Body/response schemas stay generic (Standard Schema exposes
  no JSON Schema) — the full `@Produce` mode is post-beta.

Docs: new error-handling and OpenAPI guides, plus reference updates.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-07-08 08:29:17 -05:00

2.0 KiB

title, description
title description
OpenAPI Generate a structural OpenAPI 3.1 document from the route graph.

Because the request pipeline is data you can read, green-tea can project it — the same way it renders Mermaid/DOT, it emits OpenAPI.

app.openapi()

const app = createApp({ modules: [ApiModule] });
const spec = app.openapi({ title: 'My API', version: '1.0.0' });
// → OpenAPI 3.1 document

It reads the routes and handler signatures and produces, for each route:

  • the path, templated — /users/:id → /users/{id}, catch-all :path* → {path};
  • the method;
  • parameters — path params from the pattern, plus query/header params from the handler's @query / @headers / @header decorators;
  • a request body entry for routes that read @body();
  • the systematic responses — 200, a 422 when any argument is schema-validated, and 500.

WebSocket routes are omitted (they aren't request/response).

Serve it — devOpenapi

Opt in to a GET /__openapi__ endpoint that returns the document as JSON — point Swagger UI, Redoc, or a codegen client at it:

const app = createApp({ modules: [ApiModule], devOpenapi: true });
// GET /__openapi__  →  application/json

What's structural (and what isn't yet)

This is a structural spec: paths, methods, parameters, which routes take a body, and the standard error responses. What it does not include yet:

  • Request/response body schemas. Standard Schema (zod/valibot/arktype) validates input but does not expose a JSON Schema representation, so body shapes are documented generically. Parameter types default to string.

Full schemas — declared and enforced on the way out via a @Produce(schema) decorator that also validates responses — are on the roadmap for the stable release. For beta, the structural document already drives Swagger UI, client codegen, and API diffing.