Add Authentication (Optional)
You can easily define global security schemes (like Bearer Tokens, API Keys, or Cookies) in your openapi.config.ts, and then protect specific routes using the @security JSDoc tag!
1. Update openapi.config.ts
typescript
export default {
// ...
securitySchemes: {
BearerAuth: {
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT'
},
CookieAuth: {
type: 'apiKey',
in: 'cookie',
name: 'session_id'
}
}
};2. Protecting a Route
typescript
/**
* @summary Fetch user profile
* @security [{"BearerAuth": []}]
*/
app.get('/profile', (c) => {
// ...
});