Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whitelist or blacklist paths #6

Open
oneEyedSunday opened this issue May 6, 2021 · 3 comments
Open

Whitelist or blacklist paths #6

oneEyedSunday opened this issue May 6, 2021 · 3 comments

Comments

@oneEyedSunday
Copy link

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.

@tiemma
Copy link
Owner

tiemma commented Jul 9, 2021

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?

@oneEyedSunday
Copy link
Author

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.

@tiemma
Copy link
Owner

tiemma commented Aug 16, 2021

Thanks

I'd add that in as a feature in a new MR.

Reopening this issue so I can link it

@tiemma tiemma reopened this Aug 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants