karenetheridge / JSON-Schema-Modern

Validate data against a schema using a JSON Schema
https://metacpan.org/release/JSON-Schema-Modern/
Other
10 stars 1 forks source link

changing dialects (including specification version) inside a document #80

Closed karenetheridge closed 9 months ago

karenetheridge commented 10 months ago

It's legal for $schema to appear lower down in the document than the root, so long as it's accompanied by an $id which would provide the subschema with an absolute URI for indexing.

However, when traversing the schema for the first time, we treat each keyword in turn, and by the time we encounter $schema, we've already got our list of keywords for the Core vocabulary fixed; if say we change to the draft7 specification, suddenly $anchor is no longer a valid keyword and we should skip it -- or if we switch to draft2019-09, $dynamicRef is no longer valid but now $recursiveRef is.

We need to do some fancy switching of our keyword list just as we do with our vocabulary list in traverse(). Luckily, we consider $id and $schema first, and $id cannot be a fragment (i.e. anchor) if $schema is present, so these are cases we can accomodate.

karenetheridge commented 10 months ago

The other alternative is to just prevent switching specification versions (or even dialects) midway through a document. If we do that, we can move the storage of 'specification_version' and 'vocabulary_classes' from the resource index to the document, which also saves space; we can also remove some of the complications of determining dialects out of the Core vocabulary and into the root implementation (i.e. do it in traverse() rather than _traverse_keyword_schema).

karenetheridge commented 9 months ago

This is now properly fixed as of release 0.575, although some internal optimization could still be done.