Skip to content

OpenAPI 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

Add authentication schemes to your API:

import { YelixHono } from '@yelix/hono';
const app = new YelixHono();
// Bearer Token Authentication
app.__openapi.addSecuritySchema('Bearer', {
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT',
description: 'Bearer token for authenticating requests',
});
// API Key Authentication
app.__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
app.__openapi.addSecuritySchema('Bearer', {
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT',
description: 'JWT Bearer token authentication',
});
app.__openapi.addSecuritySchema('ApiKey', {
type: 'apiKey',
in: 'header',
name: 'X-API-Key',
description: 'API key authentication',
});
app.__openapi.addSecuritySchema('ApiKeyQuery', {
type: 'apiKey',
in: 'query',
name: 'api_key',
description: 'API key in query parameter',
});