Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const securityFilter =
args.securityFilter ||
function defaultSecurityFilter(ctx, next) {
ctx.status = 200;
ctx.body = ctx.state.apiDoc;
};
const frameworkArgs: OpenAPIFrameworkConstructorArgs = {
apiDoc: args.apiDoc,
featureType: 'middleware',
name: loggingPrefix,
paths: args.paths,
...(args as OpenAPIFrameworkArgs)
};
const framework = new OpenAPIFramework(frameworkArgs);
framework.initialize({
visitApi(apiCtx: OpenAPIFrameworkAPIContext) {
const basePaths = apiCtx.basePaths.map(toKoaBasePath);
for (const basePath of basePaths) {
if (exposeApiDocs) {
// Swagger UI support
router.get(basePath + docsPath, (ctx: Context, next) => {
ctx.state.apiDoc = apiCtx.getApiDoc();
if (ctx.state.apiDoc.swagger) {
ctx.state.apiDoc.host = ctx.headers.host;
ctx.state.apiDoc.basePath =
basePath.length === 0 ? '/' : basePath;
}
securityFilter(ctx, next);
});
const promiseMode = !!args.promiseMode;
const securityFilter = args.securityFilter
? args.promiseMode
? toPromiseCompatibleMiddleware(args.securityFilter)
: args.securityFilter
: function defaultSecurityFilter(req, res, next) {
res.status(200).json(req.apiDoc);
};
const frameworkArgs: OpenAPIFrameworkConstructorArgs = {
featureType: 'middleware',
name: loggingPrefix,
...(args as OpenAPIFrameworkArgs)
};
const framework = new OpenAPIFramework(frameworkArgs);
framework.initialize({
visitApi: ctx => {
if (exposeApiDocs || errorMiddleware) {
const basePaths = [];
basePaths.push(...ctx.basePaths.map(toExpressBasePath));
for (const basePath of basePaths) {
// Swagger UI support
if (exposeApiDocs) {
app.get(basePath + docsPath, (req, res, next) => {
// @ts-ignore
req.apiDoc = ctx.getApiDoc();
// @ts-ignore
if (req.apiDoc.swagger) {
// @ts-ignore