config/swagger.js

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const swagger_jsdoc_1 = __importDefault(require("swagger-jsdoc"));
/**
 * @namespace config
 * @description Configuration for Swagger documentation generation using swagger-jsdoc.
 */
/**
 * Swagger configuration options for generating the OpenAPI documentation.
 * Defines metadata, servers, and paths for the API documentation.
 *
 * @memberof config
 * @constant {swaggerJsdoc.Options}
 * @property {object} definition - OpenAPI specification details.
 * @property {string} definition.openapi - Specifies the OpenAPI version.
 * @property {object} definition.info - Contains metadata about the API.
 * @property {string} definition.info.title - Title of the API documentation.
 * @property {string} definition.info.version - Version of the API.
 * @property {string} definition.info.description - A short description of the API.
 * @property {string} definition.host - The host URL for the API.
 * @property {Array<object>} definition.servers - List of server objects for API interaction.
 * @property {string} apis - Glob pattern to locate route files for Swagger documentation.
 * @example
 * const swaggerOptions = {
 *   definition: {
 *     openapi: '3.0.0',
 *     info: {
 *       title: 'My API',
 *       version: '1.0.0',
 *       description: 'API documentation',
 *     },
 *     servers: [{ url: 'http://localhost:5000' }],
 *   },
 *   apis: ['./src/routes/*.ts'],
 * };
 */
const swaggerOptions = {
    definition: {
        openapi: '3.0.0',
        info: {
            title: 'Express API with TypeScript',
            version: '1.0.0',
            description: 'A simple Express API with autogenerated Swagger documentation',
        },
        host: 'localhost:5000',
        servers: [
            {
                url: 'http://localhost:5000', // Replace with your base URL
            },
        ],
    },
    apis: ['./src/routes/*.ts'], // Path to your route files
};
/**
 * Generates the Swagger specification using the provided options.
 * This specification can be used to configure Swagger-UI or similar tools.
 *
 * @memberof config
 * @constant {object}
 * @property {object} paths - Contains the paths and endpoints documented in your API.
 * @property {object} components - Holds reusable components such as schemas or responses.
 * @example
 * import swaggerSpec from './swaggerConfig';
 * app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
 */
const swaggerSpec = (0, swagger_jsdoc_1.default)(swaggerOptions);
exports.default = swaggerSpec;