From e5ae07c2b4a816ae583c7abe7b1ce5324ae99d12 Mon Sep 17 00:00:00 2001 From: Vito De Tullio Date: Thu, 20 Jun 2024 12:23:34 +0200 Subject: [PATCH] avoid setting debug property if not needed (#18872) * avoid setting debug property if not needed * update samples * fix compatibility with python 3.7 * always set Configuration.__debug * update samples * check `Configuration` behavior when debug parameter is / is not set * address PR requests --- .../src/main/resources/python/configuration.mustache | 7 ++++++- .../openapi_client/configuration.py | 7 ++++++- .../echo_api/python/openapi_client/configuration.py | 7 ++++++- .../python-aiohttp/petstore_api/configuration.py | 7 ++++++- .../client/petstore/python/petstore_api/configuration.py | 7 ++++++- .../client/petstore/python/tests/test_configuration.py | 9 +++++++++ 6 files changed, 39 insertions(+), 5 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/python/configuration.mustache b/modules/openapi-generator/src/main/resources/python/configuration.mustache index fc9c7f06309..c50c6fe3fdf 100644 --- a/modules/openapi-generator/src/main/resources/python/configuration.mustache +++ b/modules/openapi-generator/src/main/resources/python/configuration.mustache @@ -150,6 +150,8 @@ conf = {{{packageName}}}.Configuration( server_operation_index=None, server_operation_variables=None, ssl_ca_cert=None, retries=None, + *, + debug: Optional[bool] = None ) -> None: """Constructor """ @@ -214,7 +216,10 @@ conf = {{{packageName}}}.Configuration( self.logger_file = None """Debug file location """ - self.debug = False + if debug is not None: + self.debug = debug + else: + self.__debug = False """Debug switch """ diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/configuration.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/configuration.py index ea06c939fa8..0966e566417 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/configuration.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/configuration.py @@ -86,6 +86,8 @@ conf = openapi_client.Configuration( server_operation_index=None, server_operation_variables=None, ssl_ca_cert=None, retries=None, + *, + debug: Optional[bool] = None ) -> None: """Constructor """ @@ -143,7 +145,10 @@ conf = openapi_client.Configuration( self.logger_file = None """Debug file location """ - self.debug = False + if debug is not None: + self.debug = debug + else: + self.__debug = False """Debug switch """ diff --git a/samples/client/echo_api/python/openapi_client/configuration.py b/samples/client/echo_api/python/openapi_client/configuration.py index ea06c939fa8..0966e566417 100644 --- a/samples/client/echo_api/python/openapi_client/configuration.py +++ b/samples/client/echo_api/python/openapi_client/configuration.py @@ -86,6 +86,8 @@ conf = openapi_client.Configuration( server_operation_index=None, server_operation_variables=None, ssl_ca_cert=None, retries=None, + *, + debug: Optional[bool] = None ) -> None: """Constructor """ @@ -143,7 +145,10 @@ conf = openapi_client.Configuration( self.logger_file = None """Debug file location """ - self.debug = False + if debug is not None: + self.debug = debug + else: + self.__debug = False """Debug switch """ diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/configuration.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/configuration.py index 272c4385892..096957ab701 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/configuration.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/configuration.py @@ -145,6 +145,8 @@ conf = petstore_api.Configuration( server_operation_index=None, server_operation_variables=None, ssl_ca_cert=None, retries=None, + *, + debug: Optional[bool] = None ) -> None: """Constructor """ @@ -207,7 +209,10 @@ conf = petstore_api.Configuration( self.logger_file = None """Debug file location """ - self.debug = False + if debug is not None: + self.debug = debug + else: + self.__debug = False """Debug switch """ diff --git a/samples/openapi3/client/petstore/python/petstore_api/configuration.py b/samples/openapi3/client/petstore/python/petstore_api/configuration.py index 779ee409c75..9739ca72f44 100755 --- a/samples/openapi3/client/petstore/python/petstore_api/configuration.py +++ b/samples/openapi3/client/petstore/python/petstore_api/configuration.py @@ -146,6 +146,8 @@ conf = petstore_api.Configuration( server_operation_index=None, server_operation_variables=None, ssl_ca_cert=None, retries=None, + *, + debug: Optional[bool] = None ) -> None: """Constructor """ @@ -208,7 +210,10 @@ conf = petstore_api.Configuration( self.logger_file = None """Debug file location """ - self.debug = False + if debug is not None: + self.debug = debug + else: + self.__debug = False """Debug switch """ diff --git a/samples/openapi3/client/petstore/python/tests/test_configuration.py b/samples/openapi3/client/petstore/python/tests/test_configuration.py index d8084adafd2..3ff15aaa4c6 100644 --- a/samples/openapi3/client/petstore/python/tests/test_configuration.py +++ b/samples/openapi3/client/petstore/python/tests/test_configuration.py @@ -76,5 +76,14 @@ class TestConfiguration(unittest.TestCase): self.assertEqual("http://petstore.swagger.io:8080/v2", self.config.get_host_from_settings(0, {'port': '8080'})) self.assertEqual("http://dev-petstore.swagger.io:8080/v2", self.config.get_host_from_settings(0, {'server': 'dev-petstore', 'port': '8080'})) + def testConfigurationDebug(self): + for debug, expected in [(True, True), (False, False), (None, False)]: + with self.subTest('expicitly passing debug parameter', debug=debug, expected=expected): + c = petstore_api.Configuration(debug=debug) + self.assertEqual(expected, c.debug) + with self.subTest('not passing debug parameter'): + c = petstore_api.Configuration() + self.assertFalse(c.debug) + if __name__ == '__main__': unittest.main()