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

restructure the 'traverse' phase #72

Open karenetheridge opened 2 years ago

karenetheridge commented 2 years ago

see https://github.com/karenetheridge/OpenAPI-Modern/issues/36.

Alter JSM::Document::BUILD so that it evaluates the document against its metaschema with keyword callbacks (for the purpose of populating the resource index).

Specification metaschemas would need to have their resource index entries 'baked in' because we can't evaluate these schemas against themselves until their resource indexes are populated.

Therefore add_schema will need to bootstrap the specification metaschemas on first use.

This may or may not save time; some benchmarking is needed.

karenetheridge commented 1 year ago

This lets us get rid of the traverse phase entirely, which is going to make things a little easier on the openapi front because the way that document is structured is a little different, and we have to jump through hoops to make its 'traverse' sub behave the same way. Also there is a bit of confusion when constructing and validating an openapi document object, whether we report errors in 'instanceLocation' or 'keywordLocation'.

karenetheridge commented 1 year ago

Also, the 'callback' subs in 'evaluate' are going to start producing errors (for checks that can't be represented by the spec metaschema itself), so during the evaluation loop we need to also check the callback return value and use that for short-circuiting decisions.

(This is now done.)

karenetheridge commented 1 year ago

once the problem of bootstrapping specification metaschemas is solved, traverse() can be rewritten simply as an evaluate() where the data instance is the schema and the schema is either extracted out of the schema's $schema keyword or is overridden with metaschema_uri.