Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (this.validate) {
// validate the document
this.validateDefinition();
}
} catch (err) {
if (this.strict) {
// in strict-mode, fail hard and re-throw the error
throw err;
} else {
// just emit a warning about the validation errors
console.warn(err);
}
}
// dereference the document into definition
this.definition = dereference(this.inputDocument);
// create axios instance
this.instance = this.createAxiosInstance();
// we are now initalized
this.initalized = true;
return this.instance as Client;
};
function derefJsonSchema(jsonSchemaWithRefs) {
let jsonSchema;
// In case there are errors with `deref`, which can happen with circular $refs
try {
jsonSchema = deref(jsonSchemaWithRefs);
} catch(error) {
jsonSchema = jsonSchemaWithRefs;
}
return jsonSchema;
}
export function compile(document: Document): Compiled {
// get the de-referenced version of the swagger document
const swagger = deref(document);
// add a validator for every parameter in swagger document
Object.keys(swagger.paths).forEach(pathName => {
const path = swagger.paths[pathName];
Object.keys(path)
.filter(name => name !== 'parameters')
.forEach(operationName => {
const operation = path[operationName];
const parameters: any = {};
const resolveParameter = (parameter: any) => {
parameters[`${parameter.name}:${parameter.location}`] = parameter;
};
// start with parameters at path level
(path.parameters || []).forEach(resolveParameter);