Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public initialize(visitor: OpenAPIFrameworkVisitor) {
const securitySchemes = (this.apiDoc as OpenAPIV3.Document).openapi
? (this.apiDoc.components || {}).securitySchemes
: this.apiDoc.securityDefinitions;
const apiSecurityMiddleware =
this.securityHandlers && this.apiDoc.security && securitySchemes
? new OpenAPISecurityHandler({
securityDefinitions: securitySchemes,
securityHandlers: this.securityHandlers,
operationSecurity: this.apiDoc.security,
loggingKey: `${this.name}-security`
})
: null;
let paths = [];
let routes = [];
const routesCheckMap = {};
if (this.paths) {
paths = [].concat(this.paths);
this.logger.debug(`${this.loggingPrefix}paths=`, paths);
paths.forEach(pathItem => {
if (byString(pathItem)) {
let securityDefinition;
if (this.securityHandlers && securitySchemes) {
if (operationDoc.security) {
securityDefinition = operationDoc.security;
} else if (this.pathSecurity.length) {
securityDefinition = getSecurityDefinitionByPath(
openapiPath,
this.pathSecurity
);
}
}
if (securityDefinition) {
pathDoc[methodName].security = securityDefinition;
securityFeature = new OpenAPISecurityHandler({
securityDefinitions: securitySchemes,
securityHandlers: this.securityHandlers,
operationSecurity: securityDefinition,
loggingKey: `${this.name}-security`
});
} else if (apiSecurityMiddleware) {
securityFeature = apiSecurityMiddleware;
}
if (securityFeature) {
operationContext.features.securityHandler = securityFeature;
}
}
}
if (visitor.visitOperation) {