added validation for folder

This commit is contained in:
Dhroov7
2019-12-04 17:05:01 +05:30
parent df454cdfd8
commit 822a034526
2 changed files with 57 additions and 49 deletions

View File

@@ -120,6 +120,14 @@ module.exports = {
data = fs.readFileSync(input.data).toString();
return validate(data);
}
else if (input.type === 'folder') {
if (!_.isEmpty(parse.getRootFiles(input.data))) {
return {
result: true,
reason: 'valid input type'
};
}
}
return {
result: false,
reason: 'input type is not valid'

View File

@@ -1,54 +1,54 @@
// var expect = require('chai').expect,
// path = require('path'),
// fs = require('fs'),
// parse = require('../../lib/parse');
var expect = require('chai').expect,
// path = require('path'),
fs = require('fs'),
parse = require('../../lib/parse');
// describe('Parse function tests', function() {
// describe('getRootFiles function', function() {
// it('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');
// });
// });
describe('Parse function tests', function() {
// describe('getRootFiles function', function() {
// it('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');
// });
// });
// describe('validateRoot function', function() {
// it('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);
// });
// });
describe('validateRoot function', function() {
it('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);
});
});
// describe('getOasObject function', function() {
// it('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);
describe('getOasObject function', function() {
it('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');
// });
// });
// });
expect(result.openapi).to.equal('3.0.0');
});
});
});