From a985607e23dbb6a4817b1b3ce1365702442d4869 Mon Sep 17 00:00:00 2001 From: Josh Wulf Date: Sun, 23 Nov 2025 09:15:20 +1300 Subject: [PATCH 1/3] fix: use httpx in generated configuration.py --- .../main/resources/python/configuration.mustache | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/python/configuration.mustache b/modules/openapi-generator/src/main/resources/python/configuration.mustache index 511281f298e4..9e90659d40bc 100644 --- a/modules/openapi-generator/src/main/resources/python/configuration.mustache +++ b/modules/openapi-generator/src/main/resources/python/configuration.mustache @@ -3,6 +3,7 @@ {{>partial_header}} +import base64 import copy import http.client as httplib import logging @@ -14,7 +15,9 @@ import sys from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict, Union from typing_extensions import NotRequired, Self +{{^async}} import urllib3 +{{/async}} {{#hasHttpSignatureMethods}} from {{packageName}}.signing import HttpSigningConfiguration @@ -187,7 +190,7 @@ class 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. - :param key_file: the path to a client key file, for mTLS. + :param key_file: the path to a client key file, for mTLS. {{#hasAuthMethods}} :Example: @@ -353,7 +356,9 @@ conf = {{{packageName}}}.Configuration( """Logging Settings """ self.logger["package_logger"] = logging.getLogger("{{packageName}}") + {{^async}} self.logger["urllib3_logger"] = logging.getLogger("urllib3") + {{/async}} self.logger_format = '%(asctime)s %(levelname)s %(message)s' """Log format """ @@ -615,9 +620,10 @@ conf = {{{packageName}}}.Configuration( password = "" if self.password is not None: password = self.password - return urllib3.util.make_headers( - basic_auth=username + ':' + password - ).get('authorization') + + return "Basic " + base64.b64encode( + (username + ":" + password).encode('utf-8') + ).decode('utf-8') def auth_settings(self)-> AuthSettings: """Gets Auth Settings dict for api client. From 9a64b3bb3c256678aaee394806804c56e24773b4 Mon Sep 17 00:00:00 2001 From: Josh Wulf Date: Sun, 23 Nov 2025 10:10:53 +1300 Subject: [PATCH 2/3] fix: add enum_values for httpx --- .../main/resources/python/configuration.mustache | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/python/configuration.mustache b/modules/openapi-generator/src/main/resources/python/configuration.mustache index 9e90659d40bc..039b2a85519f 100644 --- a/modules/openapi-generator/src/main/resources/python/configuration.mustache +++ b/modules/openapi-generator/src/main/resources/python/configuration.mustache @@ -3,7 +3,9 @@ {{>partial_header}} +{{#async}} import base64 +{{/async}} import copy import http.client as httplib import logging @@ -621,9 +623,16 @@ conf = {{{packageName}}}.Configuration( if self.password is not None: password = self.password + {{#async}} return "Basic " + base64.b64encode( (username + ":" + password).encode('utf-8') ).decode('utf-8') + {{/async}} + {{^async}} + return urllib3.util.make_headers( + basic_auth=username + ':' + password + ).get('authorization') + {{/async}} def auth_settings(self)-> AuthSettings: """Gets Auth Settings dict for api client. @@ -726,6 +735,11 @@ conf = {{{packageName}}}.Configuration( ] {{/-last}} {{/enumValues}} + {{^enumValues}} + {{#async}} + 'enum_values': [] + {{/async}} + {{/enumValues}} }{{^-last}},{{/-last}} {{#-last}} } @@ -768,6 +782,7 @@ conf = {{{packageName}}}.Configuration( variable_name, variable['default_value']) if 'enum_values' in variable \ + and variable['enum_values'] \ and used_value not in variable['enum_values']: raise ValueError( "The variable `{0}` in the host URL has invalid value " From f27bd321a41abf65f0c0fcc4a2737f36e90c57a1 Mon Sep 17 00:00:00 2001 From: Josh Wulf Date: Sun, 23 Nov 2025 10:23:27 +1300 Subject: [PATCH 3/3] chore: update petstore samples --- .../openapi_client/configuration.py | 4 +++- .../echo_api/python/openapi_client/configuration.py | 4 +++- .../python-aiohttp/petstore_api/configuration.py | 13 +++++++------ .../python-httpx/petstore_api/configuration.py | 13 +++++++------ .../petstore_api/configuration.py | 4 +++- .../petstore/python/petstore_api/configuration.py | 4 +++- 6 files changed, 26 insertions(+), 16 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 6f5f511966c6..bc8fb73562ff 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/configuration.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/configuration.py @@ -166,7 +166,7 @@ class 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. - :param key_file: the path to a client key file, for mTLS. + :param key_file: the path to a client key file, for mTLS. :Example: @@ -504,6 +504,7 @@ def get_basic_auth_token(self) -> Optional[str]: password = "" if self.password is not None: password = self.password + return urllib3.util.make_headers( basic_auth=username + ':' + password ).get('authorization') @@ -587,6 +588,7 @@ def get_host_from_settings( variable_name, variable['default_value']) if 'enum_values' in variable \ + and variable['enum_values'] \ and used_value not in variable['enum_values']: raise ValueError( "The variable `{0}` in the host URL has invalid value " diff --git a/samples/client/echo_api/python/openapi_client/configuration.py b/samples/client/echo_api/python/openapi_client/configuration.py index 6f5f511966c6..bc8fb73562ff 100644 --- a/samples/client/echo_api/python/openapi_client/configuration.py +++ b/samples/client/echo_api/python/openapi_client/configuration.py @@ -166,7 +166,7 @@ class 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. - :param key_file: the path to a client key file, for mTLS. + :param key_file: the path to a client key file, for mTLS. :Example: @@ -504,6 +504,7 @@ def get_basic_auth_token(self) -> Optional[str]: password = "" if self.password is not None: password = self.password + return urllib3.util.make_headers( basic_auth=username + ':' + password ).get('authorization') @@ -587,6 +588,7 @@ def get_host_from_settings( variable_name, variable['default_value']) if 'enum_values' in variable \ + and variable['enum_values'] \ and used_value not in variable['enum_values']: raise ValueError( "The variable `{0}` in the host URL has invalid value " 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 2d12349c1a3c..8a5ebdc1143f 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/configuration.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/configuration.py @@ -12,6 +12,7 @@ """ # noqa: E501 +import base64 import copy import http.client as httplib import logging @@ -20,7 +21,6 @@ from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict, Union from typing_extensions import NotRequired, Self -import urllib3 from petstore_api.signing import HttpSigningConfiguration @@ -171,7 +171,7 @@ class 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. - :param key_file: the path to a client key file, for mTLS. + :param key_file: the path to a client key file, for mTLS. :Example: @@ -325,7 +325,6 @@ def __init__( """Logging Settings """ self.logger["package_logger"] = logging.getLogger("petstore_api") - self.logger["urllib3_logger"] = logging.getLogger("urllib3") self.logger_format = '%(asctime)s %(levelname)s %(message)s' """Log format """ @@ -574,9 +573,10 @@ def get_basic_auth_token(self) -> Optional[str]: password = "" if self.password is not None: password = self.password - return urllib3.util.make_headers( - basic_auth=username + ':' + password - ).get('authorization') + + return "Basic " + base64.b64encode( + (username + ":" + password).encode('utf-8') + ).decode('utf-8') def auth_settings(self)-> AuthSettings: """Gets Auth Settings dict for api client. @@ -727,6 +727,7 @@ def get_host_from_settings( variable_name, variable['default_value']) if 'enum_values' in variable \ + and variable['enum_values'] \ and used_value not in variable['enum_values']: raise ValueError( "The variable `{0}` in the host URL has invalid value " 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 2d12349c1a3c..8a5ebdc1143f 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/configuration.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/configuration.py @@ -12,6 +12,7 @@ """ # noqa: E501 +import base64 import copy import http.client as httplib import logging @@ -20,7 +21,6 @@ from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict, Union from typing_extensions import NotRequired, Self -import urllib3 from petstore_api.signing import HttpSigningConfiguration @@ -171,7 +171,7 @@ class 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. - :param key_file: the path to a client key file, for mTLS. + :param key_file: the path to a client key file, for mTLS. :Example: @@ -325,7 +325,6 @@ def __init__( """Logging Settings """ self.logger["package_logger"] = logging.getLogger("petstore_api") - self.logger["urllib3_logger"] = logging.getLogger("urllib3") self.logger_format = '%(asctime)s %(levelname)s %(message)s' """Log format """ @@ -574,9 +573,10 @@ def get_basic_auth_token(self) -> Optional[str]: password = "" if self.password is not None: password = self.password - return urllib3.util.make_headers( - basic_auth=username + ':' + password - ).get('authorization') + + return "Basic " + base64.b64encode( + (username + ":" + password).encode('utf-8') + ).decode('utf-8') def auth_settings(self)-> AuthSettings: """Gets Auth Settings dict for api client. @@ -727,6 +727,7 @@ def get_host_from_settings( variable_name, variable['default_value']) if 'enum_values' in variable \ + and variable['enum_values'] \ and used_value not in variable['enum_values']: raise ValueError( "The variable `{0}` in the host URL has invalid value " 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 0415f9599ae0..0bd1cbdcadd2 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/configuration.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/configuration.py @@ -172,7 +172,7 @@ class 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. - :param key_file: the path to a client key file, for mTLS. + :param key_file: the path to a client key file, for mTLS. :Example: @@ -578,6 +578,7 @@ def get_basic_auth_token(self) -> Optional[str]: password = "" if self.password is not None: password = self.password + return urllib3.util.make_headers( basic_auth=username + ':' + password ).get('authorization') @@ -731,6 +732,7 @@ def get_host_from_settings( variable_name, variable['default_value']) if 'enum_values' in variable \ + and variable['enum_values'] \ and used_value not in variable['enum_values']: raise ValueError( "The variable `{0}` in the host URL has invalid value " diff --git a/samples/openapi3/client/petstore/python/petstore_api/configuration.py b/samples/openapi3/client/petstore/python/petstore_api/configuration.py index 0415f9599ae0..0bd1cbdcadd2 100755 --- a/samples/openapi3/client/petstore/python/petstore_api/configuration.py +++ b/samples/openapi3/client/petstore/python/petstore_api/configuration.py @@ -172,7 +172,7 @@ class 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. - :param key_file: the path to a client key file, for mTLS. + :param key_file: the path to a client key file, for mTLS. :Example: @@ -578,6 +578,7 @@ def get_basic_auth_token(self) -> Optional[str]: password = "" if self.password is not None: password = self.password + return urllib3.util.make_headers( basic_auth=username + ':' + password ).get('authorization') @@ -731,6 +732,7 @@ def get_host_from_settings( variable_name, variable['default_value']) if 'enum_values' in variable \ + and variable['enum_values'] \ and used_value not in variable['enum_values']: raise ValueError( "The variable `{0}` in the host URL has invalid value "