-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathraml2oas.js
51 lines (40 loc) · 1.5 KB
/
raml2oas.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
const wap = require('webapi-parser').WebApiParser
const path = require('path')
async function main() {
// Parse RAML 1.0 file
const inPath = path.join(__dirname, '../mod-source-record-manager/ramls/change-manager.raml')
const model = await wap.raml10.parse(`file://${inPath}`)
// // Get User.age property
// const age = model.declares[0].properties[2]
//
// // Set age minimum to 18
// age.range.withMinimum(18)
//
// // Set API baseUrl
// model.encodes.withServer('127.0.0.1/api/{version}')
const ramlPath = path.join(__dirname, './generated.raml')
console.log('Generating file to:', ramlPath)
// resolve the model
const resModel = await wap.raml10.resolve(model)
const api = resModel.encodes
const endpoints = api.endPoints
for (const endpoint of endpoints) {
console.log(endpoint.path.value())
for (const operation of endpoint.operations) {
for (const response of operation.responses) {
console.log(response.name.value())
for (const payload of response.payloads) {
console.log(payload.schema.toJsonSchema)
}
}
}
}
// Generate RAML 1.0 file
await wap.raml10.generateFile(resModel, `file://${ramlPath}`)
const oasPath = path.join(__dirname, './oas.json')
console.log('Generating file to:', oasPath)
await wap.oas30.generateFile(resModel, `file://${oasPath}`)
}
main().catch(reason => {
console.log(reason)
})