openapi-core/openapi_core/contrib/requests/requests.py
2020-03-03 11:09:28 +00:00

34 lines
950 B
Python

"""OpenAPI core contrib requests requests module"""
from werkzeug.datastructures import ImmutableMultiDict
from openapi_core.validation.request.datatypes import (
RequestParameters, OpenAPIRequest,
)
class RequestsOpenAPIRequestFactory(object):
@classmethod
def create(cls, request):
method = request.method.lower()
cookie = request.cookies or {}
# gets deduced by path finder against spec
path = {}
mimetype = request.headers.get('Accept') or \
request.headers.get('Content-Type')
parameters = RequestParameters(
query=ImmutableMultiDict(request.params),
header=request.headers,
cookie=cookie,
path=path,
)
return OpenAPIRequest(
full_url_pattern=request.url,
method=method,
parameters=parameters,
body=request.data,
mimetype=mimetype,
)