Skip to content

Instantly share code, notes, and snippets.

@albarin
Created April 1, 2019 13:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save albarin/3e58da56e5a5e63480eb7054a024d4e3 to your computer and use it in GitHub Desktop.
Save albarin/3e58da56e5a5e63480eb7054a024d4e3 to your computer and use it in GitHub Desktop.
Script to filter OpenAPI spec
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