Skip to content

Commit

Permalink
fix: yargs argument passing and infinite loop with --inverse and --valid
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeRalphson committed Apr 13, 2023
1 parent 0c969b8 commit a75235e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function filter(obj,options) {
let checkForReferences = true;

while (checkForReferences) {
checkForReferences = false;
let changesMade = false;

recurse(filtered, {}, function (o, key, state) {
Expand Down
21 changes: 10 additions & 11 deletions openapi-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ const yaml = require('yaml');
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' })
})
.usage('$0 <infile> [outfile]')
.demand(1)
.strict()
.boolean('info')
.describe('info','include complete info object with --valid')
Expand Down Expand Up @@ -79,21 +76,23 @@ if (argv && argv.configFile) {
}
}

info('Input file: ' + argv.infile)
const infile = argv._[0];
const outfile = argv._[1];
info('Input file: ' + infile)

let s = fs.readFileSync(argv.infile,'utf8');
let s = fs.readFileSync(infile,'utf8');
let obj = yaml.parse(s, {maxAliasCount: argv.maxAliasCount});
let res = openapiFilter.filter(obj,argv);
if (argv.infile.indexOf('.json')>=0) {
if (infile.indexOf('.json')>=0) {
s = JSON.stringify(res,null,2);
}
else {
s = yaml.stringify(res, {lineWidth: argv.lineWidth});
}
if (argv.outfile) {
fs.writeFileSync(argv.outfile,s,'utf8');
if (outfile) {
fs.writeFileSync(outfile,s,'utf8');

info('Output file: ' + argv.outfile)
info('Output file: ' + outfile)
}
else {
console.log(s);
Expand Down

0 comments on commit a75235e

Please sign in to comment.