2017-11-26 20:45:40 +00:00
|
|
|
const utils = require('./src/utils');
|
|
|
|
|
|
|
|
const importers = [
|
|
|
|
require('./src/importers/insomnia-1'),
|
|
|
|
require('./src/importers/insomnia-2'),
|
|
|
|
require('./src/importers/insomnia-3'),
|
|
|
|
require('./src/importers/postman'),
|
|
|
|
require('./src/importers/postman-env'),
|
|
|
|
require('./src/importers/har'),
|
2018-01-16 07:02:12 +00:00
|
|
|
require('./src/importers/curl'),
|
2018-12-12 17:36:11 +00:00
|
|
|
require('./src/importers/swagger2'),
|
2017-11-26 20:45:40 +00:00
|
|
|
];
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
module.exports.convert = async function(contents) {
|
2017-11-26 20:45:40 +00:00
|
|
|
for (const importer of importers) {
|
2018-01-16 05:51:28 +00:00
|
|
|
const resources = await importer.convert(contents);
|
2017-11-26 20:45:40 +00:00
|
|
|
|
|
|
|
if (resources) {
|
2018-11-30 05:50:30 +00:00
|
|
|
if (resources.length > 0 && resources[0].variable) {
|
|
|
|
resources[0].environment = resources[0].variable;
|
|
|
|
}
|
|
|
|
let parsedData = {
|
2017-11-26 20:45:40 +00:00
|
|
|
type: {
|
|
|
|
id: importer.id,
|
|
|
|
name: importer.name,
|
2018-12-12 17:36:11 +00:00
|
|
|
description: importer.description,
|
2017-11-26 20:45:40 +00:00
|
|
|
},
|
|
|
|
data: {
|
|
|
|
_type: 'export',
|
|
|
|
__export_format: 3,
|
|
|
|
__export_date: utils.getDateString(),
|
|
|
|
__export_source: 'insomnia.importers:v0.1.0',
|
2018-12-12 17:36:11 +00:00
|
|
|
resources: resources.map(utils.setDefaults),
|
|
|
|
},
|
2018-06-25 17:42:50 +00:00
|
|
|
};
|
2018-11-30 05:50:30 +00:00
|
|
|
|
|
|
|
return parsedData;
|
2017-11-26 20:45:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Error('No importers found for file');
|
|
|
|
};
|