Skip to content

Commit

Permalink
rename from serialization/deserializers to content_types
Browse files Browse the repository at this point in the history
  • Loading branch information
dtkav committed Dec 12, 2019
1 parent 2494326 commit fd89862
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@

from jsonschema import ValidationError

from ..exceptions import ExtraParameterProblem, BadRequestProblem
from ..problem import problem
from ..types import coerce_type
from ..utils import is_null
from .exceptions import ExtraParameterProblem, BadRequestProblem
from .types import coerce_type
from .utils import is_null

logger = logging.getLogger('connexion.serialization.deserializers')
logger = logging.getLogger('connexion.content_types')


class ContentHandler(object):
Expand Down Expand Up @@ -120,7 +119,7 @@ class MultiPartFormDataContentHandler(FormDataContentHandler):
)


DEFAULT_DESERIALIZERS = (
KNOWN_CONTENT_TYPES = (
StreamingContentHandler,
JSONContentHandler,
FormDataContentHandler,
Expand Down
12 changes: 8 additions & 4 deletions connexion/decorators/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from ..exceptions import ExtraParameterProblem, BadRequestProblem, UnsupportedMediaTypeProblem
from ..http_facts import FORM_CONTENT_TYPES
from ..json_schema import Draft4RequestValidator, Draft4ResponseValidator
from ..serialization.deserializers import DEFAULT_DESERIALIZERS
from ..content_types import KNOWN_CONTENT_TYPES
from ..types import TypeValidationError, coerce_type
from ..utils import all_json, boolean, is_json_mimetype, is_null, is_nullable

Expand Down Expand Up @@ -56,7 +56,7 @@ def __init__(self, schema, consumes, api, is_null_value_valid=False, validator=N
de(self.validator,
self.schema,
self.strict_validation,
self.is_null_value_valid) for de in DEFAULT_DESERIALIZERS
self.is_null_value_valid) for de in KNOWN_CONTENT_TYPES
]

def register_content_handler(self, cv):
Expand All @@ -69,7 +69,8 @@ def register_content_handler(self, cv):
def lookup_content_handler(self, request):
matches = [
v for v in self._content_handlers
if v.regex.match(request.content_type)
if request.content_type is not None and
v.regex.match(request.content_type)
]
if len(matches) > 1:
logger.warning("Content could be handled by multiple validators")
Expand All @@ -85,7 +86,10 @@ def __call__(self, function):
@functools.wraps(function)
def wrapper(request):
content_handler = self.lookup_content_handler(request)
exact_match = request.content_type in self.consumes
exact_match = (
request.content_type is not None and
request.content_type in self.consumes
)
partial_match = content_handler and content_handler.name in self.consumes
if not (exact_match or partial_match):
raise UnsupportedMediaTypeProblem(
Expand Down
Empty file.

0 comments on commit fd89862

Please sign in to comment.