jhthorsen / json-validator

:cop: Validate data against a JSON schema
https://metacpan.org/release/JSON-Validator
56 stars 58 forks source link

fix oneOf with type => [array] #199

Closed karenetheridge closed 4 years ago

karenetheridge commented 4 years ago

Summary

fixes more edge cases with oneOf

Motivation

Many of the new tests I added will fail without the accompanying code changes.

karenetheridge commented 4 years ago

I have created a separate PR for the first change. That commit is still contained in this PR as the code change is also needed here, but it will rebase away when it is merged to master.

karenetheridge commented 4 years ago

@expected is removed in the _validate_(all|any|one)_of subs because it doesn't actually help anything -- the _validate call already did the type check and returned the proper error, and also schema_type can't return a useful result in the cases where type => .. is a list of types.

We don't actually need to do anything extra at all at the end of these subs if we don't care about joining all the type errors into one -- the code gets much simpler if instead of:

E('/', '/anyOf/1 Expected integer/boolean - got string.');

we can return:

E('/', '/anyOf/1 Expected integer - got string.'),
E('/', '/anyOf/1 Expected boolean - got string.');
jhthorsen commented 4 years ago

Thanks for all the changes 👍