forked from webdock-io/nodejs-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreprocess.js
More file actions
41 lines (30 loc) · 1.11 KB
/
preprocess.js
File metadata and controls
41 lines (30 loc) · 1.11 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
const yaml = require('js-yaml')
const { mapValues } = require('lodash')
exports.preprocessSchema = (yamlSchema) => {
const openApiSchema = yaml.load(yamlSchema);
/** Temp hack */
openApiSchema.components.schemas.WarningDTO.properties.data = {
description: 'Warning message',
type: 'object',
additionalProperties: [{ type: 'string' }]
}
const requestBodies = openApiSchema.components.requestBodies;
const replaceRefs = (input) => {
const iterator = (value) => {
if (Array.isArray(value)) {
return value.map(value => iterator(value))
}
if (typeof value === 'object' && value && /requestBodies/.test(value['$ref'])) {
const modelName = value['$ref'].split('/').pop()
return requestBodies[modelName]
}
if (typeof value === 'object' && value !== null) {
return mapValues(value, iterator)
}
return value
};
return mapValues(input, iterator)
}
const output = replaceRefs(openApiSchema)
return output;
}