Replace definitions with $defs in JSON Schema artifact#109
Conversation
2a75825 to
bde8ace
Compare
| assert_that(json_schema).is_not_empty() | ||
|
|
||
| # Idea from https://github.com/Julian/jsonschema/issues/348#issuecomment-647418176 | ||
| class SaferDraft202012Validator(jsonschema.Draft202012Validator): |
There was a problem hiding this comment.
@gaurav: is there any specific reason why we want to use this SaferDraft202012Validator class rather than just Draft202012Validator or Draft7Validator?
There was a problem hiding this comment.
Why not Draft7Validator: because it uses definitions rather than $defs, which is what we're trying to move to.
Why not Draft202012Validator: because by default Draft202012Validator sets additionalProperties to true, which makes the validator very permissible -- any property that doesn't validate is assumed to be an additional property, and validation is successful :). In retrospect, we should probably call this LessPermissiveDraft202012Validator or something.
There was a problem hiding this comment.
By the look of it, LinkML seems to be generating JSON Schema that's compatible with the Draft 7 version of JSON Schema. Here's an example personinfo schema.
Or maybe the LinkML JSON Schema generating logic just needs to update the version of the schema standards it's using.
My reading of https://json-schema.org/understanding-json-schema/structuring.html#ref makes me think that other keywords in `$ref` should be ignored by the validator, but this raises an error with the SaferDraft...Validator. So I'm going to remove it for now.
This PR replaces the use of
definitionswith$defsin the JSON Schema artifact by upgrading the version of LinkML we use (incorporating the changes made in response to issue linkml/linkml#305).I've also added a JSON Schema validation test to ensure that the generated JSON Schema is valid -- it currently is not, which I suspect is because of #85. I'll keep working on this PR until it fully validates.
Closes #102.