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

Passing explicit path to middleware instance #36

Open
kibertoad opened this issue Sep 28, 2018 · 4 comments
Open

Passing explicit path to middleware instance #36

kibertoad opened this issue Sep 28, 2018 · 4 comments
Milestone

Comments

@kibertoad
Copy link
Collaborator

Currently middleware itself is responsible for determining path that is currently being accessed (let path = req.baseUrl.concat(req.route.path);). It would be helpful to be able to attach middleware to specific endpoints with predefined swagger path already filled during instantiation.

This is useful for Google Cloud Functions: while they seem to use Express under the hood and in general support swagger-style middleware, you can't attach middleware on app or router level and you don't have access to routing params, making usage of express-ajv-swagger-validation impossible.

Basically API could look like this:

app.post("/echo", validator.validate("post", "/echo"), (req, res, next) => {
  res.json({ output: req.body.input });
});
@kibertoad
Copy link
Collaborator Author

@idanto I could work on this if you think that it makes sense.

@idanto
Copy link
Contributor

idanto commented Oct 4, 2018

@kibertoad sure, I would love to add this feature to the package.
if you do that, please also think about an option to enable validation only for specific routes in the current way we configure it.

@kibertoad
Copy link
Collaborator Author

@idanto But current way is middleware per-route already; why can't user simply comment out or delete middleware for that particular route?

@idanto
Copy link
Contributor

idanto commented Oct 7, 2018

right, haven't thought about it like that. It was more like reading specific routes from the swagger file and not all of them but it's less critical.

feel free to go ahead with just your use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants