Adonis Open Swagger

Basic

Basic Configuration

You can edit config/swagger.ts to customize your API documentation.

config/swagger.ts
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.

namedescription
vinejsUse VineJS for schema validation. VineJS Docs
typeboxUse TypeBox for schema validation. TypeBox Docs
zodUse Zod for schema validation. Zod Docs

info

OpenAPI specification information.

namedescription
titleTitle of the API
versionVersion of the API
descriptionDescription of the API
contactContact information for the API
licenseLicense information for the API

servers

Servers configuration.

namedescription
urlURL of the server
descriptionDescription 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):

config/swagger.ts
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.

TypeDescription
apiKeyAPI key in header, query, or cookie
httpHTTP authentication (bearer, basic)
oauth2OAuth 2.0 authentication flows
openIdConnectOpenID 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