-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathindex.js
More file actions
54 lines (45 loc) · 1.45 KB
/
Copy pathindex.js
File metadata and controls
54 lines (45 loc) · 1.45 KB
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
46
47
48
49
50
51
52
53
54
const Connnector = require('apiconnect-wsdl')
const fs = require('fs')
const Converter = require('./converters')
async function convert(options) {
const wsdls = await Connnector.getJsonForWSDL(options.input)
const serviceData = Connnector.getWSDLServices(wsdls)
const opts = {
openapiVersion: options.openapiVersion,
inlineAttributes: options.inlineAttributes,
suppressExamples: !options.examples,
// type: 'wsdl-to-rest',
wssecurity: options.useSecurity,
}
const services = []
for (const item in serviceData.services) { // eslint-disable-line
const { service: svcName, filename: wsdlId } =
serviceData.services[item]
const openapi = Connnector.createOpenApi(
options.input,
svcName,
wsdlId,
opts,
)
services.push(openapi)
}
const openApis = await Promise.all(services).then((apis) =>
apis.map(({ openapi }) => openapi),
)
let out
switch (options.target) {
case 'Postman':
out = await Converter.Postman(openApis[0])
break
case 'OpenAPI':
case 'Swagger':
;[out] = openApis
break
default:
throw new Error(
`Output format [${options.target}] currently not supported`,
)
}
fs.writeFileSync(options.output, JSON.stringify(out, null, 2))
}
module.exports = convert