mirror of
https://github.com/correl/openapi-core.git
synced 2024-11-28 19:19:52 +00:00
24 lines
655 B
Python
24 lines
655 B
Python
|
from openapi_core.templating.responses.exceptions import ResponseNotFound
|
||
|
|
||
|
|
||
|
class ResponseFinder(object):
|
||
|
|
||
|
def __init__(self, responses):
|
||
|
self.responses = responses
|
||
|
|
||
|
def find(self, http_status='default'):
|
||
|
try:
|
||
|
return self.responses[http_status]
|
||
|
except KeyError:
|
||
|
pass
|
||
|
|
||
|
# try range
|
||
|
http_status_range = '{0}XX'.format(http_status[0])
|
||
|
if http_status_range in self.responses:
|
||
|
return self.responses[http_status_range]
|
||
|
|
||
|
if 'default' not in self.responses:
|
||
|
raise ResponseNotFound(http_status, self.responses)
|
||
|
|
||
|
return self.responses['default']
|