2018-04-17 12:18:40 +00:00
|
|
|
"""OpenAPI core responses models module"""
|
2018-05-30 13:46:54 +00:00
|
|
|
from openapi_core.schema.content.exceptions import MimeTypeNotFound
|
2018-04-18 10:39:03 +00:00
|
|
|
from openapi_core.schema.media_types.exceptions import InvalidContentType
|
2018-04-17 12:18:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Response(object):
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
self, http_status, description, headers=None, content=None,
|
2020-03-03 13:01:45 +00:00
|
|
|
links=None, extensions=None):
|
2018-04-17 12:18:40 +00:00
|
|
|
self.http_status = http_status
|
|
|
|
self.description = description
|
|
|
|
self.headers = headers and dict(headers) or {}
|
2021-03-30 11:29:37 +00:00
|
|
|
self.content = content
|
2018-04-17 12:18:40 +00:00
|
|
|
self.links = links and dict(links) or {}
|
|
|
|
|
2020-03-03 13:01:45 +00:00
|
|
|
self.extensions = extensions and dict(extensions) or {}
|
|
|
|
|
2018-04-17 12:18:40 +00:00
|
|
|
def __getitem__(self, mimetype):
|
2018-08-17 14:54:01 +00:00
|
|
|
return self.get_content_type(mimetype)
|
|
|
|
|
|
|
|
def get_content_type(self, mimetype):
|
2018-04-17 12:18:40 +00:00
|
|
|
try:
|
|
|
|
return self.content[mimetype]
|
2018-05-30 13:46:54 +00:00
|
|
|
except MimeTypeNotFound:
|
2018-09-06 14:50:16 +00:00
|
|
|
raise InvalidContentType(mimetype)
|