feat: per-route body limits, custom error rendering, OpenAPI generation
CI / build (push) Has been cancelled

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>
This commit is contained in:
chrnx committed 2026-07-08 08:29:17 -05:00
1 parent 7c20d74fe4
commit 2db5de6858
19 files changed
+811 -100

No files matched your search

+8 -1
View File
@@ -31,6 +31,8 @@ export interface RouteMeta {
transport: Transport;
export: boolean;
duplicates?: 'array' | 'last';
maxBodyBytes?: number;
maxParts?: number;
}
/** Options accepted by the `@Module` decorator. */
export interface ModuleOptions {
@@ -93,7 +95,10 @@ export function Route(prefix: string): ClassDecorator {
}
function routeDecorator(method: HttpMethod, transport: Transport) {
return (path: string, opts?: { export?: boolean; duplicates?: 'array' | 'last' }): MethodDecorator =>
return (
path: string,
opts?: { export?: boolean; duplicates?: 'array' | 'last'; maxBodyBytes?: number; maxParts?: number },
): MethodDecorator =>
(target, propertyKey) => {
const ctor = target.constructor;
const routes = (Reflect.getMetadata(K.routes, ctor) as RouteMeta[]) ?? [];
@@ -104,6 +109,8 @@ function routeDecorator(method: HttpMethod, transport: Transport) {
transport,
export: opts?.export ?? false,
duplicates: opts?.duplicates,
maxBodyBytes: opts?.maxBodyBytes,
maxParts: opts?.maxParts,
});
Reflect.defineMetadata(K.routes, routes, ctor);
};