Skip to content

Commit 27cced5

Browse files
authored
feat(python): expose all config properties in constructor (#23021)
* templates * samples * scope to python generator * address suggestions * revert pydantic-v1
1 parent a5e2fdf commit 27cced5

11 files changed

Lines changed: 251 additions & 105 deletions

File tree

modules/openapi-generator/src/main/resources/python-pydantic-v1/configuration.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,4 +613,4 @@ conf = {{{packageName}}}.Configuration(
613613
def host(self, value):
614614
"""Fix base path."""
615615
self._base_path = value
616-
self.server_index = None
616+
self.server_index = None

modules/openapi-generator/src/main/resources/python/configuration.mustache

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ class Configuration:
183183
string values to replace variables in templated server configuration.
184184
The validation of enums is performed for variables with defined enum
185185
values before.
186+
:param verify_ssl: bool - Set this to false to skip verifying SSL certificate
187+
when calling API from https server.
186188
:param ssl_ca_cert: str - the path to a file of concatenated CA certificates
187189
in PEM format.
188190
{{#async}}
@@ -195,6 +197,16 @@ class Configuration:
195197
in PEM (str) or DER (bytes) format.
196198
:param cert_file: the path to a client certificate file, for mTLS.
197199
:param key_file: the path to a client key file, for mTLS.
200+
:param assert_hostname: Set this to True/False to enable/disable SSL hostname verification.
201+
:param tls_server_name: SSL/TLS Server Name Indication (SNI). Set this to the SNI value expected by the server.
202+
:param connection_pool_maxsize: Connection pool max size. None in the constructor is coerced to 100 for async and cpu_count * 5 for sync.
203+
:param proxy: Proxy URL.
204+
:param proxy_headers: Proxy headers.
205+
:param safe_chars_for_path_param: Safe characters for path parameter encoding.
206+
:param client_side_validation: Enable client-side validation. Default True.
207+
:param socket_options: Options to pass down to the underlying urllib3 socket.
208+
:param datetime_format: Datetime format string for serialization.
209+
:param date_format: Date format string for serialization.
198210

199211
{{#hasAuthMethods}}
200212
:Example:
@@ -304,6 +316,17 @@ conf = {{{packageName}}}.Configuration(
304316
ca_cert_data: Optional[Union[str, bytes]] = None,
305317
cert_file: Optional[str]=None,
306318
key_file: Optional[str]=None,
319+
verify_ssl: bool=True,
320+
assert_hostname: Optional[bool]=None,
321+
tls_server_name: Optional[str]=None,
322+
connection_pool_maxsize: Optional[int]=None,
323+
proxy: Optional[str]=None,
324+
proxy_headers: Optional[Any]=None,
325+
safe_chars_for_path_param: str='',
326+
client_side_validation: bool=True,
327+
socket_options: Optional[Any]=None,
328+
datetime_format: str="{{{datetimeFormat}}}",
329+
date_format: str="{{{dateFormat}}}",
307330
*,
308331
debug: Optional[bool] = None,
309332
) -> None:
@@ -382,7 +405,7 @@ conf = {{{packageName}}}.Configuration(
382405
"""Debug switch
383406
"""
384407

385-
self.verify_ssl = True
408+
self.verify_ssl = verify_ssl
386409
"""SSL/TLS verification
387410
Set this to false to skip verifying SSL certificate when calling API
388411
from https server.
@@ -400,54 +423,51 @@ conf = {{{packageName}}}.Configuration(
400423
self.key_file = key_file
401424
"""client key file
402425
"""
403-
self.assert_hostname = None
426+
self.assert_hostname = assert_hostname
404427
"""Set this to True/False to enable/disable SSL hostname verification.
405428
"""
406-
self.tls_server_name = None
429+
self.tls_server_name = tls_server_name
407430
"""SSL/TLS Server Name Indication (SNI)
408431
Set this to the SNI value expected by the server.
409432
"""
410433

411434
{{#async}}
412-
self.connection_pool_maxsize = 100
435+
self.connection_pool_maxsize = connection_pool_maxsize if connection_pool_maxsize is not None else 100
413436
"""This value is passed to the aiohttp to limit simultaneous connections.
414-
Default values is 100, None means no-limit.
437+
None in the constructor is coerced to default 100.
415438
"""
416439
{{/async}}
417440
{{^async}}
418-
self.connection_pool_maxsize = multiprocessing.cpu_count() * 5
441+
self.connection_pool_maxsize = connection_pool_maxsize if connection_pool_maxsize is not None else multiprocessing.cpu_count() * 5
419442
"""urllib3 connection pool's maximum number of connections saved
420-
per pool. urllib3 uses 1 connection as default value, but this is
421-
not the best value when you are making a lot of possibly parallel
422-
requests to the same host, which is often the case here.
423-
cpu_count * 5 is used as default value to increase performance.
443+
per pool. None in the constructor is coerced to cpu_count * 5.
424444
"""
425445
{{/async}}
426446

427-
self.proxy: Optional[str] = None
447+
self.proxy = proxy
428448
"""Proxy URL
429449
"""
430-
self.proxy_headers = None
450+
self.proxy_headers = proxy_headers
431451
"""Proxy headers
432452
"""
433-
self.safe_chars_for_path_param = ''
453+
self.safe_chars_for_path_param = safe_chars_for_path_param
434454
"""Safe chars for path_param
435455
"""
436456
self.retries = retries
437457
"""Retry configuration
438458
"""
439459
# Enable client side validation
440-
self.client_side_validation = True
460+
self.client_side_validation = client_side_validation
441461

442-
self.socket_options = None
462+
self.socket_options = socket_options
443463
"""Options to pass down to the underlying urllib3 socket
444464
"""
445465

446-
self.datetime_format = "{{{datetimeFormat}}}"
466+
self.datetime_format = datetime_format
447467
"""datetime format
448468
"""
449469

450-
self.date_format = "{{{dateFormat}}}"
470+
self.date_format = date_format
451471
"""date format
452472
"""
453473

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/configuration.py

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,25 @@ class Configuration:
158158
string values to replace variables in templated server configuration.
159159
The validation of enums is performed for variables with defined enum
160160
values before.
161+
:param verify_ssl: bool - Set this to false to skip verifying SSL certificate
162+
when calling API from https server.
161163
:param ssl_ca_cert: str - the path to a file of concatenated CA certificates
162164
in PEM format.
163165
:param retries: int | urllib3.util.retry.Retry - Retry configuration.
164166
:param ca_cert_data: verify the peer using concatenated CA certificate data
165167
in PEM (str) or DER (bytes) format.
166168
:param cert_file: the path to a client certificate file, for mTLS.
167169
:param key_file: the path to a client key file, for mTLS.
170+
:param assert_hostname: Set this to True/False to enable/disable SSL hostname verification.
171+
:param tls_server_name: SSL/TLS Server Name Indication (SNI). Set this to the SNI value expected by the server.
172+
:param connection_pool_maxsize: Connection pool max size. None in the constructor is coerced to 100 for async and cpu_count * 5 for sync.
173+
:param proxy: Proxy URL.
174+
:param proxy_headers: Proxy headers.
175+
:param safe_chars_for_path_param: Safe characters for path parameter encoding.
176+
:param client_side_validation: Enable client-side validation. Default True.
177+
:param socket_options: Options to pass down to the underlying urllib3 socket.
178+
:param datetime_format: Datetime format string for serialization.
179+
:param date_format: Date format string for serialization.
168180
169181
:Example:
170182
@@ -205,6 +217,17 @@ def __init__(
205217
ca_cert_data: Optional[Union[str, bytes]] = None,
206218
cert_file: Optional[str]=None,
207219
key_file: Optional[str]=None,
220+
verify_ssl: bool=True,
221+
assert_hostname: Optional[bool]=None,
222+
tls_server_name: Optional[str]=None,
223+
connection_pool_maxsize: Optional[int]=None,
224+
proxy: Optional[str]=None,
225+
proxy_headers: Optional[Any]=None,
226+
safe_chars_for_path_param: str='',
227+
client_side_validation: bool=True,
228+
socket_options: Optional[Any]=None,
229+
datetime_format: str="%Y-%m-%dT%H:%M:%S.%f%z",
230+
date_format: str="%Y-%m-%d",
208231
*,
209232
debug: Optional[bool] = None,
210233
) -> None:
@@ -274,7 +297,7 @@ def __init__(
274297
"""Debug switch
275298
"""
276299

277-
self.verify_ssl = True
300+
self.verify_ssl = verify_ssl
278301
"""SSL/TLS verification
279302
Set this to false to skip verifying SSL certificate when calling API
280303
from https server.
@@ -292,46 +315,43 @@ def __init__(
292315
self.key_file = key_file
293316
"""client key file
294317
"""
295-
self.assert_hostname = None
318+
self.assert_hostname = assert_hostname
296319
"""Set this to True/False to enable/disable SSL hostname verification.
297320
"""
298-
self.tls_server_name = None
321+
self.tls_server_name = tls_server_name
299322
"""SSL/TLS Server Name Indication (SNI)
300323
Set this to the SNI value expected by the server.
301324
"""
302325

303-
self.connection_pool_maxsize = multiprocessing.cpu_count() * 5
326+
self.connection_pool_maxsize = connection_pool_maxsize if connection_pool_maxsize is not None else multiprocessing.cpu_count() * 5
304327
"""urllib3 connection pool's maximum number of connections saved
305-
per pool. urllib3 uses 1 connection as default value, but this is
306-
not the best value when you are making a lot of possibly parallel
307-
requests to the same host, which is often the case here.
308-
cpu_count * 5 is used as default value to increase performance.
328+
per pool. None in the constructor is coerced to cpu_count * 5.
309329
"""
310330

311-
self.proxy: Optional[str] = None
331+
self.proxy = proxy
312332
"""Proxy URL
313333
"""
314-
self.proxy_headers = None
334+
self.proxy_headers = proxy_headers
315335
"""Proxy headers
316336
"""
317-
self.safe_chars_for_path_param = ''
337+
self.safe_chars_for_path_param = safe_chars_for_path_param
318338
"""Safe chars for path_param
319339
"""
320340
self.retries = retries
321341
"""Retry configuration
322342
"""
323343
# Enable client side validation
324-
self.client_side_validation = True
344+
self.client_side_validation = client_side_validation
325345

326-
self.socket_options = None
346+
self.socket_options = socket_options
327347
"""Options to pass down to the underlying urllib3 socket
328348
"""
329349

330-
self.datetime_format = "%Y-%m-%dT%H:%M:%S.%f%z"
350+
self.datetime_format = datetime_format
331351
"""datetime format
332352
"""
333353

334-
self.date_format = "%Y-%m-%d"
354+
self.date_format = date_format
335355
"""date format
336356
"""
337357

samples/client/echo_api/python-pydantic-v1/openapi_client/configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,4 +463,4 @@ def host(self):
463463
def host(self, value):
464464
"""Fix base path."""
465465
self._base_path = value
466-
self.server_index = None
466+
self.server_index = None

samples/client/echo_api/python/openapi_client/configuration.py

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,25 @@ class Configuration:
158158
string values to replace variables in templated server configuration.
159159
The validation of enums is performed for variables with defined enum
160160
values before.
161+
:param verify_ssl: bool - Set this to false to skip verifying SSL certificate
162+
when calling API from https server.
161163
:param ssl_ca_cert: str - the path to a file of concatenated CA certificates
162164
in PEM format.
163165
:param retries: int | urllib3.util.retry.Retry - Retry configuration.
164166
:param ca_cert_data: verify the peer using concatenated CA certificate data
165167
in PEM (str) or DER (bytes) format.
166168
:param cert_file: the path to a client certificate file, for mTLS.
167169
:param key_file: the path to a client key file, for mTLS.
170+
:param assert_hostname: Set this to True/False to enable/disable SSL hostname verification.
171+
:param tls_server_name: SSL/TLS Server Name Indication (SNI). Set this to the SNI value expected by the server.
172+
:param connection_pool_maxsize: Connection pool max size. None in the constructor is coerced to 100 for async and cpu_count * 5 for sync.
173+
:param proxy: Proxy URL.
174+
:param proxy_headers: Proxy headers.
175+
:param safe_chars_for_path_param: Safe characters for path parameter encoding.
176+
:param client_side_validation: Enable client-side validation. Default True.
177+
:param socket_options: Options to pass down to the underlying urllib3 socket.
178+
:param datetime_format: Datetime format string for serialization.
179+
:param date_format: Date format string for serialization.
168180
169181
:Example:
170182
@@ -205,6 +217,17 @@ def __init__(
205217
ca_cert_data: Optional[Union[str, bytes]] = None,
206218
cert_file: Optional[str]=None,
207219
key_file: Optional[str]=None,
220+
verify_ssl: bool=True,
221+
assert_hostname: Optional[bool]=None,
222+
tls_server_name: Optional[str]=None,
223+
connection_pool_maxsize: Optional[int]=None,
224+
proxy: Optional[str]=None,
225+
proxy_headers: Optional[Any]=None,
226+
safe_chars_for_path_param: str='',
227+
client_side_validation: bool=True,
228+
socket_options: Optional[Any]=None,
229+
datetime_format: str="%Y-%m-%dT%H:%M:%S.%f%z",
230+
date_format: str="%Y-%m-%d",
208231
*,
209232
debug: Optional[bool] = None,
210233
) -> None:
@@ -274,7 +297,7 @@ def __init__(
274297
"""Debug switch
275298
"""
276299

277-
self.verify_ssl = True
300+
self.verify_ssl = verify_ssl
278301
"""SSL/TLS verification
279302
Set this to false to skip verifying SSL certificate when calling API
280303
from https server.
@@ -292,46 +315,43 @@ def __init__(
292315
self.key_file = key_file
293316
"""client key file
294317
"""
295-
self.assert_hostname = None
318+
self.assert_hostname = assert_hostname
296319
"""Set this to True/False to enable/disable SSL hostname verification.
297320
"""
298-
self.tls_server_name = None
321+
self.tls_server_name = tls_server_name
299322
"""SSL/TLS Server Name Indication (SNI)
300323
Set this to the SNI value expected by the server.
301324
"""
302325

303-
self.connection_pool_maxsize = multiprocessing.cpu_count() * 5
326+
self.connection_pool_maxsize = connection_pool_maxsize if connection_pool_maxsize is not None else multiprocessing.cpu_count() * 5
304327
"""urllib3 connection pool's maximum number of connections saved
305-
per pool. urllib3 uses 1 connection as default value, but this is
306-
not the best value when you are making a lot of possibly parallel
307-
requests to the same host, which is often the case here.
308-
cpu_count * 5 is used as default value to increase performance.
328+
per pool. None in the constructor is coerced to cpu_count * 5.
309329
"""
310330

311-
self.proxy: Optional[str] = None
331+
self.proxy = proxy
312332
"""Proxy URL
313333
"""
314-
self.proxy_headers = None
334+
self.proxy_headers = proxy_headers
315335
"""Proxy headers
316336
"""
317-
self.safe_chars_for_path_param = ''
337+
self.safe_chars_for_path_param = safe_chars_for_path_param
318338
"""Safe chars for path_param
319339
"""
320340
self.retries = retries
321341
"""Retry configuration
322342
"""
323343
# Enable client side validation
324-
self.client_side_validation = True
344+
self.client_side_validation = client_side_validation
325345

326-
self.socket_options = None
346+
self.socket_options = socket_options
327347
"""Options to pass down to the underlying urllib3 socket
328348
"""
329349

330-
self.datetime_format = "%Y-%m-%dT%H:%M:%S.%f%z"
350+
self.datetime_format = datetime_format
331351
"""datetime format
332352
"""
333353

334-
self.date_format = "%Y-%m-%d"
354+
self.date_format = date_format
335355
"""date format
336356
"""
337357

0 commit comments

Comments
 (0)