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

Support jsonschema >= 3.0.0 #1050

Merged
merged 2 commits into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
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
23 changes: 19 additions & 4 deletions connexion/decorators/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import logging
import sys

import pkg_resources
import six
from jsonschema import Draft4Validator, ValidationError, draft4_format_checker
from jsonschema.validators import extend
from werkzeug.datastructures import FileStorage

from ..exceptions import ExtraParameterProblem
Expand All @@ -14,6 +16,10 @@
from ..problem import problem
from ..utils import all_json, boolean, is_json_mimetype, is_null, is_nullable

_jsonschema_3_or_newer = pkg_resources.parse_version(
pkg_resources.get_distribution("jsonschema").version) >= \
pkg_resources.parse_version("3.0.0")

logger = logging.getLogger('connexion.decorators.validation')

TYPE_MAP = {
Expand Down Expand Up @@ -245,10 +251,19 @@ def validate_parameter(parameter_type, value, param, param_name=None):
del param['required']
try:
if parameter_type == 'formdata' and param.get('type') == 'file':
Draft4Validator(
param,
format_checker=draft4_format_checker,
types={'file': FileStorage}).validate(converted_value)
if _jsonschema_3_or_newer:
extend(
Draft4Validator,
type_checker=Draft4Validator.TYPE_CHECKER.redefine(
"file",
lambda checker, instance: isinstance(instance, FileStorage)
)
)(param, format_checker=draft4_format_checker).validate(converted_value)
else:
Draft4Validator(
param,
format_checker=draft4_format_checker,
types={'file': FileStorage}).validate(converted_value)
else:
Draft4Validator(
param, format_checker=draft4_format_checker).validate(converted_value)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def read_version(package):

install_requires = [
'clickclick>=1.2',
'jsonschema>=2.5.1,<3.0.0',
'jsonschema>=2.5.1',
'PyYAML>=5.1',
'requests>=2.9.1',
'six>=1.9',
Expand Down