-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js
76 lines (64 loc) · 2.3 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const debug = require('debug')('soap-converter:index')
const apiWSDL = require('apiconnect-wsdl')
const fs = require('fs')
const converter = require('./converters')
async function convert(options) {
debug('convert', options.input)
const wsdls = await apiWSDL.getJsonForWSDL(options.input)
const serviceData = apiWSDL.getWSDLServices(wsdls)
const items = []
// Loop through all services
for (const item in serviceData.services) { // eslint-disable-line
const svcName = serviceData.services[item].service
const wsdlId = serviceData.services[item].filename
const wsdlEntry = apiWSDL.findWSDLForServiceName(wsdls, svcName)
const swaggerOptions = {
inlineAttributes: options.inlineAttributes,
suppressExamples: !options.examples,
type: 'wsdl',
wssecurity: options.useSecurity
}
const swagger = apiWSDL.getSwaggerForService(
wsdlEntry,
svcName,
wsdlId,
swaggerOptions
)
if (!options.useIbmDatapowerGateway) {
delete swagger.info['x-ibm-name']
delete swagger['x-ibm-configuration']
}
if (options.apiKeyHeader) {
swagger.securityDefinitions.clientID.name = options.apiKeyHeader
if (!options.useIbmDatapowerGateway) {
// ApiKeyAuth is more swagger-standard than clientID
swagger.securityDefinitions.ApiKeyAuth =
swagger.securityDefinitions.clientID
delete swagger.securityDefinitions.clientID
swagger.security = [{ ApiKeyAuth: [] }]
}
}
items.push(swagger)
}
let isJSONOutput = true
let out
switch (options.target) {
case 'Postman':
out = converter.Postman(items)
break
case 'SwaggerJSON':
;[out] = items
break
case 'SwaggerYAML':
out = converter.Swagger(items[0])
isJSONOutput = false
break
default:
throw new Error(
`output format [${options.target}] currently not supported`
)
}
const data = isJSONOutput ? JSON.stringify(out, null, 2) : out
fs.writeFileSync(options.output, data)
}
module.exports = convert