import swaggerJsdoc from 'swagger-jsdoc';
import swaggerUi from 'swagger-ui-express';
import { Application } from 'express';
const options = {
definition: {
openapi: '3.0.0',
info: {
title: 'MCP Node API',
version: '1.0.0',
description: 'A Node.js API with TypeScript, TypeORM, and MongoDB following layered architecture',
contact: {
name: 'API Support',
},
},
servers: [
{
url: 'http://localhost:3000',
description: 'Development server',
},
],
components: {
schemas: {
User: {
type: 'object',
properties: {
id: {
type: 'string',
},
email: {
type: 'string',
format: 'email',
},
name: {
type: 'string',
},
pictureUrl: {
type: 'string',
},
createdAt: {
type: 'string',
format: 'date-time',
},
updatedAt: {
type: 'string',
format: 'date-time',
},
},
},
Product: {
type: 'object',
properties: {
id: {
type: 'string',
},
name: {
type: 'string',
},
description: {
type: 'string',
},
pictureUrl: {
type: 'string',
},
unitPrice: {
type: 'number',
},
quantity: {
type: 'number',
},
measureType: {
type: 'string',
},
attributes: {
type: 'object',
additionalProperties: true,
},
createdAt: {
type: 'string',
format: 'date-time',
},
updatedAt: {
type: 'string',
format: 'date-time',
},
},
},
},
},
},
apis: [
'./src/features/*/controllers/*.ts',
'./src/features/*/routes/*.ts',
'./src/features/*/dtos/*.ts',
],
};
const swaggerSpec = swaggerJsdoc(options);
export const setupSwagger = (app: Application): void => {
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
console.log('📚 Swagger documentation available at http://localhost:3000/api-docs');
};