added check for https, changed behaviour of callback back to err throwing in convert function

This commit is contained in:
Dhroov7
2019-12-09 18:48:40 +05:30
parent e12a1afed7
commit 5deb2c9e0f
3 changed files with 28 additions and 34 deletions

View File

@@ -40,17 +40,10 @@ module.exports = {
.then((spec) => {
converter.convert(spec, options, (err, result) => {
if (err) {
return callback(null, {
result: false,
reason: err
});
return callback(err);
}
// eslint-disable-next-line no-else-return
else {
convertedSpecs.push(result);
return callback(null);
}
convertedSpecs.push(result);
return callback(null);
});
})
.catch((err) => {
@@ -59,7 +52,14 @@ module.exports = {
reason: err
});
});
}, () => {
}, (err) => {
if (err) {
return cb({
result: false,
reason: 'input type:' + input.type + ' is not valid'
});
}
var conversionResult = false,
convertedCollections = [],
@@ -73,6 +73,7 @@ module.exports = {
else {
conversionResult = convertedSpec.result;
reasonForFail = convertedSpec.reason;
return false; // it will break out from the loop
}
});
@@ -116,8 +117,7 @@ module.exports = {
else if (input.type === 'folder') {
if (!_.isEmpty(parse.getRootFiles(input.data))) {
return {
result: true,
reason: 'valid input type'
result: true
};
}
}

View File

@@ -273,10 +273,7 @@ module.exports = {
}
else {
// Unhandled exception, rethrow
callback(null, {
result: false,
reason: e.message
});
callback(e);
}
}
},

View File

@@ -102,25 +102,22 @@ module.exports = {
getOasObject: function (file) {
let oasObj = file;
if (typeof oasObj === 'string') {
try {
oasObj = JSON.parse(oasObj);
}
catch (jsonEx) {
// Not direct JSON. Could be YAML
try {
oasObj = JSON.parse(oasObj);
oasObj = yaml.safeLoad(oasObj);
}
catch (jsonEx) {
// Not direct JSON. Could be YAML
try {
oasObj = yaml.safeLoad(oasObj);
}
catch (yamlEx) {
// Not JSON or YAML
return {
result: false,
reason: 'The input must be valid JSON or YAML'
};
}
// valid YAML
catch (yamlEx) {
// Not JSON or YAML
return {
result: false,
reason: 'The input must be valid JSON or YAML'
};
}
// valid YAML
}
return oasObj;
@@ -187,7 +184,7 @@ module.exports = {
},
readSpecFile: function (file) {
if (file && file.startsWith('http')) {
if (file.startsWith('http') || file.startsWith('https')) {
// remote file
return fetch(file).then((res) => {
if (res.status !== 200) {