Skip to content

Replace definitions with $defs in JSON Schema artifact#109

Draft
gaurav wants to merge 9 commits into
mainfrom
update-linkml
Draft

Replace definitions with $defs in JSON Schema artifact#109
gaurav wants to merge 9 commits into
mainfrom
update-linkml

Conversation

@gaurav

@gaurav gaurav commented Sep 14, 2021

Copy link
Copy Markdown
Collaborator

This PR replaces the use of definitions with $defs in 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.

@gaurav gaurav changed the base branch from rename-codeable-concept-to-enum to main September 16, 2021 21:39
Comment thread tests/test_validate_artifacts.py Outdated
assert_that(json_schema).is_not_empty()

# Idea from https://github.com/Julian/jsonschema/issues/348#issuecomment-647418176
class SaferDraft202012Validator(jsonschema.Draft202012Validator):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gaurav: is there any specific reason why we want to use this SaferDraft202012Validator class rather than just Draft202012Validator or Draft7Validator?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@sujaypatil96 sujaypatil96 Sep 22, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants