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

Use latest jsonschema version v4.18 or higher #1521

Open
shahzebsiddiqui opened this issue Jul 6, 2023 · 1 comment
Open

Use latest jsonschema version v4.18 or higher #1521

shahzebsiddiqui opened this issue Jul 6, 2023 · 1 comment

Comments

@shahzebsiddiqui
Copy link
Member

According to https://github.com/python-jsonschema/jsonschema/releases/tag/v4.18.0 the RefResolver has been deprecated in favor of referencing library which requires a bit of work to change the codebase. This will impact the way we call custom_validator method

resolver = RefResolver.from_schema(
schema_table["definitions.schema.json"]["recipe"], store=schema_store
)
def custom_validator(recipe, schema):
"""This is a custom validator for validating JSON documents. We implement a
custom resolver using `RefResolver <https://python-jsonschema.readthedocs.io/en/stable/references/#jsonschema.RefResolver>`_
to find schemas locally in order to validate buildspecs with schema files on local filesystem. This ensures changes to
schema can be done in sync with change to code base.
This method uses `Draft7Validator <https://python-jsonschema.readthedocs.io/en/stable/validate/#jsonschema.Draft7Validator>`_
for validating schemas. If there is an error during validation jsonschema will raise an exception of type
`jsonschema.exceptions.ValidationError <https://python-jsonschema.readthedocs.io/en/stable/errors/#jsonschema.exceptions.ValidationError>`_
Args:
recipe (dict): Loaded test recipe as YAML document
schema (dict): Schema document loaded in JSON format
Raises:
jsonschema.exceptions.ValidationError: if recipe fails to validate with schema
"""
# making sure input recipe and schema are dictionary
assert isinstance(recipe, dict)
assert isinstance(schema, dict)
validator = Draft7Validator(schema, resolver=resolver)
validator.validate(recipe)

@Mariamajib
Copy link
Collaborator

According to https://github.com/python-jsonschema/jsonschema/releases/tag/v4.18.0 the RefResolver has been deprecated in favor of referencing library which requires a bit of work to change the codebase. This will impact the way we call custom_validator method

resolver = RefResolver.from_schema(
schema_table["definitions.schema.json"]["recipe"], store=schema_store
)
def custom_validator(recipe, schema):
"""This is a custom validator for validating JSON documents. We implement a
custom resolver using `RefResolver <https://python-jsonschema.readthedocs.io/en/stable/references/#jsonschema.RefResolver>`_
to find schemas locally in order to validate buildspecs with schema files on local filesystem. This ensures changes to
schema can be done in sync with change to code base.
This method uses `Draft7Validator <https://python-jsonschema.readthedocs.io/en/stable/validate/#jsonschema.Draft7Validator>`_
for validating schemas. If there is an error during validation jsonschema will raise an exception of type
`jsonschema.exceptions.ValidationError <https://python-jsonschema.readthedocs.io/en/stable/errors/#jsonschema.exceptions.ValidationError>`_
Args:
recipe (dict): Loaded test recipe as YAML document
schema (dict): Schema document loaded in JSON format
Raises:
jsonschema.exceptions.ValidationError: if recipe fails to validate with schema
"""
# making sure input recipe and schema are dictionary
assert isinstance(recipe, dict)
assert isinstance(schema, dict)
validator = Draft7Validator(schema, resolver=resolver)
validator.validate(recipe)

upfated

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

No branches or pull requests

2 participants