forked from LucyBot-Inc/api-spec-converter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (33 loc) · 946 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict';
var Types = require('./lib/types.js');
var _ = require('lodash');
var Converter = module.exports = {};
Converter.Types = Types;
Converter.BaseType = require('./lib/base-type.js');
Converter.getSpec = function (source, type, callback) {
var spec = new Types[type]();
spec.resolveResources(source, function(error) {
if (error)
callback(error, null);
else
callback(null, spec);
});
}
Converter.getTypeName = function (name, version) {
var result;
_.each(Types, function (type, typeName) {
type = type.prototype;
if (type.formatName === name && type.supportedVersions.indexOf(version) !== -1)
result = typeName;
});
return result;
};
Converter.convert = function(options, callback) {
Converter.getSpec(options.source, options.from, function(error, fromSpec) {
if (error) {
callback(error, null);
return;
}
fromSpec.convertTo(options.to, callback);
});
}