mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
some changes
This commit is contained in:
6
index.js
6
index.js
@@ -5,8 +5,8 @@ var converter = require('./lib/convert.js'),
|
||||
_ = require('lodash'),
|
||||
fs = require('fs');
|
||||
|
||||
// options for speccy loader
|
||||
const loaderOptions = {
|
||||
// options for oas-resolver
|
||||
const OasResolverOptions = {
|
||||
resolve: true, // Resolve external references
|
||||
jsonSchema: true // Treat $ref like JSON Schema and convert to OpenAPI Schema Objects
|
||||
};
|
||||
@@ -36,7 +36,7 @@ module.exports = {
|
||||
async.eachSeries(rootFiles, (rootFile, callback) => {
|
||||
parse
|
||||
// will merge all the files in the folder
|
||||
.loadSpec(rootFile, loaderOptions)
|
||||
.loadSpec(rootFile, OasResolverOptions)
|
||||
.then((spec) => {
|
||||
converter.convert(spec, options, (err, result) => {
|
||||
if (err) {
|
||||
|
||||
14
lib/parse.js
14
lib/parse.js
@@ -130,14 +130,18 @@ module.exports = {
|
||||
let rootFilesArray = [];
|
||||
|
||||
filesPathArray.forEach((filePath) => {
|
||||
let file = fs.readFileSync(filePath.fileName, 'utf8'),
|
||||
oasObject = this.getOasObject(file);
|
||||
try {
|
||||
let file = fs.readFileSync(filePath.fileName, 'utf8'),
|
||||
oasObject = this.getOasObject(file);
|
||||
|
||||
if (this.validateRoot(oasObject).result) {
|
||||
rootFilesArray.push(filePath.fileName);
|
||||
if (this.validateRoot(oasObject).result) {
|
||||
rootFilesArray.push(filePath.fileName);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
});
|
||||
|
||||
return rootFilesArray;
|
||||
},
|
||||
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
var expect = require('chai').expect,
|
||||
_ = require('lodash'),
|
||||
Utils = require('../../lib/util.js'),
|
||||
// path = require('path'),
|
||||
// fs = require('fs'),
|
||||
parse = require('../../lib/parse.js'),
|
||||
openApiErr = require('../../lib/error.js');
|
||||
|
||||
/* Utility function Unit tests */
|
||||
@@ -1969,47 +1966,3 @@ describe('convertToPmQueryArray function', function() {
|
||||
expect(result[1]).to.equal('variable3=queryParamExample1 queryParamExample1');
|
||||
});
|
||||
});
|
||||
|
||||
describe('PARSE FUNCTION TESTS', function() {
|
||||
// it('getRootFiles should return an array with only one root file path', function() {
|
||||
// let folderPath = path.join(__dirname, '../data/multiFile_with_one_root'),
|
||||
// array = [
|
||||
// { fileName: folderPath + '/index.yaml' },
|
||||
// { fileName: folderPath + '/definitions/index.yaml' },
|
||||
// { fileName: folderPath + '/definitions/User.yaml' },
|
||||
// { fileName: folderPath + '/info/index.yaml' },
|
||||
// { fileName: folderPath + '/paths/index.yaml' },
|
||||
// { fileName: folderPath + '/paths/foo.yaml' },
|
||||
// { fileName: folderPath + '/paths/bar.yaml' }
|
||||
// ],
|
||||
// result = parse.getRootFiles(array);
|
||||
// expect(result.length).to.equal(1);
|
||||
// expect(result[0]).to.equal('/Users/dhroovgupta/Postman/projects/openapi-to-postman' +
|
||||
// '/test/data/multiFile_with_one_root/index.yaml');
|
||||
// });
|
||||
|
||||
it('validateRoot function should return an object with result true', function() {
|
||||
let oas = {
|
||||
'openapi': '3.0.0',
|
||||
'info': {
|
||||
'title': 'sample title',
|
||||
'version': '1.2.4'
|
||||
},
|
||||
'paths': {
|
||||
'/': {}
|
||||
}
|
||||
},
|
||||
result = parse.validateRoot(oas);
|
||||
expect(result.result).to.equal(true);
|
||||
});
|
||||
|
||||
// it('getOasObject function should return a valid oas object from a yaml file', function() {
|
||||
// let filePath = '/Users/dhroovgupta/Postman/projects/openapi-to-postman' +
|
||||
// '/test/data/multiFile_with_one_root/index.yaml',
|
||||
// file = fs.readFileSync(filePath, 'utf8'),
|
||||
// result = parse.getOasObject(file);
|
||||
|
||||
// expect(result.openapi).to.equal('3.0.0');
|
||||
// });
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user