sonic-express
sonic-express copied to clipboard
Whitelist or blacklist paths
Is your feature request related to a problem? Please describe. Naa, not a problem, just an extension for my use case.
Describe the solution you'd like An option (via config or a function) to whitelist or blacklist paths
Describe alternatives you've considered I've considered adding a post-processing step after the tests that will strip out paths from the doc. This is likely trivial, but other items like tags, schemas and responses (schemas and responses are auto-generated, so very tricky to remove in a post-processing step).
Another alternative is to use an unless
middleware that only runs the getResponseExpress(...)
on select routes
/**
* Helper to apply middleware selectively to routes
* @param {*} prefixes
* @param {*} middleware
*/
function unless(prefixes = [], middleware) {
return function (req, res, next) {
if (prefixes.includes(req.url)) {
return next();
} else {
return middleware(req, res, next);
}
};
}
This could be run in userland, but I'm not sure if sonic-express has any expectations regarding how its attached as a middleware.
Additional context We have an API, housed in a single codebase that will feed both internal and external consumers. For now, this distinction is via route groups and different authorizers. I'm using sonic-express to update the swagger doc we expose to internal consumers. I need a way to not include routes that are meant for other consumers.
Hello
Currently, what I do for this particular use case is to just import the json via a node script and remove the routes directly.
Since this use case would be very common, I can add a step or two to perform this.
Do you already have a solution?
I wrapped the middleware step in the unless
middleware effectively only calling sonic-express for the routes I need.
I'm curious to see how your solution looks like.
Thanks
I'd add that in as a feature in a new MR.
Reopening this issue so I can link it