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'),
|
|
|
|
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) {
|
|
|
|
return {
|
|
|
|
type: {
|
|
|
|
id: importer.id,
|
|
|
|
name: importer.name,
|
|
|
|
description: importer.description
|
|
|
|
},
|
|
|
|
data: {
|
|
|
|
_type: 'export',
|
|
|
|
__export_format: 3,
|
|
|
|
__export_date: utils.getDateString(),
|
|
|
|
__export_source: 'insomnia.importers:v0.1.0',
|
2018-06-25 17:42:50 +00:00
|
|
|
resources: resources.map(utils.setDefaults)
|
2017-11-26 20:45:40 +00:00
|
|
|
}
|
2018-06-25 17:42:50 +00:00
|
|
|
};
|
2017-11-26 20:45:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Error('No importers found for file');
|
|
|
|
};
|