openapi-filter
Advanced tools
Comparing version 3.1.0 to 3.2.0
@@ -84,3 +84,3 @@ { | ||
"key-spacing": "off", | ||
"keyword-spacing": "off", | ||
"keyword-spacing": ["error", { "after": true }], | ||
"line-comment-position": "off", | ||
@@ -87,0 +87,0 @@ "linebreak-style": [ |
@@ -66,5 +66,8 @@ 'use strict'; | ||
recurse(src,{},function(obj,key,state){ | ||
if (obj.hasOwnProperty('$ref') && filteredpaths.includes(obj.$ref)) { | ||
if (Array.isArray(state.parent)) { | ||
state.parent.splice(state.pkey, 1); | ||
if (Array.isArray(obj) && obj.length > 0) { | ||
for (let idx = 0; idx < obj.length; idx++) { | ||
if (obj[idx] && obj[idx].hasOwnProperty('$ref') && filteredpaths.includes(obj[idx].$ref)) { | ||
obj.splice(idx, 1); | ||
idx--; | ||
} | ||
} | ||
@@ -71,0 +74,0 @@ } |
@@ -50,2 +50,6 @@ #!/usr/bin/env node | ||
.describe('maxAliasCount','maximum YAML aliases allowed') | ||
.alias('configFile', 'c') | ||
.describe('configFile', 'The file & path for the filter options') | ||
.count('verbose') | ||
.describe('verbose', 'Output more details of the filter process.') | ||
.help() | ||
@@ -55,2 +59,29 @@ .version() | ||
// Helper function to display info message, depending on the verbose level | ||
function info(msg) { | ||
if (argv.verbose >= 1) { | ||
console.warn(msg); | ||
} | ||
} | ||
info('=== Document filtering started ===\n') | ||
// apply options from config file if present | ||
if (argv && argv.configFile) { | ||
info('Config File: ' + argv.configFile) | ||
try { | ||
let configFileOptions = {} | ||
if (argv.configFile.indexOf('.json')>=0) { | ||
configFileOptions = JSON.parse(fs.readFileSync(argv.configFile, 'utf8')); | ||
} else { | ||
configFileOptions = yaml.parse(fs.readFileSync(argv.configFile, 'utf8'), {schema:'core'}); | ||
} | ||
argv = Object.assign({}, argv, configFileOptions); | ||
} catch (err) { | ||
console.error(err) | ||
} | ||
} | ||
info('Input file: ' + argv.infile) | ||
let s = fs.readFileSync(argv.infile,'utf8'); | ||
@@ -68,2 +99,4 @@ let obj = yaml.parse(s, {maxAliasCount: argv.maxAliasCount}); | ||
fs.writeFileSync(argv.outfile,s,'utf8'); | ||
info('Output file: ' + argv.outfile) | ||
} | ||
@@ -74,1 +107,3 @@ else { | ||
info('\nā Document was filtered successfully') | ||
{ | ||
"name": "openapi-filter", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "Filter internal paths, operations, parameters, schemas etc from OpenAPI/Swagger definitions", | ||
@@ -8,3 +8,3 @@ "main": "index.js", | ||
"scripts": { | ||
"lint": "npx eslint *.js", | ||
"lint": "npx eslint *.js test/*.js", | ||
"test": "npx mocha" | ||
@@ -11,0 +11,0 @@ }, |
@@ -46,3 +46,5 @@ # openapi-filter | ||
--maxAliasCount maximum YAML aliases allowed [number] [default: 100] | ||
--configFile The file & path for the filter options [path] | ||
--help Show help [boolean] | ||
--verbose Output more details of the filter process [count] | ||
``` | ||
@@ -49,0 +51,0 @@ |
@@ -21,6 +21,16 @@ 'use strict'; | ||
let options = {}; | ||
let configFile = null | ||
try { | ||
options = yaml.parse(fs.readFileSync(path.join(__dirname, test, 'options.yaml'),'utf8'), {schema:'core'}); | ||
// Load options.yaml | ||
configFile = path.join(__dirname, test, 'options.yaml'); | ||
options = yaml.parse(fs.readFileSync(configFile, 'utf8'), {schema: 'core'}); | ||
} catch (ex) { | ||
try { | ||
// Fallback to options.json | ||
configFile = path.join(__dirname, test, 'options.json'); | ||
options = JSON.parse(fs.readFileSync(configFile, 'utf8')); | ||
} catch (ex) { | ||
// No options found. options = {} will be used | ||
} | ||
} | ||
catch (ex) {}; | ||
@@ -38,3 +48,3 @@ if (options.maxAliasCount) { | ||
} | ||
catch (ex) {}; | ||
catch (ex) {} | ||
@@ -41,0 +51,0 @@ const result = filter.filter(input, options); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
147326
61
555
67