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

validation_errors returns [] after running validation #506

Open
exterm opened this issue Oct 25, 2023 · 1 comment
Open

validation_errors returns [] after running validation #506

exterm opened this issue Oct 25, 2023 · 1 comment

Comments

@exterm
Copy link

exterm commented Oct 25, 2023

It seems that in version 4.1.1, JSON::Validator#validation_errors always returns []. I think it's due to the @errors attribute being reset during validation:

.

To reproduce:

schema = { type: "string" }

v = JSON::Validator.new(schema, record_errors: true)
v.validate(1)
v.validation_errors

We previously used validation_errors to get to the error objects and be able to call .message on them, which yields a nicer error message for anonymous schemas (without URI). Now that seems no longer possible, and in addition the validation_errors method seems useless.

@exterm
Copy link
Author

exterm commented Oct 25, 2023

Our problem would be solved by either restoring the way record_errors worked before, or adding an option that makes validate return the error objects, or by adding an option to omit the (generated) schema URI from the error messages.

I'm happy to put up a PR but am not sure which solution is preferred.

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

1 participant