How to use the swagger-ui-express.serveFiles function in swagger-ui-express

To help you get started, we’ve selected a few swagger-ui-express examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eropple / nestjs-openapi3 / src / openapi.module.ts View on Github external
private static serveSwagger(
    document: O3TS.OpenAPIObject,
    apiDocsPath: string,
    logger: BunyanLike,
    app: INestApplication,
    httpAdapter: HttpServer,
  ) {
    try {
      // tslint:disable-next-line: no-require-imports
      const swaggerUi = require('swagger-ui-express');

      const html = swaggerUi.generateHTML(document, {});

      app.use(apiDocsPath, swaggerUi.serveFiles(document, {}));
      httpAdapter.get(apiDocsPath, (req, res) => res.contentType('html').send(html));

    } catch (err) {
      logger.warn({ err }, 'Error when loading `swagger-ui-express`. Make sure you have it in your package.json.');
    }
  }
github egodigital / swagger-jsdoc-express / src / index.ts View on Github external
favIcon = null;
    }

    let url = toStringSafe(opts.url);
    if (isEmptyString(url)) {
        url = null;
    }

    let title = toStringSafe(opts.title);
    if (isEmptyString(title)) {
        title = null;
    }

    const ROUTER = express.Router();

    ROUTER.use('/', swaggerUi.serveFiles(SWAGGER_DOC));
    ROUTER.get('/', swaggerUi.setup(
        SWAGGER_DOC,
        null,  // opts
        null,  // options
        css,  // customCss
        favIcon,  // customfavIcon
        url,  // swaggerUrl
        title,  // customeSiteTitle
    ));

    // download link (JSON)
    ROUTER.get(`/json`, function (req, res) {
        return res.status(200)
            .header('content-type', 'application/json; charset=utf-8')
            .header('content-disposition', `attachment; filename=api.json`)
            .send(

swagger-ui-express

Swagger UI Express

MIT
Latest version published 10 months ago

Package Health Score

77 / 100
Full package analysis