-
Notifications
You must be signed in to change notification settings - Fork 49
fix validating array with multiple types #30
Conversation
can you show an example of data that is validated incorrectly by jesse? |
Got failing tests now, so don't merge. About to fix that. |
I'm asking since I have doubts about the fix :) |
Data that would pass but shouldn't:
|
Forget about the fix, it's broken :) |
My guess is that either your schema is invalid (didn't check yet), or your expectations are wrong :) |
I'm pretty sure there is a bug in jesse. |
what? how is it possible that validate/3 throws exceptions and validate_with_state/3 doesn't even when validate/3 calls validate_with_state/3 internally? :) validate_with_state/3 will call jesse_validator_draft3:check_value/3 which can throw an exception. btw, have you set allowed_errors to something but 0? :) I'm asking because I think I found the problem |
Nah, you're right, I found out too in the meantime, validate_with_state can throw errors, but just look at what validate does: it takes the result from validate_with_state and passes it to result/1 which throws an error if any. About allowed_errors, I need to check. I've got to catch a plane now, so won't get back before Monday probably. And yeah, things are more complicated than I thought initially. ;) |
Oh, you're right, allowed_errors is set to 5 |
fbb4d18
to
82d1354
Compare
OK, then the problem is actually here: https://github.com/klarna/jesse/blob/master/src/jesse_validator_draft3.erl#L284 the original state will be passed here (it has allowed_errors == 5), and validate_with_state/3 won't throw any exceptions because of that, so what we really want to do here is to call validate_with_state/3 either with a new default state (with allowed_errors == 0), or with the original state, but with changed allowed_errors to 0. Do you follow? :) |
Yes, it starts to make sense now :D |
I'll have a look later today. |
82d1354
to
b48ba5f
Compare
I've changed the pull request by adding a set_allowed_errors to jesse_state, but haven't tested yet with my specific case. And now I really have to get on that damn plane 👯 |
have a nice flight! :) |
it does fix the issue! I'll merge it soon, just want to do some more checks. |
Unfortunately this doesn't fix the issue completely. Now I get validation errors like
My actual schema is a bit different then the one from above, ie. data to validate looks like
so please don't be confused about 'paths' used. Maybe this is because 'additionalItems: false' doesn't get the correct 'state' with the items already validated? |
could you please create a new issue and include the following:
thanks in advance! |
will do |
When validating a schema like
jesse would just accept any types for items in array. This fixes that situation as results from validation are actually evaluated.