summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2022-11-21 10:31:01 +0000
committerGerrit Code Review <review@openstack.org>2022-11-21 10:31:01 +0000
commit012b7c5aa901b220479da2a71bb6005edd0506e1 (patch)
tree2c17e4aebb345d26ed0a05a13aa3e7044cf865c3
parent299c2afe14e2bc7e33794bdf89c7da2e191f7b2a (diff)
parent4bd0ab33272064cc4e44fe2d652ecf7a11b07274 (diff)
downloadtaskflow-012b7c5aa901b220479da2a71bb6005edd0506e1.tar.gz
Merge "Adapt to new jsonschema versions"
-rw-r--r--taskflow/utils/schema_utils.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/taskflow/utils/schema_utils.py b/taskflow/utils/schema_utils.py
index 8d7c216..7f6b52d 100644
--- a/taskflow/utils/schema_utils.py
+++ b/taskflow/utils/schema_utils.py
@@ -17,12 +17,6 @@
import jsonschema
from jsonschema import exceptions as schema_exc
-# Special jsonschema validation types/adjustments.
-_SCHEMA_TYPES = {
- # See: https://github.com/Julian/jsonschema/issues/148
- 'array': (list, tuple),
-}
-
# Expose these types so that people don't have to import the same exceptions.
ValidationError = schema_exc.ValidationError
@@ -31,4 +25,11 @@ SchemaError = schema_exc.SchemaError
def schema_validate(data, schema):
"""Validates given data using provided json schema."""
- jsonschema.validate(data, schema, types=_SCHEMA_TYPES)
+ Validator = jsonschema.validators.validator_for(schema)
+ # Special jsonschema validation types/adjustments.
+ # See: https://github.com/Julian/jsonschema/issues/148
+ type_checker = Validator.TYPE_CHECKER.redefine(
+ "array", lambda checker, data: isinstance(data, (list, tuple)))
+ TupleAllowingValidator = jsonschema.validators.extend(
+ Validator, type_checker=type_checker)
+ TupleAllowingValidator(schema).validate(data)