-
Notifications
You must be signed in to change notification settings - Fork 536
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
Give more context about validation path on ValidationException
#1843
Comments
The current vertx-web-openapi implementation is lacking compared to the prior vertx-web-api-contract. There is no indication of what field in the body caused the validation error, and no way to obtain it from the underlying api-contract produced this error: "$.field1: must be at least 1 characters long" |
The nesting of error system in the new validation library is:
In this Do you have any particular suggestions about that? Maybe it's just a lack of docs? Or should we have better helpers?
I honestly never noticed it, but I believe this is more a problem of the correct toString() implementations. That should be trivial to fix 😄 |
As far as I have observed (correct me if I'm wrong), the JSON pointer in the So maybe this is a bug rather than a feature request? |
I'm admittedly not familiar with the code, but I tried to pull information from the |
I am adding the custom response body in an error handler on the router, so I am having access to the What is the
What I really need is more than the local information provided by |
|
In the case of failing a minimum-length constraint, for example, input is |
The schema scope also doesn't help in that case. If I am working with a simple schema, I could try to derive the location of the validation failure by matching the keyword in the validation schema. But if we suppose that the schema is more complex (like in my case) the keyword, input and schema scope alone may not be sufficient to distinguish the concrete location of the error. (like when, for example, two different fields in the request body have the same value, then |
Ok I get your concerns, so I guess what we miss on the vertx-json-schema side is the ability to "trace" the execution of the validator, so when it fails, it's able to return a json pointer expliciting where it failed. I've opened an issue for that eclipse-vertx/vertx-json-schema#32 |
@mwm-twx @Traderjoe95 I've drafted an implementation in json schema, do you want to try out? eclipse-vertx/vertx-json-schema#37 |
The PR in vertx-json-schema was merged, so i consider this done. Reopen if you need it |
Describe the feature
When validating properties of an object or items of an array (in a request body), add more context on where the validation failed. That information should preferably returned in form of a
JsonPointer
.At the moment, the property path taken in validation can't be derived from the
ValidationException
as it never carries that information, not event in thescope
property which is always set to the root schema.Use cases
For the consumer of a REST API dealing with error responses, it is necessary to know where exactly the error happened. Therefore, the pointer to the specific element failing validation should be returned in the error response.
Contribution
I am not yet custom with the internal structure of Vert.x validation, so I think I wouldn't be the best person to implement this. However, I might find some time to deep dive into it, but I can't guarantee it. So if anyone else from the community is able to implement this, feel free to take over.
The text was updated successfully, but these errors were encountered: