From 3dce6ca7b50a628e8241425ccf3bda9552fd592d Mon Sep 17 00:00:00 2001 From: Alexander Campbell Date: Mon, 5 Aug 2024 10:42:54 -0400 Subject: [PATCH] Use None for no request body instead of b"" This is how openapi-core expects a lack of request body. Currently it can cause issues with validation because requests without a body will be send to the validator with a request a body of empty bytes that can't be validated. --- tests/test_requests.py | 4 ++-- tornado_openapi3/requests.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_requests.py b/tests/test_requests.py index e313a61..20a8e79 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -99,7 +99,7 @@ class TestRequestFactory(unittest.TestCase): full_url_pattern=url, method="get", parameters=RequestParameters(query=ImmutableMultiDict(parameters)), - body=b"", + body=None, mimetype="application/x-www-form-urlencoded", ) openapi_request = TornadoRequestFactory.create(tornado_request) @@ -127,7 +127,7 @@ class TestRequestFactory(unittest.TestCase): parameters=RequestParameters( query=ImmutableMultiDict(parameters), path={}, cookie={} ), - body=b"", + body=None, mimetype="application/x-www-form-urlencoded", ) openapi_request = TornadoRequestFactory.create(tornado_request) diff --git a/tornado_openapi3/requests.py b/tornado_openapi3/requests.py index b52404d..396cb0c 100644 --- a/tornado_openapi3/requests.py +++ b/tornado_openapi3/requests.py @@ -55,7 +55,7 @@ class TornadoRequestFactory: header=Headers(request.headers.get_all()), cookie=parse_cookie(request.headers.get("Cookie", "")), ), - body=request.body if request.body else b"", + body=request.body if request.body else None, mimetype=parse_mimetype( request.headers.get("Content-Type", "application/x-www-form-urlencoded") ),