-
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathopenapi-filter.js
More file actions
executable file
·77 lines (73 loc) · 2.46 KB
/
Copy pathopenapi-filter.js
File metadata and controls
executable file
·77 lines (73 loc) · 2.46 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/env node
'use strict';
const fs = require('fs');
const yaml = require('yaml');
const {strOptions} = require('yaml/types');
const openapiFilter = require('./index.js');
let argv = require('yargs')
.usage('$0 <infile> [outfile]',false,(yargs) => {
yargs
.positional('infile',{ describe: 'the input file' })
.positional('outfile',{ describe: 'the output file' })
})
.strict()
.boolean('info')
.describe('info','include complete info object with --valid')
.boolean('inverse')
.describe('inverse','output filtered elements only')
.alias('inverse','i')
.boolean('servers')
.describe('servers','include complete servers object with --valid')
.array('flags')
.alias('flags','f')
.describe('flags','flags to filter by')
.default('flags',['x-internal'])
.array('flagValues')
.alias('flagValues', 'v')
.describe('flagValues', 'flag string values to consider as a filter match (in addition to matching on boolean types)')
.default('flagValues', [])
.boolean('checkTags')
.describe('checkTags', 'filter if flags given in --flags are in the tags array')
.array('overrides')
.alias('overrides','o')
.default('overrides', [])
.describe('overrides', 'prefixes used to override named properties')
.array('methods')
.alias('methods', 'm')
.describe('methods', 'OpenAPI methods to filter by')
.default('methods', [])
.array('operationIds')
.alias('operationIds', 'id')
.describe('operationIds', 'OpenAPI operationIds to filter by')
.default('operationIds', [])
.boolean('valid')
.describe('valid', 'try to ensure inverse output is valid')
.boolean('strip')
.alias('strip','s')
.describe('strip','strip the flags from the finished product')
.number('lineWidth')
.alias('lineWidth','l')
.describe('lineWidth','max line width of yaml output')
.default('lineWidth',-1)
.number('maxAliasCount')
.default('maxAliasCount',100)
.describe('maxAliasCount','maximum YAML aliases allowed')
.help()
.version()
.argv;
let s = fs.readFileSync(argv.infile,'utf8');
let obj = yaml.parse(s, {maxAliasCount: argv.maxAliasCount});
let res = openapiFilter.filter(obj,argv);
if (argv.infile.indexOf('.json')>=0) {
s = JSON.stringify(res,null,2);
}
else {
strOptions.fold.lineWidth = argv.lineWidth;
s = yaml.stringify(res);
}
if (argv.outfile) {
fs.writeFileSync(argv.outfile,s,'utf8');
}
else {
console.log(s);
}