Created
April 1, 2019 13:35
-
-
Save albarin/3e58da56e5a5e63480eb7054a024d4e3 to your computer and use it in GitHub Desktop.
Script to filter OpenAPI spec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const pickBy = require('lodash.pickby') | |
const validate = require('./schema-validator.js') | |
const DEFAULT_FILTERS = [ | |
{ | |
key: 'x-visibility', | |
value: 'EXTERNAL' | |
}, | |
{ | |
key: 'x-status', | |
value: 'LIVE' | |
} | |
] | |
module.exports = function filterPaths (schema, filters = DEFAULT_FILTERS) { | |
try { | |
validate(schema) | |
} catch (e) { | |
throw e | |
} | |
const { paths } = schema | |
const filteredPaths = pickBy(paths, pathItemObject => { | |
return filters.every(({ key, value }) => { | |
return value.includes(pathItemObject[key]) | |
}) | |
}) | |
return Object.assign({}, schema, { | |
paths: filteredPaths | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment