Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace definitions with $defs in JSON Schema artifact #109

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

gaurav
Copy link
Collaborator

@gaurav gaurav commented Sep 14, 2021

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
assert_that(json_schema).is_not_empty()

# Idea from https://github.com/Julian/jsonschema/issues/348#issuecomment-647418176
class SaferDraft202012Validator(jsonschema.Draft202012Validator):
Copy link
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
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.

Copy link
Contributor

@sujaypatil96 sujaypatil96 Sep 22, 2021

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