UNPKG

3.64 kBTypeScriptView Raw
1import { RequestHandler } from "express";
2import { ServeStaticOptions } from "serve-static";
3
4export interface JsonObject {
5 [key: string]: any;
6}
7
8export interface SwaggerOptions {
9 [key: string]: any;
10}
11
12export interface SwaggerUiOptions {
13 customCss?: string | undefined;
14 customCssUrl?: string | undefined;
15 customfavIcon?: string | undefined;
16 customJs?: string | undefined;
17 customSiteTitle?: string | undefined;
18 explorer?: boolean | undefined;
19 isExplorer?: boolean | undefined;
20 swaggerOptions?: SwaggerOptions | undefined;
21 swaggerUrl?: string | undefined;
22 swaggerUrls?: string[] | undefined;
23}
24
25/**
26 * Creates a middleware function that returns the pre-generated HTML file for the Swagger UI page.
27 *
28 * @param swaggerDoc JSON object with the API schema.
29 * @param opts swagger-ui-express options.
30 * @param options custom Swagger options.
31 * @param customCss string with a custom CSS to embed into the page.
32 * @param customfavIcon link to a custom favicon.
33 * @param swaggerUrl URL of the Swagger API schema, can be specified instead of the swaggerDoc.
34 * @param customSiteTitle custom title for a page.
35 * @returns an express middleware function that returns the generated HTML page.
36 */
37export function setup(
38 swaggerDoc?: JsonObject,
39 opts?: SwaggerUiOptions,
40 options?: SwaggerOptions,
41 customCss?: string,
42 customfavIcon?: string,
43 swaggerUrl?: string,
44 customSiteTitle?: string,
45): RequestHandler;
46
47/** @deprecated */
48export function setup(swaggerDoc?: JsonObject, isExplorer?: boolean): RequestHandler;
49
50/**
51 * Returns handlers for serving Swagger UI files.
52 * This includes the custom initialization JS file and static files of Swagger UI.
53 *
54 * @returns Express handlers that process requests and return files for Swagger UI.
55 */
56export const serve: RequestHandler[];
57
58/**
59 * Returns handlers for serving Swagger UI files.
60 * This includes custom initialization js file and static files of Swagger UI.
61 * Additional options are passed to the `express.static` middleware.
62 *
63 * @param options options object that is passed to the `express.static` middleware.
64 * @returns Express handlers that process requests and return files for Swagger UI.
65 */
66export function serveWithOptions(options: ServeStaticOptions): RequestHandler[];
67
68/**
69 * Generates the custom HTML page for the UI API.
70 *
71 * @param swaggerDoc JSON object with the API schema.
72 * @param opts swagger-ui-express options.
73 * @param options custom Swagger options.
74 * @param customCss string with a custom CSS to embed into the page.
75 * @param customfavIcon link to a custom favicon.
76 * @param swaggerUrl URL of the Swagger API schema, can be specified instead of the swaggerDoc.
77 * @param customSiteTitle custom title for a page.
78 * @returns the generated HTML page.
79 */
80export function generateHTML(
81 swaggerDoc?: JsonObject,
82 opts?: SwaggerUiOptions,
83 options?: SwaggerOptions,
84 customCss?: string,
85 customfavIcon?: string,
86 swaggerUrl?: string,
87 customSiteTitle?: string,
88): string;
89
90/** @deprecated */
91export function generateHTML(swaggerDoc?: JsonObject, isExplorer?: boolean): RequestHandler;
92
93/**
94 * Returns handlers for serving Swagger UI files.
95 * This includes custom initialization js file and static files of Swagger UI.
96 * Additional options object is passed to Swagger UI.
97 *
98 * @param swaggerDoc JSON object with the Swagger API schema.
99 * @param opts options to pass to Swagger UI.
100 * @returns Express handlers that process requests and return files for Swagger UI.
101 */
102export function serveFiles(swaggerDoc?: JsonObject, opts?: SwaggerUiOptions): RequestHandler[];