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

Fix for DeprecationWarnings for jsonschema Validator.iter_errors() V2 #1733

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion connexion/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
from .operations import OpenAPIOperation, Swagger2Operation
from .utils import deep_get

try:
from importlib.metadata import version
except ImportError: # Python < 3.10 (backport)
from importlib_metadata import version

from packaging.version import Version

_jsonschema_4_or_newer = Version(version("jsonschema")) >= Version("4.0.0")

validate_properties = Draft4Validator.VALIDATORS["properties"]


Expand All @@ -47,7 +56,11 @@ def validate_defaults(validator, properties, instance, schema):
if not valid:
return
if isinstance(instance, dict) and 'default' in instance:
for error in instance_validator.iter_errors(instance['default'], instance):
if _jsonschema_4_or_newer:
errors = instance_validator.evolve(schema=instance).iter_errors(instance['default'])
else:
errors = instance_validator.iter_errors(instance['default'], instance)
for error in errors:
yield error

SpecValidator = extend_validator(Draft4Validator, {"properties": validate_defaults})
Expand Down
Loading