forked from premku70/swagger-mongoose-crud
-
Notifications
You must be signed in to change notification settings - Fork 3
/
swagger.params.map.js
43 lines (41 loc) · 1008 Bytes
/
swagger.params.map.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
// Purpose : map every key to its value
let map = (req) => {
if (req.operationDoc) {
let params = {};
req.operationDoc.parameters.forEach(element => {
switch (element.in) {
case 'body': {
params[element.name] = req.body;
break;
}
case 'query': {
if (req.query[element.name])
params[element.name] = req.query[element.name];
break;
}
case 'path': {
if (req.params[element.name])
params[element.name] = req.params[element.name];
break;
}
}
});
return params;
} else if (req.swagger && req.swagger.params) {
return Object.keys(req.swagger.params).reduce((prev, curr) => {
prev[curr] = req.swagger.params[curr].value;
return prev;
}, {});
} else {
let params = {};
Object.keys(req.query).forEach((key) => {
params[key] = req.query[key];
});
Object.keys(req.params).forEach((key) => {
params[key] = req.params[key];
});
params['data'] = req.body;
return params;
}
};
module.exports = { map: map };