Skip to content

Whitelist or blacklist paths #6

Description

@oneEyedSunday

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions