Volt v0.1 · TypeScript APIs on Bun · Get started
Docs/API Reference/OpenAPI & Swagger UI

OpenAPI & Swagger UI

Generate request schemas and document response metadata.

Complete OpenAPI example

index.ts
import { Volt, openapi, t } from 'voltts';

const app = new Volt();
app.use(openapi({
  info: { title: 'Tasks API', version: '1.0.0' },
  path: '/docs',
  swaggerPath: '/swagger',
  specPath: '/openapi.json',
  ui: 'both',
  openapiVersion: '3.1.0',
}));
app.post('/tasks', (c) => c.json(c.body, 201), {
  summary: 'Create a task',
  tags: ['Tasks'],
  body: t.Object({ title: t.String({ minLength: 2 }) }),
  response: { 201: t.Object({ title: t.String() }) },
});
if (globalThis._importMeta_.main) app.listen(3000);
export default app;

Open the reference

Run bun run index.ts. Open http://localhost:3000/docs for Scalar, http://localhost:3000/swagger for Swagger UI, or http://localhost:3000/openapi.json for the specification.

Options and metadata

The default specification version is 3.0.3. Set openapiVersion: '3.1.0' explicitly for 3.1. ui accepts scalar, swagger, or both. Route metadata includes summary, description, tags, response, and security. A security declaration describes your API; you must still enforce authentication in handlers or middleware.

Response contract

Response schemas describe the contract in generated documentation. They do not currently validate or filter returned objects. Return the exact public fields yourself to avoid leaking database fields. Interactive UIs load third-party assets from CDNs and need network access.