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