removed speccy and using oas-resolver

This commit is contained in:
Dhroov7
2019-12-06 14:06:58 +05:30
parent abc948d8d4
commit cf53c1c209
4 changed files with 93 additions and 1222 deletions

View File

@@ -2,7 +2,6 @@ var converter = require('./lib/convert.js'),
validate = require('./lib/validate.js'),
parse = require('./lib/parse.js'),
async = require('async'),
loader = require('speccy/lib/loader'),
_ = require('lodash'),
fs = require('fs');
@@ -35,7 +34,7 @@ module.exports = {
rootFiles = parse.getRootFiles(filesPathArray);
async.eachSeries(rootFiles, (rootFile, callback) => {
loader
parse
// will merge all the files in the folder
.loadSpec(rootFile, loaderOptions)
.then((spec) => {

View File

@@ -1,5 +1,8 @@
var yaml = require('js-yaml'),
fs = require('fs');
fetch = require('node-fetch'),
fs = require('fs'),
resolver = require('oas-resolver'),
yamlParse = require('yaml');
module.exports = {
@@ -136,5 +139,69 @@ module.exports = {
});
return rootFilesArray;
},
resolveContent: function (openapi, options) {
return resolver.resolve(openapi, options.source, {
options: Object.assign({}, options),
resolve: true,
cache: [],
externals: [],
externalRefs: {},
rewriteRefs: true,
openapi: openapi
});
},
loadSpec: function(source, options = {}) {
options.source = source;
options.origin = source;
return this.readSpecFile(source)
.then((content) => {
try {
return yamlParse.parse(content, { prettyErrors: true });
}
catch (err) {
throw new ReadError('\nLine: ' + err.linePos.start.line + ', col: ' +
err.linePos.start.col + ' ' + err.message);
}
}, (err) => {
throw new OpenError(err.message);
})
.then((unresolved) => {
if (options.resolve === true) {
return this.resolveContent(unresolved, options);
}
}, (err) => {
throw err;
})
.then((result) => {
return result.openapi;
}, (err) => {
throw err;
});
},
readSpecFile: function (file) {
if (file && file.startsWith('http')) {
// remote file
return fetch(file).then((res) => {
if (res.status !== 200) {
return `Received status code ${res.status}`;
}
return res.text();
});
}
return this.readFileAsync(file, 'utf8');
},
readFileAsync: function(filename, encoding) {
return new Promise((resolve, reject) => {
fs.readFile(filename, encoding, (err, data) => {
if (err) { reject(err); }
else { resolve(data); }
});
});
}
};

1227
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -120,8 +120,8 @@
"commander": "2.3.0",
"js-yaml": "3.13.1",
"lodash": "4.17.13",
"postman-collection": "3.5.1",
"speccy": "0.11.0"
"oas-resolver": "2.2.5",
"postman-collection": "3.5.1"
},
"author": "Postman Labs <help@getpostman.com>",
"license": "Apache-2.0",