2020-02-03 13:05:44 +00:00
|
|
|
from openapi_core.deserializing.exceptions import DeserializeError
|
|
|
|
from openapi_core.deserializing.parameters.exceptions import (
|
|
|
|
EmptyParameterValue,
|
|
|
|
)
|
2021-04-27 21:39:28 +00:00
|
|
|
from openapi_core.schema.parameters import get_aslist, get_explode, get_style
|
2020-02-03 13:05:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PrimitiveDeserializer(object):
|
|
|
|
|
|
|
|
def __init__(self, param, deserializer_callable):
|
|
|
|
self.param = param
|
|
|
|
self.deserializer_callable = deserializer_callable
|
|
|
|
|
2021-04-23 11:36:27 +00:00
|
|
|
self.aslist = get_aslist(self.param)
|
|
|
|
self.explode = get_explode(self.param)
|
|
|
|
self.style = get_style(self.param)
|
|
|
|
|
2020-02-03 13:05:44 +00:00
|
|
|
def __call__(self, value):
|
2021-04-23 11:36:27 +00:00
|
|
|
style = get_style(self.param)
|
|
|
|
if (self.param['in'] == 'query' and value == "" and
|
|
|
|
not self.param.getkey('allowEmptyValue', False)):
|
2020-02-03 13:05:44 +00:00
|
|
|
raise EmptyParameterValue(
|
2021-04-23 11:36:27 +00:00
|
|
|
value, self.style, self.param['name'])
|
2020-02-03 13:05:44 +00:00
|
|
|
|
2021-04-23 11:36:27 +00:00
|
|
|
if not self.aslist or self.explode:
|
2020-02-03 13:05:44 +00:00
|
|
|
return value
|
|
|
|
try:
|
|
|
|
return self.deserializer_callable(value)
|
2020-02-03 13:41:26 +00:00
|
|
|
except (ValueError, TypeError, AttributeError):
|
2021-04-23 11:36:27 +00:00
|
|
|
raise DeserializeError(value, self.style)
|