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.');
}
}
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(