Skip to content

Instantly share code, notes, and snippets.

@albarin albarin/filter.js
Created Apr 1, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.