English
OpenAPI
This guide covers the OpenAPI document and Swagger UI.
OpenAPI + Swagger UI
OpenApiProvider serves interactive docs of your REST routes. The spec is generated lazily on the first request to /api-docs, so every route registered during boot is included.
ts
// config/openapi.ts
export default {
title: 'My API',
version: '1.0.0',
// docsPath: '/docs', // Swagger UI (default)
// specPath: '/api-docs', // raw JSON spec (default)
// enabled: true, // default: on, except in production
// guards: ['web'], // who may read it
// middleware: ['admin'], // named middleware, or functions
}GET /docs→ Swagger UI (HTML)GET /api-docs→ the OpenAPI 3.1 JSON spec
The spec is derived from registered routes + Rune validators + guard metadata (401/403 responses are inferred from @Guard/@Role/@Permission). Route versioning (route.version(), route.deprecates()) is reflected in the spec.
OpenAPI is documentation, not an API style. It describes your REST routes; JSON-RPC and GraphQL are alternative call styles.
The spec is generated once and cached after the first request. Routes added after that first hit (e.g. dev hot-reload) won't appear until restart.
Who can read it
The document is an inventory of your API. It lists every route, internal and admin ones included, the guards each one needs, the controller class and method behind it, and the field-by-field schema of every validated body. Do not serve it to everybody unless your API is public.
- Production. The two routes are not mounted when
NODE_ENVisproduction. Setenabled: trueto serve them there, and protect them. - Guards and middleware.
/api-docsand/docsare ordinary routes. Your server middleware (start/kernel.ts) runs before them, like for any route.guardsputs.guard(...)on both routes;middlewareadds named middleware ('admin') or middleware functions. - Turn it off.
enabled: falsemounts nothing.
ts
// config/openapi.ts
export default {
enabled: true,
guards: ['web'],
middleware: ['admin'],
}guards: [] is refused with E_EMPTY_GATE_REQUIREMENT: leave the key out for no guard.