-
-
Notifications
You must be signed in to change notification settings - Fork 242
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
fully_validate
// anyOf
, typeOf
, allOf
don't raise validation errors when using record_errors: true
#300
Comments
Sorry, I feel like I'm missing something! Can you please explain again what behaviour you're seeing? And what you would expect to see? An example schema and json text that reproduces the problem would also be helpful |
Hey @iainbeeston! Really sorry for the cryptic message. It was super late on my end, I should have re-read it! Schema: https://gist.github.com/thewatts/8d7802af38c1a05ff2e4#file-schema-json Current Behavior:Running JSON::Schema::ValidationError:
The property '#/registration' of type Hash did not match any of the required schemas in schema 4c0ec013-5c14-5fe6-a148-2f81fc4075f0 Which is great! That's to be expected. However, I want to have the validation error still raise - but also know why validation broke, ex: JSON::Schema::ValidationError:
The property '#/registration' of type Hash did not match any of the required schemas. The schema specific errors were:
- oneOf #0:
- The property '#/registration' of type Hash did not match the following type: null
- oneOf #1:
- The property '#/registration' did not contain a required property of 'check_in' After some sleep - I realize now that adding the options Expected:I suppose I expected that adding the |
@iainbeeston - is there a way to currently do this? Or is this perhaps in the roadmap? If not - no worries. Just making sure I fully understand :) Thanks! ( And thanks for this killer gem! Using it as a validator for my API has vastly improved the way I test! ) |
It sounds like we have the correct behaviour when record_errors is true, but we should also use the same information when we raise errors (when record_errors is false). It appears that we already have the information available but we're not using it in exceptions. If you want that behaviour right now I'd suggest making a wrapper class for json schema that sets record_errors to true then raising an exception if any errors are returned. I'm afraid it's not on the roadmap as yet but if you have the time to make a pull request to add this feature I'd happily take a look. |
@iainbeeston when There are a couple things:
We'd have to make an adjustment in both places, as well as adjust |
Took me forever to figure out why the validation errors weren't getting added into the
errors
hash in the attribute validations. Ex: https://github.com/ruby-json-schema/json-schema/blob/master/lib/json-schema/attributes/anyof.rb#L31Partial solution: The
record_errors: true
option needs to be passed into thevalidate!
method.This will now add those errors and assign them as
sub_errors
here: https://github.com/ruby-json-schema/json-schema/blob/master/lib/json-schema/attributes/anyof.rb#L42The only kicker - is that the validation then is never raised, even though validation doesn't pass.
This is because https://github.com/ruby-json-schema/json-schema/blob/master/lib/json-schema/attributes/anyof.rb#L42 just returns a hash.
What line do I need to add to these files so that I can raise a validation error w/ its sub-errors?
I see that the
ValidationError
class has ato_string
method, which I could use to override themessage
method forValidationError
, and then call this after line42
:This fixes my validation problem, but breaks the error output for the test suite.
Am I missing something?
The text was updated successfully, but these errors were encountered: