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

Install validator on an Express Router #144

Closed
Aidenir opened this issue Nov 26, 2019 · 3 comments
Closed

Install validator on an Express Router #144

Aidenir opened this issue Nov 26, 2019 · 3 comments

Comments

@Aidenir
Copy link

Aidenir commented Nov 26, 2019

We currently have a very large codebase and not everything is documented in our spec doc. So my idea was to introduce this into Routers instead, so we could introduce it on an endpoint basis gradually instead. But unless I install this on the actual app it doesn't appear to do anything what so ever. I've tried going through the code to find any reason for this, but as I'm somewhat new to express I can't find anything in particular that would prevent it from being installed on a router that is later installed on the app itself.

Other libraries allow you to just get the actual middleware function so you can add this yourself to the method handler, but this doesn't appear to be possible with this library either. Any reason for this?

@cdimascio
Copy link
Owner

cdimascio commented Nov 27, 2019

The library must utilize express' app.param([name], callback) in order to ensure path params match those defined in your spec definition. unfortunately, this is only available at the app level and not to middleware functions. this is a key reason why the validator is not implemented as a traditional middleware function.

that being said, i plan to introduce a feature that enables you to provide a regex that can be used to ignore routes. this should make it possible to still benefit from app params, yet also enable for devs (like yourself) to introduce the validator into a large project, where it's difficult to provide doc for all endpoints upfront.

please offer feedback on this and anything else related to this project. all in all, i want to ensure this provides a great experience for devs.

@cdimascio
Copy link
Owner

cdimascio commented Nov 27, 2019

This issue is related to Add ability to ignore validation on routes to avoid 404 status for undocumented routes (issue #141 and PR #157)

The assumption here is that by providing a mechanism to ignore validation on paths, we can make it possible to gradually introduce express-openapi-validator into a large codebase.

@cdimascio
Copy link
Owner

cdimascio commented Nov 27, 2019

Closing this out as I believe #157 provides what is needed.
Please reopen if not the case.

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