import swaggerJsdoc from 'swagger-jsdoc';
import swaggerUi from 'swagger-ui-express';
import { Express } from 'express';
import { config } from '../config/index.js';
import logger from '../utils/logger.js';
// Swagger definition
const swaggerOptions = {
definition: {
openapi: '3.0.0',
info: {
title: 'Frontapp MCP API',
version: '1.0.0',
description: 'API documentation for the Frontapp MCP integration',
contact: {
name: 'API Support',
email: 'support@example.com',
},
},
servers: [
{
url: `http://localhost:${config.server.port}`,
description: 'Development server',
},
{
url: config.webhook.baseUrl || 'https://api.example.com',
description: 'Production server',
},
],
components: {
securitySchemes: {
ApiKeyAuth: {
type: 'apiKey',
in: 'header',
name: 'X-API-Key',
},
},
},
security: [
{
ApiKeyAuth: [],
},
],
},
apis: ['./src/api/*.ts', './src/models/*.ts'], // Path to the API docs
};
// Initialize swagger-jsdoc
const swaggerSpec = swaggerJsdoc(swaggerOptions);
/**
* Configure Swagger UI
* @param app Express application
*/
export function setupSwagger(app: Express): void {
// Serve swagger docs
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
// Serve swagger spec as JSON
app.get('/api-docs.json', (req, res) => {
res.setHeader('Content-Type', 'application/json');
res.send(swaggerSpec);
});
logger.info('Swagger documentation initialized', {
url: `http://localhost:${config.server.port}/api-docs`,
});
}
export default swaggerSpec;