From 68b0dfe6d16bec38a61dcfbe2f1fe46c412ab0a2 Mon Sep 17 00:00:00 2001 From: Eddie Sholl Date: Tue, 28 Oct 2025 15:33:05 +1100 Subject: [PATCH] Expose mtls certificate config params in python and php configuration templates (#22229) * Expose mtls config params in python template * Expose certFile and keyFile configuration items to support mtls in php generated client * Regenerate of examples --- .../main/resources/php/Configuration.mustache | 57 +++++++++++++++++++ .../src/main/resources/php/api.mustache | 8 +++ .../resources/python/configuration.mustache | 8 ++- .../openapi_client/configuration.py | 8 ++- .../python/openapi_client/configuration.py | 8 ++- .../lib/Api/AnotherFakeApi.php | 8 +++ .../OpenAPIClient-php/lib/Api/DefaultApi.php | 8 +++ .../php/OpenAPIClient-php/lib/Api/FakeApi.php | 8 +++ .../lib/Api/FakeClassnameTags123Api.php | 8 +++ .../php/OpenAPIClient-php/lib/Api/PetApi.php | 8 +++ .../OpenAPIClient-php/lib/Api/StoreApi.php | 8 +++ .../php/OpenAPIClient-php/lib/Api/UserApi.php | 8 +++ .../OpenAPIClient-php/lib/Configuration.php | 57 +++++++++++++++++++ .../petstore/php/psr-18/lib/Configuration.php | 57 +++++++++++++++++++ .../petstore_api/configuration.py | 8 ++- .../petstore_api/configuration.py | 8 ++- .../petstore_api/configuration.py | 8 ++- .../python/petstore_api/configuration.py | 8 ++- 18 files changed, 277 insertions(+), 14 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/php/Configuration.mustache b/modules/openapi-generator/src/main/resources/php/Configuration.mustache index df34eeec3f9..8b0c3ea38ff 100644 --- a/modules/openapi-generator/src/main/resources/php/Configuration.mustache +++ b/modules/openapi-generator/src/main/resources/php/Configuration.mustache @@ -115,6 +115,20 @@ class Configuration */ protected $tempFolderPath; + /** + * Path to a certificate file, for mTLS + * + * @var string + */ + protected $certFile; + + /** + * Path to a key file, for mTLS + * + * @var string + */ + protected $keyFile; + /** * Constructor */ @@ -388,6 +402,49 @@ class Configuration return $this->tempFolderPath; } + /** + * Sets the certificate file path, for mTLS + * + * @return $this + */ + public function setCertFile($certFile) + { + $this->certFile = $certFile; + return $this; + } + + /** + * Gets the certificate file path, for mTLS + * + * @return string Certificate file path + */ + public function getCertFile() + { + return $this->certFile; + } + + /** + * Sets the certificate key path, for mTLS + * + * @return $this + */ + public function setKeyFile($keyFile) + { + $this->keyFile = $keyFile; + return $this; + } + + /** + * Gets the certificate key path, for mTLS + * + * @return string Certificate key path + */ + public function getKeyFile() + { + return $this->keyFile; + } + + /** * Gets the default configuration instance * diff --git a/modules/openapi-generator/src/main/resources/php/api.mustache b/modules/openapi-generator/src/main/resources/php/api.mustache index 1a0e561f7a0..f7455121941 100644 --- a/modules/openapi-generator/src/main/resources/php/api.mustache +++ b/modules/openapi-generator/src/main/resources/php/api.mustache @@ -832,6 +832,14 @@ use {{invokerPackage}}\ObjectSerializer; } } + if ($this->config->getCertFile()) { + $options[RequestOptions::CERT] = $this->config->getCertFile(); + } + + if ($this->config->getKeyFile()) { + $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile(); + } + return $options; } diff --git a/modules/openapi-generator/src/main/resources/python/configuration.mustache b/modules/openapi-generator/src/main/resources/python/configuration.mustache index 97e0f93efc3..511281f298e 100644 --- a/modules/openapi-generator/src/main/resources/python/configuration.mustache +++ b/modules/openapi-generator/src/main/resources/python/configuration.mustache @@ -186,6 +186,8 @@ class Configuration: :param retries: Number of retries for API requests. :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. {{#hasAuthMethods}} :Example: @@ -293,6 +295,8 @@ conf = {{{packageName}}}.Configuration( ssl_ca_cert: Optional[str]=None, retries: Optional[int] = None, ca_cert_data: Optional[Union[str, bytes]] = None, + cert_file: Optional[str]=None, + key_file: Optional[str]=None, *, debug: Optional[bool] = None, ) -> None: @@ -381,10 +385,10 @@ conf = {{{packageName}}}.Configuration( """Set this to verify the peer using PEM (str) or DER (bytes) certificate data. """ - self.cert_file = None + self.cert_file = cert_file """client certificate file """ - self.key_file = None + self.key_file = key_file """client key file """ self.assert_hostname = None 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 d1ae379ac7b..6f5f511966c 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/configuration.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/configuration.py @@ -165,6 +165,8 @@ class Configuration: :param retries: Number of retries for API requests. :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. :Example: @@ -203,6 +205,8 @@ conf = openapi_client.Configuration( ssl_ca_cert: Optional[str]=None, retries: Optional[int] = None, ca_cert_data: Optional[Union[str, bytes]] = None, + cert_file: Optional[str]=None, + key_file: Optional[str]=None, *, debug: Optional[bool] = None, ) -> None: @@ -284,10 +288,10 @@ conf = openapi_client.Configuration( """Set this to verify the peer using PEM (str) or DER (bytes) certificate data. """ - self.cert_file = None + self.cert_file = cert_file """client certificate file """ - self.key_file = None + self.key_file = key_file """client key file """ self.assert_hostname = None diff --git a/samples/client/echo_api/python/openapi_client/configuration.py b/samples/client/echo_api/python/openapi_client/configuration.py index d1ae379ac7b..6f5f511966c 100644 --- a/samples/client/echo_api/python/openapi_client/configuration.py +++ b/samples/client/echo_api/python/openapi_client/configuration.py @@ -165,6 +165,8 @@ class Configuration: :param retries: Number of retries for API requests. :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. :Example: @@ -203,6 +205,8 @@ conf = openapi_client.Configuration( ssl_ca_cert: Optional[str]=None, retries: Optional[int] = None, ca_cert_data: Optional[Union[str, bytes]] = None, + cert_file: Optional[str]=None, + key_file: Optional[str]=None, *, debug: Optional[bool] = None, ) -> None: @@ -284,10 +288,10 @@ conf = openapi_client.Configuration( """Set this to verify the peer using PEM (str) or DER (bytes) certificate data. """ - self.cert_file = None + self.cert_file = cert_file """client certificate file """ - self.key_file = None + self.key_file = key_file """client key file """ self.assert_hostname = None diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php index ed9bd19716e..7d28533d1ae 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php @@ -408,6 +408,14 @@ class AnotherFakeApi } } + if ($this->config->getCertFile()) { + $options[RequestOptions::CERT] = $this->config->getCertFile(); + } + + if ($this->config->getKeyFile()) { + $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile(); + } + return $options; } diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/DefaultApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/DefaultApi.php index d48f651ef39..6c1e0b73d95 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/DefaultApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/DefaultApi.php @@ -381,6 +381,14 @@ class DefaultApi } } + if ($this->config->getCertFile()) { + $options[RequestOptions::CERT] = $this->config->getCertFile(); + } + + if ($this->config->getKeyFile()) { + $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile(); + } + return $options; } diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php index 8dcc28d68cc..ba87d1406f0 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php @@ -7578,6 +7578,14 @@ class FakeApi } } + if ($this->config->getCertFile()) { + $options[RequestOptions::CERT] = $this->config->getCertFile(); + } + + if ($this->config->getKeyFile()) { + $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile(); + } + return $options; } diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php index 6b2e7568627..b71896853be 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php @@ -413,6 +413,14 @@ class FakeClassnameTags123Api } } + if ($this->config->getCertFile()) { + $options[RequestOptions::CERT] = $this->config->getCertFile(); + } + + if ($this->config->getKeyFile()) { + $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile(); + } + return $options; } diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php index 120fcc7864c..bebec189963 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php @@ -3450,6 +3450,14 @@ class PetApi } } + if ($this->config->getCertFile()) { + $options[RequestOptions::CERT] = $this->config->getCertFile(); + } + + if ($this->config->getKeyFile()) { + $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile(); + } + return $options; } diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php index 859b39524e7..b7496eac95f 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php @@ -1162,6 +1162,14 @@ class StoreApi } } + if ($this->config->getCertFile()) { + $options[RequestOptions::CERT] = $this->config->getCertFile(); + } + + if ($this->config->getKeyFile()) { + $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile(); + } + return $options; } diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php index 0f36cb0c2d6..823d362f84b 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php @@ -2024,6 +2024,14 @@ class UserApi } } + if ($this->config->getCertFile()) { + $options[RequestOptions::CERT] = $this->config->getCertFile(); + } + + if ($this->config->getKeyFile()) { + $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile(); + } + return $options; } diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Configuration.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Configuration.php index 81797bf53ab..953b357448a 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Configuration.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Configuration.php @@ -123,6 +123,20 @@ class Configuration */ protected $tempFolderPath; + /** + * Path to a certificate file, for mTLS + * + * @var string + */ + protected $certFile; + + /** + * Path to a key file, for mTLS + * + * @var string + */ + protected $keyFile; + /** * Constructor */ @@ -396,6 +410,49 @@ class Configuration return $this->tempFolderPath; } + /** + * Sets the certificate file path, for mTLS + * + * @return $this + */ + public function setCertFile($certFile) + { + $this->certFile = $certFile; + return $this; + } + + /** + * Gets the certificate file path, for mTLS + * + * @return string Certificate file path + */ + public function getCertFile() + { + return $this->certFile; + } + + /** + * Sets the certificate key path, for mTLS + * + * @return $this + */ + public function setKeyFile($keyFile) + { + $this->keyFile = $keyFile; + return $this; + } + + /** + * Gets the certificate key path, for mTLS + * + * @return string Certificate key path + */ + public function getKeyFile() + { + return $this->keyFile; + } + + /** * Gets the default configuration instance * diff --git a/samples/client/petstore/php/psr-18/lib/Configuration.php b/samples/client/petstore/php/psr-18/lib/Configuration.php index 81797bf53ab..953b357448a 100644 --- a/samples/client/petstore/php/psr-18/lib/Configuration.php +++ b/samples/client/petstore/php/psr-18/lib/Configuration.php @@ -123,6 +123,20 @@ class Configuration */ protected $tempFolderPath; + /** + * Path to a certificate file, for mTLS + * + * @var string + */ + protected $certFile; + + /** + * Path to a key file, for mTLS + * + * @var string + */ + protected $keyFile; + /** * Constructor */ @@ -396,6 +410,49 @@ class Configuration return $this->tempFolderPath; } + /** + * Sets the certificate file path, for mTLS + * + * @return $this + */ + public function setCertFile($certFile) + { + $this->certFile = $certFile; + return $this; + } + + /** + * Gets the certificate file path, for mTLS + * + * @return string Certificate file path + */ + public function getCertFile() + { + return $this->certFile; + } + + /** + * Sets the certificate key path, for mTLS + * + * @return $this + */ + public function setKeyFile($keyFile) + { + $this->keyFile = $keyFile; + return $this; + } + + /** + * Gets the certificate key path, for mTLS + * + * @return string Certificate key path + */ + public function getKeyFile() + { + return $this->keyFile; + } + + /** * Gets the default configuration instance * 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 5738e19cf7b..2d12349c1a3 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/configuration.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/configuration.py @@ -170,6 +170,8 @@ class Configuration: :param retries: Number of retries for API requests. :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. :Example: @@ -267,6 +269,8 @@ conf = petstore_api.Configuration( ssl_ca_cert: Optional[str]=None, retries: Optional[int] = None, ca_cert_data: Optional[Union[str, bytes]] = None, + cert_file: Optional[str]=None, + key_file: Optional[str]=None, *, debug: Optional[bool] = None, ) -> None: @@ -353,10 +357,10 @@ conf = petstore_api.Configuration( """Set this to verify the peer using PEM (str) or DER (bytes) certificate data. """ - self.cert_file = None + self.cert_file = cert_file """client certificate file """ - self.key_file = None + self.key_file = key_file """client key file """ self.assert_hostname = None 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 5738e19cf7b..2d12349c1a3 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/configuration.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/configuration.py @@ -170,6 +170,8 @@ class Configuration: :param retries: Number of retries for API requests. :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. :Example: @@ -267,6 +269,8 @@ conf = petstore_api.Configuration( ssl_ca_cert: Optional[str]=None, retries: Optional[int] = None, ca_cert_data: Optional[Union[str, bytes]] = None, + cert_file: Optional[str]=None, + key_file: Optional[str]=None, *, debug: Optional[bool] = None, ) -> None: @@ -353,10 +357,10 @@ conf = petstore_api.Configuration( """Set this to verify the peer using PEM (str) or DER (bytes) certificate data. """ - self.cert_file = None + self.cert_file = cert_file """client certificate file """ - self.key_file = None + self.key_file = key_file """client key file """ self.assert_hostname = None 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 cb081f807f5..0415f9599ae 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/configuration.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/configuration.py @@ -171,6 +171,8 @@ class Configuration: :param retries: Number of retries for API requests. :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. :Example: @@ -268,6 +270,8 @@ conf = petstore_api.Configuration( ssl_ca_cert: Optional[str]=None, retries: Optional[int] = None, ca_cert_data: Optional[Union[str, bytes]] = None, + cert_file: Optional[str]=None, + key_file: Optional[str]=None, *, debug: Optional[bool] = None, ) -> None: @@ -354,10 +358,10 @@ conf = petstore_api.Configuration( """Set this to verify the peer using PEM (str) or DER (bytes) certificate data. """ - self.cert_file = None + self.cert_file = cert_file """client certificate file """ - self.key_file = None + self.key_file = key_file """client key file """ self.assert_hostname = None diff --git a/samples/openapi3/client/petstore/python/petstore_api/configuration.py b/samples/openapi3/client/petstore/python/petstore_api/configuration.py index cb081f807f5..0415f9599ae 100755 --- a/samples/openapi3/client/petstore/python/petstore_api/configuration.py +++ b/samples/openapi3/client/petstore/python/petstore_api/configuration.py @@ -171,6 +171,8 @@ class Configuration: :param retries: Number of retries for API requests. :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. :Example: @@ -268,6 +270,8 @@ conf = petstore_api.Configuration( ssl_ca_cert: Optional[str]=None, retries: Optional[int] = None, ca_cert_data: Optional[Union[str, bytes]] = None, + cert_file: Optional[str]=None, + key_file: Optional[str]=None, *, debug: Optional[bool] = None, ) -> None: @@ -354,10 +358,10 @@ conf = petstore_api.Configuration( """Set this to verify the peer using PEM (str) or DER (bytes) certificate data. """ - self.cert_file = None + self.cert_file = cert_file """client certificate file """ - self.key_file = None + self.key_file = key_file """client key file """ self.assert_hostname = None