From bcdbf6eadda7b3b2f13a0f0f3f7e9bb234dd8587 Mon Sep 17 00:00:00 2001 From: Sergiu-Vlad Bonta Date: Wed, 21 Apr 2021 19:04:05 +0300 Subject: [PATCH] Bugfix #311, openapicore works with falcon 3.0.0 --- openapi_core/contrib/falcon/requests.py | 13 +++++++++---- tests/integration/contrib/falcon/conftest.py | 1 - 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/openapi_core/contrib/falcon/requests.py b/openapi_core/contrib/falcon/requests.py index e48b4fa..2e88ff1 100644 --- a/openapi_core/contrib/falcon/requests.py +++ b/openapi_core/contrib/falcon/requests.py @@ -11,19 +11,24 @@ from openapi_core.validation.request.datatypes import ( class FalconOpenAPIRequestFactory: @classmethod - def create(cls, request): + def create(cls, request, default_when_empty={}): """ Create OpenAPIRequest from falcon Request and route params. """ + default = default_when_empty method = request.method.lower() # gets deduced by path finder against spec path = {} - # Support falcon-jsonify. + # in falcon 3 we must hadle empty media or an exception will be raised + if hasattr(request, "get_media"): + media = request.get_media(default_when_empty=default) + else: + media = request.media if request.media else default + # # Support falcon-jsonify. body = ( - dumps(request.json) if getattr(request, "json", None) - else dumps(request.media) + dumps(getattr(request, "json", media)) ) mimetype = request.options.default_media_type if request.content_type: diff --git a/tests/integration/contrib/falcon/conftest.py b/tests/integration/contrib/falcon/conftest.py index 60ac8d6..5ad0503 100644 --- a/tests/integration/contrib/falcon/conftest.py +++ b/tests/integration/contrib/falcon/conftest.py @@ -33,7 +33,6 @@ def request_factory(environ_factory, router): options = RequestOptions() # return create_req(options=options, **environ) req = Request(environ, options) - resource, method_map, params, req.uri_template = router.find(path, req) return req return create_request