diff --git a/openapi_core/schema/media_types/models.py b/openapi_core/schema/media_types/models.py index ba31ef1..69cceba 100644 --- a/openapi_core/schema/media_types/models.py +++ b/openapi_core/schema/media_types/models.py @@ -1,9 +1,8 @@ """OpenAPI core media types models module""" from collections import defaultdict -from json import loads - from openapi_core.schema.media_types.exceptions import InvalidMediaTypeValue +from openapi_core.schema.media_types.util import json_loads from openapi_core.schema.schemas.exceptions import ( CastError, ValidateError, ) @@ -11,7 +10,7 @@ from openapi_core.unmarshalling.schemas.exceptions import UnmarshalError MEDIA_TYPE_DESERIALIZERS = { - 'application/json': loads, + 'application/json': json_loads, } diff --git a/openapi_core/schema/media_types/util.py b/openapi_core/schema/media_types/util.py new file mode 100644 index 0000000..e09c1d1 --- /dev/null +++ b/openapi_core/schema/media_types/util.py @@ -0,0 +1,10 @@ +from json import loads + +from six import binary_type + + +def json_loads(value): + # python 3.5 doesn't support binary input fix + if isinstance(value, (binary_type, )): + value = value.decode() + return loads(value)