-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (39 loc) · 1.37 KB
/
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
40
41
42
43
44
45
'use strict';
var apib2swagger = require('apib2swagger');
var apib2swaggerOptions = { preferReference: true, bearerAsApikey: false };
var swagger2openapi = require('swagger2openapi');
var swagger2openapiOptions = { anchors:true, direct:true, patch:true };
var Converter = module.exports = {};
Converter.apib2swaggerConverter = function(data, options) {
return new Promise((resolve, reject) => {
var mergedOptions = Object.assign(apib2swaggerOptions, options);
apib2swagger.convert(data, mergedOptions, (error, result) => {
if (error) {
reject(error);
} else {
resolve(result);
}
});
});
}
Converter.swagger2openapiConverter = function(data, options) {
return new Promise((resolve, reject) => {
var mergedOptions = Object.assign(swagger2openapiOptions, options);
swagger2openapi.convert(data, mergedOptions, (error, result) => {
if (error) {
reject(error);
} else {
resolve(result);
}
});
});
}
Converter.convert = function(data, options) {
return Converter.apib2swaggerConverter(data, options.apib2swaggerOptions)
.then(result =>
Converter.swagger2openapiConverter(
result.swagger,
options.swagger2openapiOptions
)
);
}