From d1b148a7d3c531c11e6b188dc43b123cf277c704 Mon Sep 17 00:00:00 2001 From: OliverTetzTT <111119720+OliverTetzTT@users.noreply.github.com> Date: Tue, 14 Nov 2023 04:30:10 +0100 Subject: [PATCH] [python] added handling for boolean content type (#17020) * added handling for boolean content type * adapted addition to newer version of template * [python] updated samples --- .../src/main/resources/python/rest.mustache | 9 +++++++++ .../openapi_client/rest.py | 9 +++++++++ samples/client/echo_api/python/openapi_client/rest.py | 9 +++++++++ .../openapi3/client/petstore/python/petstore_api/rest.py | 9 +++++++++ 4 files changed, 36 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/python/rest.mustache b/modules/openapi-generator/src/main/resources/python/rest.mustache index f72bf6dfd8f..2d8a1c9706e 100644 --- a/modules/openapi-generator/src/main/resources/python/rest.mustache +++ b/modules/openapi-generator/src/main/resources/python/rest.mustache @@ -198,6 +198,15 @@ class RESTClientObject: headers=headers, preload_content=False ) + elif headers['Content-Type'] == 'text/plain' and isinstance(body, bool): + request_body = "true" if body else "false" + r = self.pool_manager.request( + method, + url, + body=request_body, + preload_content=False, + timeout=timeout, + headers=headers) else: # Cannot generate the request from given parameters msg = """Cannot prepare a request message for provided diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent-true/openapi_client/rest.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent-true/openapi_client/rest.py index da77b96513f..0c9afe7006f 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent-true/openapi_client/rest.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent-true/openapi_client/rest.py @@ -209,6 +209,15 @@ class RESTClientObject: headers=headers, preload_content=False ) + elif headers['Content-Type'] == 'text/plain' and isinstance(body, bool): + request_body = "true" if body else "false" + r = self.pool_manager.request( + method, + url, + body=request_body, + preload_content=False, + timeout=timeout, + headers=headers) else: # Cannot generate the request from given parameters msg = """Cannot prepare a request message for provided diff --git a/samples/client/echo_api/python/openapi_client/rest.py b/samples/client/echo_api/python/openapi_client/rest.py index da77b96513f..0c9afe7006f 100644 --- a/samples/client/echo_api/python/openapi_client/rest.py +++ b/samples/client/echo_api/python/openapi_client/rest.py @@ -209,6 +209,15 @@ class RESTClientObject: headers=headers, preload_content=False ) + elif headers['Content-Type'] == 'text/plain' and isinstance(body, bool): + request_body = "true" if body else "false" + r = self.pool_manager.request( + method, + url, + body=request_body, + preload_content=False, + timeout=timeout, + headers=headers) else: # Cannot generate the request from given parameters msg = """Cannot prepare a request message for provided diff --git a/samples/openapi3/client/petstore/python/petstore_api/rest.py b/samples/openapi3/client/petstore/python/petstore_api/rest.py index da531ca1461..785cc38e825 100755 --- a/samples/openapi3/client/petstore/python/petstore_api/rest.py +++ b/samples/openapi3/client/petstore/python/petstore_api/rest.py @@ -208,6 +208,15 @@ class RESTClientObject: headers=headers, preload_content=False ) + elif headers['Content-Type'] == 'text/plain' and isinstance(body, bool): + request_body = "true" if body else "false" + r = self.pool_manager.request( + method, + url, + body=request_body, + preload_content=False, + timeout=timeout, + headers=headers) else: # Cannot generate the request from given parameters msg = """Cannot prepare a request message for provided