This repository has been archived by the owner on Feb 11, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
munge.js
61 lines (49 loc) · 1.61 KB
/
munge.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
/** munge test results for easier comparison
* not used as an optimisation, default or otherwise
* mutates passed-in object
*/
var _ = require('lodash');
var common = require('./common.js');
var parameters = require('./parameters.js');
module.exports = {
munge : function(src,options) {
if ((!src.securityDefinitions) || (Object.keys(src.securityDefinitions).length<=0)) {
delete src.securityDefinitions;
src.securityDefinitions = {}; // forces add at end of properties
}
common.forEachAction(src,function(action){
if (!action.produces) {
action.produces = src.produces;
}
if (!action.consumes) {
action.consumes = src.consumes;
}
var deprecated = (typeof action.deprecated == 'undefined' ? false : action.deprecated);
var produces = _.cloneDeep(action.produces);
var consumes = _.cloneDeep(action.consumes);
delete action.produces;
delete action.consumes;
action.produces = produces;
action.consumes = consumes;
delete action.deprecated;
action.deprecated = deprecated;
});
for (var p in src.parameters) {
src.parameters[p] = parameters.transform(src.parameters[p]);
}
if (src.components && src.components.parameters) {
src.components.parameters[p] = parameters.transform(src.components.parameters[p]);
}
common.forEachPath(src,function(path){
for (var p in path.parameters) {
path.parameters[p] = parameters.transform(path.parameters[p]);
}
});
common.forEachAction(src,function(action){
for (var p in action.parameters) {
action.parameters[p] = parameters.transform(action.parameters[p]);
}
});
return src;
}
};