Basic
Basic Configuration
You can edit config/swagger.ts to customize your API documentation.
import { defineConfig } from "adonis-open-swagger";
/**
* Configuration for Open Swagger
*/
export default defineConfig({
/**
* Enable or disable swagger documentation
*/
enabled: true,
/**
* Path where the documentation will be served
*/
path: "/docs",
/**
* Schema validator to use for automatic schema conversion
* Choose based on your preferred validation library
*/
validator: "vinejs", // 'vinejs' | 'zod' | 'typebox'
/**
* OpenAPI specification information
*/
info: {
title: "VoiceOps",
version: "1.0.0",
description: "API documentation for VoiceOPS",
contact: {
name: "API Support",
email: "support@example.com",
},
license: {
name: "MIT",
url: "https://opensource.org/licenses/MIT",
},
},
/**
* Servers configuration
*/
servers: [
{
url: "http://localhost:3333",
description: "Development server",
},
],
});Options
enabled
Enable or disable swagger documentation.
path
Path where the documentation will be served. Example: /docs
validator
Schema validator to use for automatic schema conversion.
| name | description |
|---|---|
vinejs | Use VineJS for schema validation. VineJS Docs |
typebox | Use TypeBox for schema validation. TypeBox Docs |
zod | Use Zod for schema validation. Zod Docs |
info
OpenAPI specification information.
| name | description |
|---|---|
title | Title of the API |
version | Version of the API |
description | Description of the API |
contact | Contact information for the API |
license | License information for the API |
servers
Servers configuration.
| name | description |
|---|---|
url | URL of the server |
description | Description of the server |
Security Schemes
Open Swagger supports all OpenAPI 3.0 security schemes including Cookie Authentication (useful for session-based auth like Better-Auth):
export default defineConfig({
// ... other config
securitySchemes: {
// Cookie Authentication (for session-based auth)
cookieAuth: {
type: "apiKey",
in: "cookie",
name: "session", // or 'JSESSIONID', 'auth_token', etc.
description: "Session cookie for authentication",
},
// Bearer Token (JWT) Authentication
bearerAuth: {
type: "http",
scheme: "bearer",
bearerFormat: "JWT",
description: "Enter your JWT token",
},
// API Key in Header
apiKeyAuth: {
type: "apiKey",
in: "header",
name: "X-API-Key",
description: "API key passed in header",
},
// Basic Authentication
basicAuth: {
type: "http",
scheme: "basic",
description: "Basic HTTP authentication",
},
// OAuth2 Authentication
oauth2Auth: {
type: "oauth2",
description: "OAuth2 authentication",
flows: {
authorizationCode: {
authorizationUrl: "https://example.com/oauth/authorize",
tokenUrl: "https://example.com/oauth/token",
scopes: {
"read:users": "Read user information",
"write:users": "Modify user information",
},
},
},
},
},
// Global security (applied to all endpoints)
security: [
{ cookieAuth: [] },
// { bearerAuth: [] },
],
});securitySchemes
Define authentication methods available for your API.
| Type | Description |
|---|---|
apiKey | API key in header, query, or cookie |
http | HTTP authentication (bearer, basic) |
oauth2 | OAuth 2.0 authentication flows |
openIdConnect | OpenID Connect Discovery |
security
Global security requirements applied to all endpoints. Can be overridden per-endpoint using the @SwaggerSecurity decorator.
Use @SwaggerSecurity([]) on specific endpoints to make them public (no
authentication required).
Last updated on