Skip to content

Commit

Permalink
Add compatibility for older jsonschema versions
Browse files Browse the repository at this point in the history
  • Loading branch information
binste committed Dec 25, 2022
1 parent 95cf206 commit 44d8476
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
27 changes: 15 additions & 12 deletions altair/utils/schemapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,21 @@ def validate_jsonschema(*args, **kwargs):

removed_format_checkers = []
try:
# The "uri-reference" checker fails for some of the Vega-Lite
# schemas as URIs in "$ref" are not encoded,
# e.g. '#/definitions/ValueDefWithCondition<MarkPropFieldOrDatumDef,
# (Gradient|string|null)>' would be a valid $ref in a Vega-Lite schema but
# it is not a valid URI reference due to the characters such as '<'.
# This is fine and we can disable this format check below-
for format_name in ["uri-reference"]:
try:
checker = validator_cls.FORMAT_CHECKER.checkers.pop(format_name)
removed_format_checkers.append((format_name, checker))
except KeyError:
continue
# In older versions of jsonschema this attribute did not yet exist
# and we do not need to disable any format checkers
if hasattr(validator_cls, "FORMAT_CHECKER"):
# The "uri-reference" checker fails for some of the Vega-Lite
# schemas as URIs in "$ref" are not encoded,
# e.g. '#/definitions/ValueDefWithCondition<MarkPropFieldOrDatumDef,
# (Gradient|string|null)>' would be a valid $ref in a Vega-Lite schema but
# it is not a valid URI reference due to the characters such as '<'.
# This is fine and we can disable this format check below-
for format_name in ["uri-reference"]:
try:
checker = validator_cls.FORMAT_CHECKER.checkers.pop(format_name)
removed_format_checkers.append((format_name, checker))
except KeyError:
continue
output = jsonschema.validate(*args, **kwargs)
finally:
# Restore the original set of checkers as the jsonschema package
Expand Down
27 changes: 15 additions & 12 deletions tools/schemapi/schemapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,21 @@ def validate_jsonschema(*args, **kwargs):

removed_format_checkers = []
try:
# The "uri-reference" checker fails for some of the Vega-Lite
# schemas as URIs in "$ref" are not encoded,
# e.g. '#/definitions/ValueDefWithCondition<MarkPropFieldOrDatumDef,
# (Gradient|string|null)>' would be a valid $ref in a Vega-Lite schema but
# it is not a valid URI reference due to the characters such as '<'.
# This is fine and we can disable this format check below-
for format_name in ["uri-reference"]:
try:
checker = validator_cls.FORMAT_CHECKER.checkers.pop(format_name)
removed_format_checkers.append((format_name, checker))
except KeyError:
continue
# In older versions of jsonschema this attribute did not yet exist
# and we do not need to disable any format checkers
if hasattr(validator_cls, "FORMAT_CHECKER"):
# The "uri-reference" checker fails for some of the Vega-Lite
# schemas as URIs in "$ref" are not encoded,
# e.g. '#/definitions/ValueDefWithCondition<MarkPropFieldOrDatumDef,
# (Gradient|string|null)>' would be a valid $ref in a Vega-Lite schema but
# it is not a valid URI reference due to the characters such as '<'.
# This is fine and we can disable this format check below-
for format_name in ["uri-reference"]:
try:
checker = validator_cls.FORMAT_CHECKER.checkers.pop(format_name)
removed_format_checkers.append((format_name, checker))
except KeyError:
continue
output = jsonschema.validate(*args, **kwargs)
finally:
# Restore the original set of checkers as the jsonschema package
Expand Down

0 comments on commit 44d8476

Please sign in to comment.