swagger-tools
swagger-tools copied to clipboard
Return all validation errors, instead of just the first one
It would be very useful, if there was a way to instruct the swagger validator to return all validation errors, instead of just the first occurance. For example:
With a following schema:
/search:
get:
parameters:
- name: firstName
in: query
required: true
type: string
- name: lastName
in: query
type: string
required: true
if a call is made to /search without any query parameters, I'd like the validator to identify both firstName and lastName as missing, as opposed to only firstName.
Would there be an appetite for such feature? I'd be happy to take a stab at a PR.
This is a great idea. We already do this when validating the spec but we do not do it when we manually validate a schema.
Do I understand correctly, that the spec validation process you referred to applies to loading the definitions (as during the application start up) as opposed to request/response validation (as in with the validator middleware)?
Validating the spec validates that your Swagger document is valid itself. When the middleware does request/response validation, it uses a similar approach but not the exact same logic. I think the reason this is happening is because we're throwing an Error to indicate that a parameter failed validation (to quick fail) instead of always validating all parameters and returning the array of failures.
When I rewrote the API in sway, you'll see that it handles this as you'd expect by validating every parameter regardless of whether a previous parameter had failed. In swagger-tools, you'll see that we do not do this as a failure validating a parameter throws an Error and we no longer process the remaining parameters.
This can be fixed pretty easily.
I'd love to see this feature added. Would you like to see a pull request for this or rather write it yourself given you have a good idea of how to do it?
I could do it pretty quickly but a PR would expedite things.
Hi, I'm also interested in this feature. Any news on it ?
I've not made much progress on it. I rewrote json-refs and I'm in the process of getting swagger-tools and sway updated to the latest json-refs first. Then I'll fix bugs and cut releases.
Does a PR make any sense or will it be a waste of time due to swagger-tools and sway update ?
PRs are always welcome. The changes I need to make for json-refs won't touch this code so it would be without conflict. My typical release process is this:
- Update dependencies
- Fix bugs (within reason)
- Cut release
Hi, Any update on this feature? I really want this feature with swagger-tools.