mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
Support for multi file schema in schemapack
This commit is contained in:
93
index.js
93
index.js
@@ -1,14 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const SchemaPack = require('./lib/schemapack.js').SchemaPack,
|
||||
async = require('async'),
|
||||
parse = require('./lib/parse.js'),
|
||||
|
||||
// options for oas-resolver
|
||||
OasResolverOptions = {
|
||||
resolve: true, // Resolve external references
|
||||
jsonSchema: true // Treat $ref like JSON Schema and convert to OpenAPI Schema Objects
|
||||
};
|
||||
const SchemaPack = require('./lib/schemapack.js').SchemaPack;
|
||||
|
||||
module.exports = {
|
||||
// Old API wrapping the new API
|
||||
@@ -18,88 +10,19 @@ module.exports = {
|
||||
if (schema.validated) {
|
||||
return schema.convert(cb);
|
||||
}
|
||||
else if (input.type === 'folder') {
|
||||
let filesPathArray = input.data,
|
||||
convertedSpecs = [],
|
||||
rootFiles = parse.getRootFiles(filesPathArray);
|
||||
|
||||
async.eachSeries(rootFiles, (rootFile, callback) => {
|
||||
parse
|
||||
// will merge all the files in the folder
|
||||
.mergeFiles(rootFile, OasResolverOptions)
|
||||
.then((spec) => {
|
||||
converter.convert(spec, options, (err, result) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
convertedSpecs.push(result);
|
||||
return callback(null);
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
return callback(err);
|
||||
});
|
||||
}, (err) => {
|
||||
|
||||
if (err) {
|
||||
return cb({
|
||||
result: false,
|
||||
reason: 'input type:' + input.type + ' is not valid'
|
||||
});
|
||||
}
|
||||
|
||||
var conversionResult = false,
|
||||
convertedCollections = [],
|
||||
reasonForFail;
|
||||
|
||||
_.forEach(convertedSpecs, (convertedSpec) => {
|
||||
if (convertedSpec.result) {
|
||||
let result;
|
||||
conversionResult = conversionResult || convertedSpec.result;
|
||||
|
||||
function returnCollection (resultSpec) {
|
||||
if (resultSpec.type === 'collection') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// filtering out the collections from the convertedSpec
|
||||
result = convertedSpec.output.filter(returnCollection);
|
||||
convertedCollections.push(result[0]);
|
||||
}
|
||||
else {
|
||||
conversionResult = conversionResult || convertedSpec.result;
|
||||
reasonForFail = convertedSpec.reason;
|
||||
}
|
||||
});
|
||||
|
||||
if (conversionResult) {
|
||||
return cb(null, {
|
||||
result: true,
|
||||
output: convertedCollections
|
||||
});
|
||||
}
|
||||
|
||||
return cb(null, {
|
||||
result: false,
|
||||
reason: reasonForFail
|
||||
});
|
||||
});
|
||||
}
|
||||
// eslint-disable-next-line no-else-return
|
||||
else {
|
||||
return cb(null, {
|
||||
result: false,
|
||||
reason: 'input type:' + input.type + ' is not valid'
|
||||
});
|
||||
}
|
||||
return cb(null, schema.validationResult);
|
||||
},
|
||||
|
||||
validate: function(input) {
|
||||
validate: function (input) {
|
||||
var schema = new SchemaPack(input);
|
||||
return schema.validationResult;
|
||||
},
|
||||
|
||||
mergeAndValidate: function (input, cb) {
|
||||
var schema = new SchemaPack(input);
|
||||
schema.mergeAndValidate(cb);
|
||||
},
|
||||
|
||||
getOptions: function() {
|
||||
return SchemaPack.getOptions();
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user