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

More consistent path for ValidationMessage? #615

Closed
ppazos opened this issue Oct 16, 2022 · 3 comments
Closed

More consistent path for ValidationMessage? #615

ppazos opened this issue Oct 16, 2022 · 3 comments

Comments

@ppazos
Copy link

ppazos commented Oct 16, 2022

I'm using 1.0.73 and doing some unit tests with JSON validation.

For the $.xxxx: is missing but it is required kind of error, the ValidationMessage.path is $

For the $.x.y: integer found, string expected kind of error, the ValidationMessage.path is $.x.y

Shouldn't the path for the is missing but it is required error be $.xxxx, which is the missing key instead of $ which is the parent object?

In unit tests when that kind of error is expected, but there are other ValidationMessage in the error set, it's difficult to find the error expected at a certain path since the returned path is for the parent, not for where the value is required and missing.

I need to test other cases to know if there is any other difference with the paths there.

Thanks.

@stevehu
Copy link
Contributor

stevehu commented Oct 17, 2022

@ppazos Thanks a lot for pointing it out. Different validators are mixed together to form a tree structure, and sometimes, the path for the error message is confusing due to the parent and child relationship. As the error message is constructed in each validator, we can fix it once the issue is identified. We do have some issues that are not resolvable as the children's path is not available for some of the validators, but the cases are limited.

@ppazos
Copy link
Author

ppazos commented Oct 17, 2022

Thanks @stevehu ! The one that I have identified for now is just the missing but required error. For that error if you check the ValidationMessage.arguments you will see the name of the missing attribute there, so I think in those cases it would be easy to add the name to the path so the error has the path to the missing attribute instead of the path to the parent.

I'm still verifying different types of errors on my library, if I found other errors with paths that I wouldn't expect, I'll report back.

Thanks again for your kind message.

@stevehu
Copy link
Contributor

stevehu commented Apr 18, 2023

There is a related issue that is resolved at #687

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