openapi-core/openapi_core/contrib/falcon/responses.py

24 lines
699 B
Python
Raw Normal View History

"""OpenAPI core contrib falcon responses module"""
2021-04-30 23:30:55 +00:00
from openapi_core.contrib.falcon.compat import get_response_text
from openapi_core.validation.response.datatypes import OpenAPIResponse
class FalconOpenAPIResponseFactory(object):
@classmethod
2020-02-17 16:33:01 +00:00
def create(cls, response):
status_code = int(response.status[:3])
mimetype = ''
if response.content_type:
mimetype = response.content_type.partition(";")[0]
else:
mimetype = response.options.default_media_type
2021-04-30 23:30:55 +00:00
data = get_response_text(response)
2021-04-30 23:01:22 +00:00
return OpenAPIResponse(
2021-04-30 23:01:22 +00:00
data=data,
2020-02-17 16:33:01 +00:00
status_code=status_code,
mimetype=mimetype,
)