openapi-core/openapi_core/schema/responses/models.py

28 lines
974 B
Python
Raw Normal View History

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
from openapi_core.schema.content.models import Content
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 {}
2018-05-30 13:46:54 +00:00
self.content = content and Content(content) or 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:
raise InvalidContentType(mimetype)