Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}).then(function(body) {
var obj = getObj(body,payload);
var globalOptions = options = {};
options.origin = true;
options.source = req.query.url;
options.patch = true;
options.resolve = true;
try {
converter.convert(obj,options,async function(err,options){
if (err) {
result.error = err.message;
result.options = sanitise(globalOptions);
}
else result = options.openapi;
if (req.query.validate && options.openapi) {
status.validations++;
try {
result = {};
result.status = await validator.validateSync(options.openapi,options);
}
catch (ex) {
result.status = false; // reset
if (options.context) {
result.context = options.context.pop();
}
var body = (req.body ? req.body.source : '')||(req.file ? req.file.buffer.toString() : '');
var validate = (req.body && req.body.validate); // on or undefined
var payload = parseRequest(req);
if (req.headers['content-type'].startsWith('application/x-www-form-urlencoded')) {
result.warning = `Your client sent the wrong Content-Type header (${req.headers['content-type']}). Try pasting your document`;
payload.status = 400;
if (!req.body.source && !req.file) payload.status = 200; // Dredd
}
var obj = getObj(body,payload);
var options = {};
options.patch = true;
options.resolve = false;
try {
converter.convert(obj,options,async function(err,options){
if (err) {
result.message = err.message||'no message';
result.options = sanitise(result.options);
}
else {
result = options.openapi;
if (options.openapi && options.openapi.openapi && options.openapi.openapi.startsWith('3.')) payload.status = 200;
}
if (validate && !err) {
status.validations++;
try {
result = {};
result.status = await validator.validateSync(options.openapi,options);
if (result.status === true) payload.status = 200;
}
catch (ex) {
this.converters.openapi_3 = Promise.method(swagger => swagger2openapi.convert(swagger.spec,{direct:true,patch:true}));
}