-
Notifications
You must be signed in to change notification settings - Fork 0
/
convDocSpec.js
executable file
·72 lines (52 loc) · 2.17 KB
/
convDocSpec.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
#!/usr/bin/env node
const toOpenApi = require('json-schema-to-openapi-schema');
const fs = require('fs')
const R = require('ramda')
const YAML = require('yaml').default
const main = () => {
const origDocs = YAML.parse(fs.readFileSync('./sls-documentation.yml').toString())
const swaggerSpec = JSON.parse(fs.readFileSync('./swagger-docs.json'))
const packageJson = JSON.parse(fs.readFileSync('./package.json'))
console.log(swaggerSpec)
swaggerSpec.definitions = R.map(schema => toOpenApi(schema), swaggerSpec.definitions)
swaggerSpec.info.title = packageJson.docs.title
swaggerSpec.info.version = packageJson.version
console.log(origDocs.documentation.models)
console.log(swaggerSpec.definitions)
R.mapObjIndexed((model, _name) => {
const _m = R.compose(R.head, R.filter(({name}) => name == _name))(origDocs.documentation.models)
console.log(_name, _m, model)
if (_m) {
['pattern', 'format', 'example'].map(i => { if(_m[i]) { model[i] = _m[i] }})
console.log(model)
}
}, swaggerSpec.definitions)
// swaggerSpec.definitions.TXID = swaggerSpec.definitions.TXID || {}
// swaggerSpec.definitions.TXID.pattern = "/^0x([0-9a-fA-F]{2})*$/"
// swaggerSpec.definitions.TXID.minLength = 66
// swaggerSpec.definitions.TXID.maxLength = 66
// swaggerSpec.definitions.TXID.format = "hexString"
// swaggerSpec.definitions.ErrTy.nullable = true
// manual additions over
fs.writeFileSync('./swagger-docs.json', JSON.stringify(swaggerSpec, null, 2))
console.log("Converted swagger-docs.json from JsonSchema to OpenAPI")
}
const fixPathParamDesc = (spec) => {
R.map(path => {
if (path.post) {
R.map((param) => {
if (param.name) {
param.description = getDescriptionFor(spec, param.name)
}
}, path.post.parameters)
}
}, spec.paths)
}
const getDescriptionFor = (spec, modelName) => {
const defaultDesc = "No description available 😢"
if (spec.definitions[modelName]) {
return spec.definitions[modelName].description || defaultDesc
}
return defaultDesc
}
main()