Skip to content

Commit

Permalink
remove jsonschema version constrain (#287)
Browse files Browse the repository at this point in the history
* remove jsonschema version constrain

* Use referencing library

* Fix lint

* Fix lint

* update schema validatoin code
  • Loading branch information
sameeul authored Nov 12, 2024
1 parent 61abb94 commit 441b1a0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies = [
# This 'graphviz' is equivalent to `conda install python-graphviz` or
# `sudo apt install python3-graphviz` ONLY.
"graphviz",
"jsonschema<4.18", # temporarily downgrade due to severe performance regression
"jsonschema",
"pyyaml",
"requests",
"mergedeep",
Expand All @@ -42,7 +42,8 @@ dependencies = [
"toil[cwl]",
"fastapi",
"python-jose",
"uvicorn"
"uvicorn",
"referencing"
]

[project.readme]
Expand Down
13 changes: 9 additions & 4 deletions src/sophios/schemas/wic_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

import networkx as nx
import graphviz
from jsonschema import RefResolver, Draft202012Validator
from jsonschema import Draft202012Validator
from referencing import Registry, Resource
from referencing.jsonschema import DRAFT202012
import yaml

import sophios
Expand Down Expand Up @@ -680,7 +682,6 @@ def get_validator(tools_cwl: Tools, yml_stems: List[str], schema_store: Dict[str

schema = wic_main_schema(tools_cwl, yml_stems, schema_store, hypothesis)
schema_store[schema['$id']] = schema
schema_store['wic_tag'] = wic_tag_schema(hypothesis)
if write_to_disk:
with open('autogenerated/schemas/wic.json', mode='w', encoding='utf-8') as f:
f.write(json.dumps(schema, indent=2))
Expand All @@ -696,7 +697,11 @@ def get_validator(tools_cwl: Tools, yml_stems: List[str], schema_store: Dict[str
# The $ref tag refers to URIs defined in $id tags, NOT relative paths on
# the local filesystem! We need to create a global mapping between ids and schemas
# i.e. schema_store.
resolver = RefResolver.from_schema(schema, store=schema_store)
schema_store_resource: Resource = Resource(contents=schema_store, specification=DRAFT202012) # type: ignore
registry: Registry = Registry().with_resource(uri="wic_schema_store", resource=schema_store_resource)
wic_tag_schema_resource: Resource = Resource(contents=wic_tag_schema(
hypothesis), specification=DRAFT202012) # type: ignore
registry = registry.with_resource(uri="wic_tag", resource=wic_tag_schema_resource)
""" Use check_schema to 'first verify that the provided schema is
itself valid, since not doing so can lead to less obvious error
messages and fail in less obvious or consistent ways.'
Expand All @@ -707,5 +712,5 @@ def get_validator(tools_cwl: Tools, yml_stems: List[str], schema_store: Dict[str
# try temporarily commenting this line out to generate the schema anyway.
# Then, in any yml file, the very first line should show a "schema stack trace"
Draft202012Validator.check_schema(schema)
validator = Draft202012Validator(schema, resolver=resolver)
validator = Draft202012Validator(schema, registry=registry)
return validator

0 comments on commit 441b1a0

Please sign in to comment.