openapi-core/openapi_core/templating/responses/finders.py

22 lines
645 B
Python
Raw Normal View History

2021-03-31 15:01:03 +00:00
from openapi_core.templating.responses.exceptions import ResponseNotFound
class ResponseFinder(object):
def __init__(self, responses):
self.responses = responses
def find(self, http_status='default'):
2021-04-23 11:36:27 +00:00
if http_status in self.responses:
return self.responses / http_status
2021-03-31 15:01:03 +00:00
# try range
http_status_range = '{0}XX'.format(http_status[0])
if http_status_range in self.responses:
2021-04-23 11:36:27 +00:00
return self.responses / http_status_range
2021-03-31 15:01:03 +00:00
if 'default' not in self.responses:
raise ResponseNotFound(http_status, self.responses)
2021-04-23 11:36:27 +00:00
return self.responses / 'default'