mirror of
https://github.com/correl/openapi-core.git
synced 2024-11-22 03:00:10 +00:00
Request and response data validation process refac
This commit is contained in:
parent
7da1ea6b77
commit
faa8164f9a
2 changed files with 52 additions and 58 deletions
|
@ -114,12 +114,12 @@ class RequestValidator(object):
|
|||
except OpenAPIParameterError as exc:
|
||||
errors.append(exc)
|
||||
continue
|
||||
else:
|
||||
try:
|
||||
casted = self._cast(param, deserialised)
|
||||
except CastError as exc:
|
||||
errors.append(exc)
|
||||
continue
|
||||
|
||||
try:
|
||||
casted = self._cast(param, deserialised)
|
||||
except CastError as exc:
|
||||
errors.append(exc)
|
||||
continue
|
||||
|
||||
try:
|
||||
unmarshalled = self._unmarshal(param, casted)
|
||||
|
@ -132,38 +132,35 @@ class RequestValidator(object):
|
|||
return RequestParameters(**locations), errors
|
||||
|
||||
def _get_body(self, request, operation):
|
||||
errors = []
|
||||
|
||||
if operation.request_body is None:
|
||||
return None, errors
|
||||
return None, []
|
||||
|
||||
body = None
|
||||
try:
|
||||
media_type = operation.request_body[request.mimetype]
|
||||
except InvalidContentType as exc:
|
||||
errors.append(exc)
|
||||
else:
|
||||
try:
|
||||
raw_body = operation.request_body.get_value(request)
|
||||
except MissingRequestBody as exc:
|
||||
errors.append(exc)
|
||||
else:
|
||||
try:
|
||||
deserialised = self._deserialise(media_type, raw_body)
|
||||
except InvalidMediaTypeValue as exc:
|
||||
errors.append(exc)
|
||||
else:
|
||||
try:
|
||||
casted = self._cast(media_type, deserialised)
|
||||
except CastError as exc:
|
||||
errors.append(exc)
|
||||
else:
|
||||
try:
|
||||
body = self._unmarshal(media_type, casted)
|
||||
except (ValidateError, UnmarshalError) as exc:
|
||||
errors.append(exc)
|
||||
return None, [exc, ]
|
||||
|
||||
return body, errors
|
||||
try:
|
||||
raw_body = operation.request_body.get_value(request)
|
||||
except MissingRequestBody as exc:
|
||||
return None, [exc, ]
|
||||
|
||||
try:
|
||||
deserialised = self._deserialise(media_type, raw_body)
|
||||
except InvalidMediaTypeValue as exc:
|
||||
return None, [exc, ]
|
||||
|
||||
try:
|
||||
casted = self._cast(media_type, deserialised)
|
||||
except CastError as exc:
|
||||
return None, [exc, ]
|
||||
|
||||
try:
|
||||
body = self._unmarshal(media_type, casted)
|
||||
except (ValidateError, UnmarshalError) as exc:
|
||||
return None, [exc, ]
|
||||
|
||||
return body, []
|
||||
|
||||
def _deserialise(self, param_or_media_type, value):
|
||||
return param_or_media_type.deserialise(value)
|
||||
|
|
|
@ -65,38 +65,35 @@ class ResponseValidator(object):
|
|||
return ResponseValidationResult(data_errors, data, None)
|
||||
|
||||
def _get_data(self, response, operation_response):
|
||||
errors = []
|
||||
|
||||
if not operation_response.content:
|
||||
return None, errors
|
||||
return None, []
|
||||
|
||||
data = None
|
||||
try:
|
||||
media_type = operation_response[response.mimetype]
|
||||
except InvalidContentType as exc:
|
||||
errors.append(exc)
|
||||
else:
|
||||
try:
|
||||
raw_data = operation_response.get_value(response)
|
||||
except MissingResponseContent as exc:
|
||||
errors.append(exc)
|
||||
else:
|
||||
try:
|
||||
deserialised = self._deserialise(media_type, raw_data)
|
||||
except InvalidMediaTypeValue as exc:
|
||||
errors.append(exc)
|
||||
else:
|
||||
try:
|
||||
casted = self._cast(media_type, deserialised)
|
||||
except CastError as exc:
|
||||
errors.append(exc)
|
||||
else:
|
||||
try:
|
||||
data = self._unmarshal(media_type, casted)
|
||||
except (ValidateError, UnmarshalError) as exc:
|
||||
errors.append(exc)
|
||||
return None, [exc, ]
|
||||
|
||||
return data, errors
|
||||
try:
|
||||
raw_data = operation_response.get_value(response)
|
||||
except MissingResponseContent as exc:
|
||||
return None, [exc, ]
|
||||
|
||||
try:
|
||||
deserialised = self._deserialise(media_type, raw_data)
|
||||
except InvalidMediaTypeValue as exc:
|
||||
return None, [exc, ]
|
||||
|
||||
try:
|
||||
casted = self._cast(media_type, deserialised)
|
||||
except CastError as exc:
|
||||
return None, [exc, ]
|
||||
|
||||
try:
|
||||
data = self._unmarshal(media_type, casted)
|
||||
except (ValidateError, UnmarshalError) as exc:
|
||||
return None, [exc, ]
|
||||
|
||||
return data, []
|
||||
|
||||
def _get_headers(self, response, operation_response):
|
||||
errors = []
|
||||
|
|
Loading…
Reference in a new issue