-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathhide-items.js
More file actions
executable file
·77 lines (70 loc) · 3.07 KB
/
hide-items.js
File metadata and controls
executable file
·77 lines (70 loc) · 3.07 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
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
73
74
75
76
77
#!/usr/bin/node
'use strict'
require('shelljs/global');
var fs = require('fs');
var YAML = require('js-yaml');
var deploy_path = process.argv[2]; // web_deploy
if(process.argv[3] != 'skip-regenerate')
{
console.log("first regenerate combined file to ensure it is up to date");
exec('swagger-repo bundle -y -o ./' + deploy_path + '/swagger.yaml'); //this wants a single dot
}
//now load that file
var swagger = YAML.safeLoad(fs.readFileSync(deploy_path + '/swagger.yaml', 'utf-8'));
function hide_items(tree) {
Object.keys(tree).forEach(function(key) {
if(typeof(tree[key]) === 'object')
{
hide_items(tree[key]);
if (typeof(tree[key]['delete_me']) === 'string')
{
if(typeof(tree) === 'object' && !isNaN(key) && tree.splice)
{
//delete was breaking arrays so using splice in certain places.
console.log(tree);
tree.splice(key,1);
console.log(tree);
}
else delete tree[key];
}
}
if(typeof(tree[key]) === 'string' && tree[key].indexOf('STAGE=') >= 0)
{
tree['delete_me'] = "delete_me";
}
});
}
hide_items(swagger);
/* OLD METHOD THAT JUST HID SUMMARY NOT ANY NODE
Object.keys(swagger).forEach(function(level1) {
//toplevels console.log(level1);
Object.keys(swagger[level1]).forEach(function(level2) {
//methods console.log(level2);
Object.keys(swagger[level1][level2]).forEach(function(level3) {
//get/post/delete console.log(level3);
if(swagger[level1][level2][level3]['summary'] && swagger[level1][level2][level3]['summary'].indexOf('STAGE=') >= 0)
{
delete swagger[level1][level2][level3]; //hide the method
}
});
});
});
*/
console.log('Saving modified yaml');
fs.writeFile(deploy_path + '/swagger.yaml', YAML.safeDump(swagger, {indent: 2, lineWidth: -1, noRefs: true, sortKeys: true}), (err) => {
if (err)
{
console.log('ERROR WRITING: ' + deploy_path + '/swagger.yaml');
console.log(err);
console.log(process.cwd());
}
});
console.log('Saving modified json');
fs.writeFile(deploy_path + '/swagger.json', JSON.stringify(swagger, null, 2) + '\n' , (err) => {
if (err)
{
console.log('ERROR WRITING: ' + deploy_path + '/swagger.json');
console.log(err);
console.log(process.cwd());
}
});