OpenAPI Configuration
Server Configuration
Section titled “Server Configuration”Define the servers where your API is hosted:
import { YelixHono } from '@yelix/hono';
const app = new YelixHono();
app.__openapi.setServers([ { url: 'http://localhost:8000', description: 'Local Server', }, { url: 'https://api.example.com', description: 'Production Server', },]);What this does:
- Defines multiple server environments (development, production, etc.)
- Allows API consumers to switch between servers in the documentation
- Each server has a URL and human-readable description
Security Schemas
Section titled “Security Schemas”Add authentication schemes to your API:
import { YelixHono } from '@yelix/hono';
const app = new YelixHono();
// Bearer Token Authenticationapp.__openapi.addSecuritySchema('Bearer', { type: 'http', scheme: 'bearer', bearerFormat: 'JWT', description: 'Bearer token for authenticating requests',});
// API Key Authenticationapp.__openapi.addSecuritySchema('ApiKey', { type: 'apiKey', in: 'header', name: 'X-API-Key', description: 'API key for authenticating requests',});What this does:
- Defines security schemas that can be used across your API
- Specifies authentication methods (Bearer tokens, API keys, etc.)
- Documents how authentication should work for protected endpoints
- These schemas can be referenced in individual route configurations
Common Security Types
Section titled “Common Security Types”Bearer Token (JWT)
Section titled “Bearer Token (JWT)”app.__openapi.addSecuritySchema('Bearer', { type: 'http', scheme: 'bearer', bearerFormat: 'JWT', description: 'JWT Bearer token authentication',});API Key in Header
Section titled “API Key in Header”app.__openapi.addSecuritySchema('ApiKey', { type: 'apiKey', in: 'header', name: 'X-API-Key', description: 'API key authentication',});API Key in Query
Section titled “API Key in Query”app.__openapi.addSecuritySchema('ApiKeyQuery', { type: 'apiKey', in: 'query', name: 'api_key', description: 'API key in query parameter',});Next Steps
Section titled “Next Steps”- Learn how to Document Your Endpoints
- See Complete Examples