express-swagger-autogen
Version:
A library that auto generates swagger docs to your endpoints from express.
32 lines (31 loc) • 1.95 kB
TypeScript
import "reflect-metadata";
import { Router } from "express";
import { StatusCodes } from "http-status-codes";
import type { OpenAPI3 } from "openapi-typescript";
import { ExpressSwaggerAutogenValidationError } from "./errors";
import { HandlerDocumentation } from "./utils";
export { Documentation } from "./decorator";
export type ExpressSwaggerAutogenDocsOptions = {
setup?: Partial<OpenAPI3>;
basePath?: string;
endpoint?: string;
validatePaths?: boolean;
disableLogger?: boolean;
deprecateNotFoundPaths?: boolean;
includeCustomQueryParams?: boolean;
};
/**
* Generates Swagger documentation for an Express application.
*
* @param {Router} router - The Express Router instance.
* @param {ExpressSwaggerAutogenDocsOptions} [options] - Optional configuration options.
* @param {Partial<OpenAPI3>} [options.setup] - Custom OpenAPI3 setup for Swagger UI.
* @param {string} [options.basePath] - Base path to prepend to all endpoints.
* @param {string} [options.endpoint] - The endpoint where the Swagger UI will be served. Defaults to "/documentation".
* @param {boolean} [options.validatePaths] - Whether to validate the paths defined manually in options.setup against the actual endpoints in the router. If true, it will throw an error if any path or method does not exist in the router endpoints. If false it will just warn in console.
* @param {boolean} [options.disableLogger] - Whether to disable the logger. Defaults to false.
* @param {boolean} [options.deprecateNotFoundPaths] - Whether to deprecate paths that are not found in the router. Defaults to true.
* @param {boolean} [options.includeCustomQueryParams] - Whether to include custom query parameters in the documentation. Defaults to false.
*/
export default function expressSwaggerAutogen(router: Router, options?: ExpressSwaggerAutogenDocsOptions): void;
export { ExpressSwaggerAutogenValidationError, HandlerDocumentation, StatusCodes };