-
Notifications
You must be signed in to change notification settings - Fork 92
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
Register custom request/response validators #171
Comments
As part of adding strict mode validation (#94), |
Added support for performing custom request/response validation by passing in an `options` object as the optional second parameter to `Operation#validateRequest`, `Operation#validateResponse` and `Response#validateResponse` with a `customValidators` property containing an `Array` of `Function` objects. _(Please review the documentation for more details.)_ Fixes #171
Hi Jeremy, Thank you! |
The |
Thank you for the fast response and the hints. The support for OAS@v3.x as it is right now, it works for me. I know it's WIP but it's pretty decent as it is.
Maybe it would be a useful thing to expose some of the helper functions to the outside? Like validateAgainstSchema or getJSONSchemaValidator. That way I don't need to specifically add the z-schema package to my package.json and just use the resources that are already available in sway and are statically typed to some degree. Let me know if maybe you see another way to do this, that I have maybe missed out. Thanks again for all the effort, and I hope at some point to maybe contribute to this awesome project. |
Why do you need to do custom body validation? |
I failed to specifically mention that I'm using OAS@3.x for my schemes. What you say I think this is valid for Swagger 2.0 schemes only. In Swagger 2.0 you define the request body in the parameters with in:body. But for OAS 3.0@x you define them in requestBody, a sibling property of parameters. Looking inside the implementation of validateRequest I saw that the validation for the body is done together with all the other parameters. So for each definitionFullyResolved.parameters I would suspect to have the req.body correctly validated here if only the schema was of type Swagger 2.0. Let me know if I'm missing something. |
sway
already has the ability to register custom validators for the full Swagger 2.0 document but it does not include the ability to register custom request/response validators. This needs to be done.Originally reported in #170.
The text was updated successfully, but these errors were encountered: