From c6f282b29a662fc910b9276d6594e1512240f19d Mon Sep 17 00:00:00 2001 From: timonrieger Date: Sat, 31 Jan 2026 20:44:35 +0100 Subject: [PATCH 1/3] feat(python): enhance retry configuration in REST client Updated the retry parameter in the Configuration class to support different types based on the library used (urllib3 or asyncio). Adjusted the RESTClientObject to handle the new retry configuration, allowing for more flexible retry options. This change improves the handling of retries in API requests, ensuring compatibility with various retry strategies. --- .../resources/python/asyncio/rest.mustache | 24 ++++++++++++------- .../resources/python/configuration.mustache | 8 ++++--- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/python/asyncio/rest.mustache b/modules/openapi-generator/src/main/resources/python/asyncio/rest.mustache index 9d9fc9682fb6..474413e955e6 100644 --- a/modules/openapi-generator/src/main/resources/python/asyncio/rest.mustache +++ b/modules/openapi-generator/src/main/resources/python/asyncio/rest.mustache @@ -68,7 +68,20 @@ class RESTClientObject: self.proxy = configuration.proxy self.proxy_headers = configuration.proxy_headers - self.retries = configuration.retries + retries = configuration.retries + if retries is None: + self._effective_retry_options = None + elif isinstance(retries, aiohttp_retry.RetryOptionsBase): + self._effective_retry_options = retries + elif isinstance(retries, int): + self._effective_retry_options = aiohttp_retry.ExponentialRetry( + attempts=retries, + factor=2.0, + start_timeout=0.1, + max_timeout=120.0 + ) + else: + self._effective_retry_options = None self.pool_manager: Optional[aiohttp.ClientSession] = None self.retry_client: Optional[aiohttp_retry.RetryClient] = None @@ -191,16 +204,11 @@ class RESTClientObject: ) pool_manager = self.pool_manager - if self.retries is not None and method in ALLOW_RETRY_METHODS: + if self._effective_retry_options is not None and method in ALLOW_RETRY_METHODS: if self.retry_client is None: self.retry_client = aiohttp_retry.RetryClient( client_session=self.pool_manager, - retry_options=aiohttp_retry.ExponentialRetry( - attempts=self.retries, - factor=2.0, - start_timeout=0.1, - max_timeout=120.0 - ) + retry_options=self._effective_retry_options ) pool_manager = self.retry_client diff --git a/modules/openapi-generator/src/main/resources/python/configuration.mustache b/modules/openapi-generator/src/main/resources/python/configuration.mustache index 039b2a85519f..f7602ed100a8 100644 --- a/modules/openapi-generator/src/main/resources/python/configuration.mustache +++ b/modules/openapi-generator/src/main/resources/python/configuration.mustache @@ -188,7 +188,9 @@ class Configuration: values before. :param ssl_ca_cert: str - the path to a file of concatenated CA certificates in PEM format. - :param retries: Number of retries for API requests. + :param retries: Retry config; type depends on library: + * urllib3: int | urllib3.util.retry.Retry + * asyncio: int | aiohttp_retry.RetryOptionsBase :param ca_cert_data: verify the peer using concatenated CA certificate data in PEM (str) or DER (bytes) format. :param cert_file: the path to a client certificate file, for mTLS. @@ -298,7 +300,7 @@ conf = {{{packageName}}}.Configuration( server_operation_variables: Optional[Dict[int, ServerVariablesT]]=None, ignore_operation_servers: bool=False, ssl_ca_cert: Optional[str]=None, - retries: Optional[int] = None, + retries: Optional[Union[int, Any]] = None, ca_cert_data: Optional[Union[str, bytes]] = None, cert_file: Optional[str]=None, key_file: Optional[str]=None, @@ -432,7 +434,7 @@ conf = {{{packageName}}}.Configuration( """Safe chars for path_param """ self.retries = retries - """Adding retries to override urllib3 default value 3 + """Retry configuration """ # Enable client side validation self.client_side_validation = True From 54c5877c2774ec01f076ca7ec48c7ca9e7326a86 Mon Sep 17 00:00:00 2001 From: timonrieger Date: Thu, 5 Feb 2026 11:13:15 +0100 Subject: [PATCH 2/3] add samples --- .../openapi_client/configuration.py | 8 ++++--- .../python/openapi_client/configuration.py | 8 ++++--- .../petstore_api/configuration.py | 8 ++++--- .../python-aiohttp/petstore_api/rest.py | 24 ++++++++++++------- .../petstore_api/configuration.py | 8 ++++--- .../petstore_api/configuration.py | 8 ++++--- .../python/petstore_api/configuration.py | 8 ++++--- 7 files changed, 46 insertions(+), 26 deletions(-) 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 bc8fb73562ff..5e7116fe8d40 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/configuration.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/configuration.py @@ -162,7 +162,9 @@ class Configuration: values before. :param ssl_ca_cert: str - the path to a file of concatenated CA certificates in PEM format. - :param retries: Number of retries for API requests. + :param retries: Retry config; type depends on library: + * urllib3: int | urllib3.util.retry.Retry + * asyncio: int | aiohttp_retry.RetryOptionsBase :param ca_cert_data: verify the peer using concatenated CA certificate data in PEM (str) or DER (bytes) format. :param cert_file: the path to a client certificate file, for mTLS. @@ -203,7 +205,7 @@ def __init__( server_operation_variables: Optional[Dict[int, ServerVariablesT]]=None, ignore_operation_servers: bool=False, ssl_ca_cert: Optional[str]=None, - retries: Optional[int] = None, + retries: Optional[Union[int, Any]] = None, ca_cert_data: Optional[Union[str, bytes]] = None, cert_file: Optional[str]=None, key_file: Optional[str]=None, @@ -320,7 +322,7 @@ def __init__( """Safe chars for path_param """ self.retries = retries - """Adding retries to override urllib3 default value 3 + """Retry configuration """ # Enable client side validation self.client_side_validation = True diff --git a/samples/client/echo_api/python/openapi_client/configuration.py b/samples/client/echo_api/python/openapi_client/configuration.py index bc8fb73562ff..5e7116fe8d40 100644 --- a/samples/client/echo_api/python/openapi_client/configuration.py +++ b/samples/client/echo_api/python/openapi_client/configuration.py @@ -162,7 +162,9 @@ class Configuration: values before. :param ssl_ca_cert: str - the path to a file of concatenated CA certificates in PEM format. - :param retries: Number of retries for API requests. + :param retries: Retry config; type depends on library: + * urllib3: int | urllib3.util.retry.Retry + * asyncio: int | aiohttp_retry.RetryOptionsBase :param ca_cert_data: verify the peer using concatenated CA certificate data in PEM (str) or DER (bytes) format. :param cert_file: the path to a client certificate file, for mTLS. @@ -203,7 +205,7 @@ def __init__( server_operation_variables: Optional[Dict[int, ServerVariablesT]]=None, ignore_operation_servers: bool=False, ssl_ca_cert: Optional[str]=None, - retries: Optional[int] = None, + retries: Optional[Union[int, Any]] = None, ca_cert_data: Optional[Union[str, bytes]] = None, cert_file: Optional[str]=None, key_file: Optional[str]=None, @@ -320,7 +322,7 @@ def __init__( """Safe chars for path_param """ self.retries = retries - """Adding retries to override urllib3 default value 3 + """Retry configuration """ # Enable client side validation self.client_side_validation = True 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 8a5ebdc1143f..68c6a6b78593 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/configuration.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/configuration.py @@ -167,7 +167,9 @@ class Configuration: values before. :param ssl_ca_cert: str - the path to a file of concatenated CA certificates in PEM format. - :param retries: Number of retries for API requests. + :param retries: Retry config; type depends on library: + * urllib3: int | urllib3.util.retry.Retry + * asyncio: int | aiohttp_retry.RetryOptionsBase :param ca_cert_data: verify the peer using concatenated CA certificate data in PEM (str) or DER (bytes) format. :param cert_file: the path to a client certificate file, for mTLS. @@ -267,7 +269,7 @@ def __init__( server_operation_variables: Optional[Dict[int, ServerVariablesT]]=None, ignore_operation_servers: bool=False, ssl_ca_cert: Optional[str]=None, - retries: Optional[int] = None, + retries: Optional[Union[int, Any]] = None, ca_cert_data: Optional[Union[str, bytes]] = None, cert_file: Optional[str]=None, key_file: Optional[str]=None, @@ -385,7 +387,7 @@ def __init__( """Safe chars for path_param """ self.retries = retries - """Adding retries to override urllib3 default value 3 + """Retry configuration """ # Enable client side validation self.client_side_validation = True diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/rest.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/rest.py index c2b11c653f16..3d0fe9da8fc8 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/rest.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/rest.py @@ -77,7 +77,20 @@ def __init__(self, configuration) -> None: self.proxy = configuration.proxy self.proxy_headers = configuration.proxy_headers - self.retries = configuration.retries + retries = configuration.retries + if retries is None: + self._effective_retry_options = None + elif isinstance(retries, aiohttp_retry.RetryOptionsBase): + self._effective_retry_options = retries + elif isinstance(retries, int): + self._effective_retry_options = aiohttp_retry.ExponentialRetry( + attempts=retries, + factor=2.0, + start_timeout=0.1, + max_timeout=120.0 + ) + else: + self._effective_retry_options = None self.pool_manager: Optional[aiohttp.ClientSession] = None self.retry_client: Optional[aiohttp_retry.RetryClient] = None @@ -200,16 +213,11 @@ async def request( ) pool_manager = self.pool_manager - if self.retries is not None and method in ALLOW_RETRY_METHODS: + if self._effective_retry_options is not None and method in ALLOW_RETRY_METHODS: if self.retry_client is None: self.retry_client = aiohttp_retry.RetryClient( client_session=self.pool_manager, - retry_options=aiohttp_retry.ExponentialRetry( - attempts=self.retries, - factor=2.0, - start_timeout=0.1, - max_timeout=120.0 - ) + retry_options=self._effective_retry_options ) pool_manager = self.retry_client diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/configuration.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/configuration.py index 8a5ebdc1143f..68c6a6b78593 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/configuration.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/configuration.py @@ -167,7 +167,9 @@ class Configuration: values before. :param ssl_ca_cert: str - the path to a file of concatenated CA certificates in PEM format. - :param retries: Number of retries for API requests. + :param retries: Retry config; type depends on library: + * urllib3: int | urllib3.util.retry.Retry + * asyncio: int | aiohttp_retry.RetryOptionsBase :param ca_cert_data: verify the peer using concatenated CA certificate data in PEM (str) or DER (bytes) format. :param cert_file: the path to a client certificate file, for mTLS. @@ -267,7 +269,7 @@ def __init__( server_operation_variables: Optional[Dict[int, ServerVariablesT]]=None, ignore_operation_servers: bool=False, ssl_ca_cert: Optional[str]=None, - retries: Optional[int] = None, + retries: Optional[Union[int, Any]] = None, ca_cert_data: Optional[Union[str, bytes]] = None, cert_file: Optional[str]=None, key_file: Optional[str]=None, @@ -385,7 +387,7 @@ def __init__( """Safe chars for path_param """ self.retries = retries - """Adding retries to override urllib3 default value 3 + """Retry configuration """ # Enable client side validation self.client_side_validation = True diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/configuration.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/configuration.py index 0bd1cbdcadd2..5a86fa735906 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/configuration.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/configuration.py @@ -168,7 +168,9 @@ class Configuration: values before. :param ssl_ca_cert: str - the path to a file of concatenated CA certificates in PEM format. - :param retries: Number of retries for API requests. + :param retries: Retry config; type depends on library: + * urllib3: int | urllib3.util.retry.Retry + * asyncio: int | aiohttp_retry.RetryOptionsBase :param ca_cert_data: verify the peer using concatenated CA certificate data in PEM (str) or DER (bytes) format. :param cert_file: the path to a client certificate file, for mTLS. @@ -268,7 +270,7 @@ def __init__( server_operation_variables: Optional[Dict[int, ServerVariablesT]]=None, ignore_operation_servers: bool=False, ssl_ca_cert: Optional[str]=None, - retries: Optional[int] = None, + retries: Optional[Union[int, Any]] = None, ca_cert_data: Optional[Union[str, bytes]] = None, cert_file: Optional[str]=None, key_file: Optional[str]=None, @@ -390,7 +392,7 @@ def __init__( """Safe chars for path_param """ self.retries = retries - """Adding retries to override urllib3 default value 3 + """Retry configuration """ # Enable client side validation self.client_side_validation = True diff --git a/samples/openapi3/client/petstore/python/petstore_api/configuration.py b/samples/openapi3/client/petstore/python/petstore_api/configuration.py index 0bd1cbdcadd2..5a86fa735906 100755 --- a/samples/openapi3/client/petstore/python/petstore_api/configuration.py +++ b/samples/openapi3/client/petstore/python/petstore_api/configuration.py @@ -168,7 +168,9 @@ class Configuration: values before. :param ssl_ca_cert: str - the path to a file of concatenated CA certificates in PEM format. - :param retries: Number of retries for API requests. + :param retries: Retry config; type depends on library: + * urllib3: int | urllib3.util.retry.Retry + * asyncio: int | aiohttp_retry.RetryOptionsBase :param ca_cert_data: verify the peer using concatenated CA certificate data in PEM (str) or DER (bytes) format. :param cert_file: the path to a client certificate file, for mTLS. @@ -268,7 +270,7 @@ def __init__( server_operation_variables: Optional[Dict[int, ServerVariablesT]]=None, ignore_operation_servers: bool=False, ssl_ca_cert: Optional[str]=None, - retries: Optional[int] = None, + retries: Optional[Union[int, Any]] = None, ca_cert_data: Optional[Union[str, bytes]] = None, cert_file: Optional[str]=None, key_file: Optional[str]=None, @@ -390,7 +392,7 @@ def __init__( """Safe chars for path_param """ self.retries = retries - """Adding retries to override urllib3 default value 3 + """Retry configuration """ # Enable client side validation self.client_side_validation = True From 28850ba8a19ea6a065d61eb85e69660d0b8731fe Mon Sep 17 00:00:00 2001 From: timonrieger Date: Thu, 5 Feb 2026 12:08:37 +0100 Subject: [PATCH 3/3] use async context for retry doc string --- .../src/main/resources/python/configuration.mustache | 9 ++++++--- .../openapi_client/configuration.py | 4 +--- .../echo_api/python/openapi_client/configuration.py | 4 +--- .../python-aiohttp/petstore_api/configuration.py | 4 +--- .../petstore/python-httpx/petstore_api/configuration.py | 4 +--- .../python-lazyImports/petstore_api/configuration.py | 4 +--- .../client/petstore/python/petstore_api/configuration.py | 4 +--- 7 files changed, 12 insertions(+), 21 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/python/configuration.mustache b/modules/openapi-generator/src/main/resources/python/configuration.mustache index f7602ed100a8..b103b03b93b8 100644 --- a/modules/openapi-generator/src/main/resources/python/configuration.mustache +++ b/modules/openapi-generator/src/main/resources/python/configuration.mustache @@ -188,9 +188,12 @@ class Configuration: values before. :param ssl_ca_cert: str - the path to a file of concatenated CA certificates in PEM format. - :param retries: Retry config; type depends on library: - * urllib3: int | urllib3.util.retry.Retry - * asyncio: int | aiohttp_retry.RetryOptionsBase +{{#async}} + :param retries: int | aiohttp_retry.RetryOptionsBase - Retry configuration. +{{/async}} +{{^async}} + :param retries: int | urllib3.util.retry.Retry - Retry configuration. +{{/async}} :param ca_cert_data: verify the peer using concatenated CA certificate data in PEM (str) or DER (bytes) format. :param cert_file: the path to a client certificate file, for mTLS. 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 5e7116fe8d40..4c6ba867ad9d 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/configuration.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/configuration.py @@ -162,9 +162,7 @@ class Configuration: values before. :param ssl_ca_cert: str - the path to a file of concatenated CA certificates in PEM format. - :param retries: Retry config; type depends on library: - * urllib3: int | urllib3.util.retry.Retry - * asyncio: int | aiohttp_retry.RetryOptionsBase + :param retries: int | urllib3.util.retry.Retry - Retry configuration. :param ca_cert_data: verify the peer using concatenated CA certificate data in PEM (str) or DER (bytes) format. :param cert_file: the path to a client certificate file, for mTLS. diff --git a/samples/client/echo_api/python/openapi_client/configuration.py b/samples/client/echo_api/python/openapi_client/configuration.py index 5e7116fe8d40..4c6ba867ad9d 100644 --- a/samples/client/echo_api/python/openapi_client/configuration.py +++ b/samples/client/echo_api/python/openapi_client/configuration.py @@ -162,9 +162,7 @@ class Configuration: values before. :param ssl_ca_cert: str - the path to a file of concatenated CA certificates in PEM format. - :param retries: Retry config; type depends on library: - * urllib3: int | urllib3.util.retry.Retry - * asyncio: int | aiohttp_retry.RetryOptionsBase + :param retries: int | urllib3.util.retry.Retry - Retry configuration. :param ca_cert_data: verify the peer using concatenated CA certificate data in PEM (str) or DER (bytes) format. :param cert_file: the path to a client certificate file, for mTLS. 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 68c6a6b78593..77bd0c53c2bb 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/configuration.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/configuration.py @@ -167,9 +167,7 @@ class Configuration: values before. :param ssl_ca_cert: str - the path to a file of concatenated CA certificates in PEM format. - :param retries: Retry config; type depends on library: - * urllib3: int | urllib3.util.retry.Retry - * asyncio: int | aiohttp_retry.RetryOptionsBase + :param retries: int | aiohttp_retry.RetryOptionsBase - Retry configuration. :param ca_cert_data: verify the peer using concatenated CA certificate data in PEM (str) or DER (bytes) format. :param cert_file: the path to a client certificate file, for mTLS. diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/configuration.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/configuration.py index 68c6a6b78593..77bd0c53c2bb 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/configuration.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/configuration.py @@ -167,9 +167,7 @@ class Configuration: values before. :param ssl_ca_cert: str - the path to a file of concatenated CA certificates in PEM format. - :param retries: Retry config; type depends on library: - * urllib3: int | urllib3.util.retry.Retry - * asyncio: int | aiohttp_retry.RetryOptionsBase + :param retries: int | aiohttp_retry.RetryOptionsBase - Retry configuration. :param ca_cert_data: verify the peer using concatenated CA certificate data in PEM (str) or DER (bytes) format. :param cert_file: the path to a client certificate file, for mTLS. diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/configuration.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/configuration.py index 5a86fa735906..9969694e9282 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/configuration.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/configuration.py @@ -168,9 +168,7 @@ class Configuration: values before. :param ssl_ca_cert: str - the path to a file of concatenated CA certificates in PEM format. - :param retries: Retry config; type depends on library: - * urllib3: int | urllib3.util.retry.Retry - * asyncio: int | aiohttp_retry.RetryOptionsBase + :param retries: int | urllib3.util.retry.Retry - Retry configuration. :param ca_cert_data: verify the peer using concatenated CA certificate data in PEM (str) or DER (bytes) format. :param cert_file: the path to a client certificate file, for mTLS. diff --git a/samples/openapi3/client/petstore/python/petstore_api/configuration.py b/samples/openapi3/client/petstore/python/petstore_api/configuration.py index 5a86fa735906..9969694e9282 100755 --- a/samples/openapi3/client/petstore/python/petstore_api/configuration.py +++ b/samples/openapi3/client/petstore/python/petstore_api/configuration.py @@ -168,9 +168,7 @@ class Configuration: values before. :param ssl_ca_cert: str - the path to a file of concatenated CA certificates in PEM format. - :param retries: Retry config; type depends on library: - * urllib3: int | urllib3.util.retry.Retry - * asyncio: int | aiohttp_retry.RetryOptionsBase + :param retries: int | urllib3.util.retry.Retry - Retry configuration. :param ca_cert_data: verify the peer using concatenated CA certificate data in PEM (str) or DER (bytes) format. :param cert_file: the path to a client certificate file, for mTLS.