mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
changed to new input format, updated plugintest
This commit is contained in:
54
index.js
54
index.js
@@ -1,5 +1,55 @@
|
||||
// Exports the interface for the plugin
|
||||
var convert = require('./lib/convert.js'),
|
||||
fs = require('fs'),
|
||||
validate = require('./lib/validate.js');
|
||||
|
||||
module.exports = {
|
||||
convert: require('./lib/convert.js'),
|
||||
validate: require('./lib/validate.js')
|
||||
convert: function(input, options, cb) {
|
||||
try {
|
||||
var data;
|
||||
if (input.type === 'string') {
|
||||
return convert(input.data, cb);
|
||||
}
|
||||
else if (input.type === 'json') {
|
||||
return convert(input.data, cb);
|
||||
}
|
||||
else if (input.type === 'file') {
|
||||
data = fs.readFileSync(input.data).toString();
|
||||
return convert(data, cb);
|
||||
}
|
||||
return cb(null, {
|
||||
result: false,
|
||||
reason: 'input type is not valid'
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
return cb(e);
|
||||
}
|
||||
|
||||
},
|
||||
validate: function(input) {
|
||||
try {
|
||||
var data;
|
||||
if (input.type === 'string') {
|
||||
return validate(input.data);
|
||||
}
|
||||
else if (input.type === 'json') {
|
||||
return validate(input.data);
|
||||
}
|
||||
else if (input.type === 'file') {
|
||||
data = fs.readFileSync(input.data).toString();
|
||||
return validate(data);
|
||||
}
|
||||
return {
|
||||
result: false,
|
||||
reason: 'input type is not valid'
|
||||
};
|
||||
}
|
||||
catch (e) {
|
||||
return {
|
||||
result: false,
|
||||
reason: e.toString()
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user