How to use the swagger-ui-express.generateHTML 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.');
    }
  }

swagger-ui-express

Swagger UI Express

MIT
Latest version published 5 months ago

Package Health Score

80 / 100
Full package analysis