mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
added check for https, changed behaviour of callback back to err throwing in convert function
This commit is contained in:
26
index.js
26
index.js
@@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,10 +273,7 @@ module.exports = {
|
||||
}
|
||||
else {
|
||||
// Unhandled exception, rethrow
|
||||
callback(null, {
|
||||
result: false,
|
||||
reason: e.message
|
||||
});
|
||||
callback(e);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
31
lib/parse.js
31
lib/parse.js
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user