Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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.');
}
}