From d755e9888affe68eedad0b14cda68df04733a15a Mon Sep 17 00:00:00 2001 From: Felix Schwarz Date: Mon, 4 Dec 2023 22:19:25 +0100 Subject: [PATCH] prevent UnboundLocalError if the user did not provide a request body Even though the request might be invalid, at least there is a chance that the server response contains some helpful information. For example a simple Connexion app responds with: HTTP status code 400 Request body must not be empty --- openapi3/paths.py | 1 + 1 file changed, 1 insertion(+) diff --git a/openapi3/paths.py b/openapi3/paths.py index f8d0f2e..e30ee07 100644 --- a/openapi3/paths.py +++ b/openapi3/paths.py @@ -268,6 +268,7 @@ def _request_handle_parameters(self, parameters={}): def _request_handle_body(self, data): if "application/json" in self.requestBody.content: + body = {} if isinstance(data, dict) or isinstance(data, list): body = json.dumps(data)