Fix compatibility with jsonschema >= 4.0.0

Fedora Rawhide (to be 37) packages jsonschema 4.9.0 at the moment, so we
can no longer get by with limiting the requirements. This patch makes
the validation work with both old and new version.

Fixes: rhbz#2113607
Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2022-08-09 15:10:38 +02:00
parent 778dcfa587
commit 0abf937b0e
2 changed files with 12 additions and 2 deletions

View File

@ -229,7 +229,6 @@ def validate(config, offline=False, schema=None):
)
validator = DefaultValidator(
schema,
{"array": (tuple, list), "regex": six.string_types, "url": six.string_types},
)
errors = []
warnings = []
@ -445,6 +444,16 @@ def _extend_with_default_and_alias(validator_class, offline=False):
context=all_errors,
)
def is_array(checker, instance):
return isinstance(instance, (tuple, list))
def is_string_type(checker, instance):
return isinstance(instance, six.string_types)
type_checker = validator_class.TYPE_CHECKER.redefine_many(
{"array": is_array, "regex": is_string_type, "url": is_string_type}
)
return jsonschema.validators.extend(
validator_class,
{
@ -455,6 +464,7 @@ def _extend_with_default_and_alias(validator_class, offline=False):
"additionalProperties": _validate_additional_properties,
"anyOf": _validate_any_of,
},
type_checker=type_checker,
)

View File

@ -3,7 +3,7 @@ dict.sorted
dogpile.cache
fedmsg
funcsigs
jsonschema < 4.0.0
jsonschema
kobo
koji
lxml