@davaux/swagger
v0.9.0
Published
Auto-generated OpenAPI/Swagger documentation for Davaux APIs
Readme
@davaux/swagger
Auto-generated OpenAPI/Swagger documentation for Davaux APIs.
Installation
npm install @davaux/swaggerSetup
Mount as middleware in a route file or middleware:
// src/routes/api/_middleware.ts
import { swagger } from '@davaux/swagger'
export default swagger({
routesDir: './dist/routes',
info: { title: 'My API', version: '1.0.0' },
})This serves:
/docs— Swagger UI/openapi.json— raw OpenAPI 3.0 spec
Options
| Option | Type | Default | Description |
|---|---|---|---|
| routesDir | string | — | Directory of compiled route files to introspect (required) |
| info.title | string | 'API' | API title |
| info.version | string | '1.0.0' | API version |
| info.description | string | — | API description |
| path | string | '/docs' | URL path for the Swagger UI page |
| specPath | string | '/openapi.json' | URL path for the raw OpenAPI JSON |
Automatic request body documentation
When zod-to-json-schema is installed, mutating routes that export a *Schema named export have their request body documented automatically:
// src/routes/api/users.post.ts
import { z } from 'zod'
export const userSchema = z.object({
name: z.string(),
email: z.string().email(),
})
export default defineHandler(async (ctx) => { ... })Notes
- The spec is generated once on the first request and cached for the process lifetime
pageroutes (HTML pages) are excluded; only API handler files appear in the spec- In single-site dev, point
routesDirat.davaux/routes— the dev server's compiled output. For@davaux/multisitedev, use.davaux-multisite/routes
