feat: per-route body limits, custom error rendering, OpenAPI generation
CI / build (push) Has been cancelled
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:
19 files changed
+811
-100
No files matched your search
@@ -57,7 +57,14 @@ Uploaded files are held in memory, so they're bounded by the same `maxBodyBytes`
|
||||
const app = createApp({ modules: [ApiModule], limits: { maxParts: 500 } });
|
||||
```
|
||||
|
||||
A malformed multipart body (bad boundary, missing headers, truncated part) → **400**.
|
||||
Both limits can be overridden **per route** — an upload endpoint can allow a larger body than the rest of the API:
|
||||
|
||||
```typescript
|
||||
@Post('/avatar', { maxBodyBytes: 5_000_000, maxParts: 20 })
|
||||
uploadAvatar(@body() form: MultipartBody) { /* ... */ }
|
||||
```
|
||||
|
||||
A route's `maxBodyBytes` / `maxParts` fall back to the server-wide `limits` when unset. A malformed multipart body (bad boundary, missing headers, truncated part) → **400**.
|
||||
|
||||
:::note
|
||||
To validate parsed fields against a schema, pass a Standard Schema to `@body()` — see [validation](/guides/validation/).
|
||||
|
||||
Reference in new issue
Block a user