jhthorsen / json-validator

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

api for loading, resolving schemas is incomplete #204

Closed karenetheridge closed 3 years ago

karenetheridge commented 4 years ago

This is a placeholder issue that I expect to be resolved when the new ::Schema interface(s) are ironed out -- just to keep track of an issue I am running into so it is not forgotten --

if I wnat to validate a document againt a URL, I need to load it myself:

my $schema = $ua->get($url);
$jv->validate($data, $schema);

...but then I lose the benefits of the caching that is done in _load_schema_from_url (e.g. if I want to validate against the draft07 spec itself). The only alternative is to call $jv->load_and_validate_schema($url) or $jv->schema($url) which wipes out the previous schema I have stored in the $jv object. Ideally I'd like to have multiple schemas cached in a single JV, so I don't have to switch objects or re-load schemas unnecessarily.

I suspect that many of these internal methods (load*, _resolve, etc) should be made public, perhaps cleaning them up a bit to add more error checking etc. I have been reading the draft07 spec on how schema documents should be parsed, which is basically writing the new api for us :)

jhthorsen commented 4 years ago

Maybe you can see what happend in #209 and see if there's something you can use/build on there?

jhthorsen commented 3 years ago

I'm pretty sure this is fixed in 792ac03f0be737a8d8096939b95bc978e84756f9.