Skip to content
Prev Previous commit
Next Next commit
Handles schema = None case
  • Loading branch information
spacether committed Apr 13, 2022
commit d6cd2d7cd27fb4cb0281ee4b44b4ccb49b482852
Original file line number Diff line number Diff line change
Expand Up @@ -803,12 +803,27 @@ class OpenApiResponse(JSONDetector):
content_type = response.getheader('content-type')
deserialized_body = unset
streamed = response.supports_chunked_reads()

deserialized_headers = unset
if self.headers is not None:
# TODO add header deserialiation here
pass

if self.content is not None:
if content_type not in self.content:
raise ApiValueError(
f'Invalid content_type={content_type} returned for response with '
'status_code={str(response.status)}'
)
body_schema = self.content[content_type].schema
if body_schema is None:
# some specs do not define response content media type schemas
return self.response_cls(
response=response,
headers=deserialized_headers,
body=unset
)

if self.content_type_is_json(content_type):
body_data = self.__deserialize_json(response)
elif content_type == 'application/octet-stream':
Expand All @@ -818,17 +833,11 @@ class OpenApiResponse(JSONDetector):
content_type = 'multipart/form-data'
else:
raise NotImplementedError('Deserialization of {} has not yet been implemented'.format(content_type))
# TODO if body_schema is None what should the code do?
body_schema = self.content[content_type].schema
deserialized_body = body_schema._from_openapi_data(
body_data, _configuration=configuration)
elif streamed:
response.release_conn()

deserialized_headers = unset
if self.headers is not None:
deserialized_headers = unset

return self.response_cls(
response=response,
headers=deserialized_headers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -808,12 +808,27 @@ def deserialize(self, response: urllib3.HTTPResponse, configuration: Configurati
content_type = response.getheader('content-type')
deserialized_body = unset
streamed = response.supports_chunked_reads()

deserialized_headers = unset
if self.headers is not None:
# TODO add header deserialiation here
pass

if self.content is not None:
if content_type not in self.content:
raise ApiValueError(
f'Invalid content_type={content_type} returned for response with '
'status_code={str(response.status)}'
)
body_schema = self.content[content_type].schema
if body_schema is None:
# some specs do not define response content media type schemas
return self.response_cls(
response=response,
headers=deserialized_headers,
body=unset
)

if self.content_type_is_json(content_type):
body_data = self.__deserialize_json(response)
elif content_type == 'application/octet-stream':
Expand All @@ -823,17 +838,11 @@ def deserialize(self, response: urllib3.HTTPResponse, configuration: Configurati
content_type = 'multipart/form-data'
else:
raise NotImplementedError('Deserialization of {} has not yet been implemented'.format(content_type))
# TODO if body_schema is None what should the code do?
body_schema = self.content[content_type].schema
deserialized_body = body_schema._from_openapi_data(
body_data, _configuration=configuration)
elif streamed:
response.release_conn()

deserialized_headers = unset
if self.headers is not None:
deserialized_headers = unset

return self.response_cls(
response=response,
headers=deserialized_headers,
Expand Down