13
13
14
14
15
15
import copy
16
+ import http .client as httplib
16
17
import logging
17
18
from logging import FileHandler
18
19
import multiprocessing
19
20
import sys
20
- from typing import Optional
21
+ from typing import Any , ClassVar , Dict , List , Literal , Optional , TypedDict
22
+ from typing_extensions import NotRequired , Self
23
+
21
24
import urllib3
22
25
23
- import http .client as httplib
24
26
25
27
JSON_SCHEMA_VALIDATION_KEYWORDS = {
26
28
'multipleOf' , 'maximum' , 'exclusiveMaximum' ,
27
29
'minimum' , 'exclusiveMinimum' , 'maxLength' ,
28
30
'minLength' , 'pattern' , 'maxItems' , 'minItems'
29
31
}
30
32
33
+ ServerVariablesT = Dict [str , str ]
34
+
35
+ GenericAuthSetting = TypedDict (
36
+ "GenericAuthSetting" ,
37
+ {
38
+ "type" : str ,
39
+ "in" : str ,
40
+ "key" : str ,
41
+ "value" : str ,
42
+ },
43
+ )
44
+
45
+
46
+ OAuth2AuthSetting = TypedDict (
47
+ "OAuth2AuthSetting" ,
48
+ {
49
+ "type" : Literal ["oauth2" ],
50
+ "in" : Literal ["header" ],
51
+ "key" : Literal ["Authorization" ],
52
+ "value" : str ,
53
+ },
54
+ )
55
+
56
+
57
+ APIKeyAuthSetting = TypedDict (
58
+ "APIKeyAuthSetting" ,
59
+ {
60
+ "type" : Literal ["api_key" ],
61
+ "in" : str ,
62
+ "key" : str ,
63
+ "value" : Optional [str ],
64
+ },
65
+ )
66
+
67
+
68
+ BasicAuthSetting = TypedDict (
69
+ "BasicAuthSetting" ,
70
+ {
71
+ "type" : Literal ["basic" ],
72
+ "in" : Literal ["header" ],
73
+ "key" : Literal ["Authorization" ],
74
+ "value" : Optional [str ],
75
+ },
76
+ )
77
+
78
+
79
+ BearerFormatAuthSetting = TypedDict (
80
+ "BearerFormatAuthSetting" ,
81
+ {
82
+ "type" : Literal ["bearer" ],
83
+ "in" : Literal ["header" ],
84
+ "format" : Literal ["JWT" ],
85
+ "key" : Literal ["Authorization" ],
86
+ "value" : str ,
87
+ },
88
+ )
89
+
90
+
91
+ BearerAuthSetting = TypedDict (
92
+ "BearerAuthSetting" ,
93
+ {
94
+ "type" : Literal ["bearer" ],
95
+ "in" : Literal ["header" ],
96
+ "key" : Literal ["Authorization" ],
97
+ "value" : str ,
98
+ },
99
+ )
100
+
101
+
102
+ HTTPSignatureAuthSetting = TypedDict (
103
+ "HTTPSignatureAuthSetting" ,
104
+ {
105
+ "type" : Literal ["http-signature" ],
106
+ "in" : Literal ["header" ],
107
+ "key" : Literal ["Authorization" ],
108
+ "value" : None ,
109
+ },
110
+ )
111
+
112
+
113
+ AuthSettings = TypedDict (
114
+ "AuthSettings" ,
115
+ {
116
+ "X-Api-Key" : APIKeyAuthSetting ,
117
+ "apikey" : APIKeyAuthSetting ,
118
+ },
119
+ total = False ,
120
+ )
121
+
122
+
123
+ class HostSettingVariable (TypedDict ):
124
+ description : str
125
+ default_value : str
126
+ enum_values : List [str ]
127
+
128
+
129
+ class HostSetting (TypedDict ):
130
+ url : str
131
+ description : str
132
+ variables : NotRequired [Dict [str , HostSettingVariable ]]
133
+
134
+
31
135
class Configuration :
32
136
"""This class contains various settings of the API client.
33
137
@@ -81,20 +185,26 @@ class Configuration:
81
185
Cookie: JSESSIONID abc123
82
186
"""
83
187
84
- _default = None
85
-
86
- def __init__ (self , host = None ,
87
- api_key = None , api_key_prefix = None ,
88
- username = None , password = None ,
89
- access_token = None ,
90
- server_index = None , server_variables = None ,
91
- server_operation_index = None , server_operation_variables = None ,
92
- ignore_operation_servers = False ,
93
- ssl_ca_cert = None ,
94
- retries = None ,
95
- * ,
96
- debug : Optional [bool ] = None
97
- ) -> None :
188
+ _default : ClassVar [Optional [Self ]] = None
189
+
190
+ def __init__ (
191
+ self ,
192
+ host : Optional [str ]= None ,
193
+ api_key : Optional [Dict [str , str ]]= None ,
194
+ api_key_prefix : Optional [Dict [str , str ]]= None ,
195
+ username : Optional [str ]= None ,
196
+ password : Optional [str ]= None ,
197
+ access_token : Optional [str ]= None ,
198
+ server_index : Optional [int ]= None ,
199
+ server_variables : Optional [ServerVariablesT ]= None ,
200
+ server_operation_index : Optional [Dict [int , int ]]= None ,
201
+ server_operation_variables : Optional [Dict [int , ServerVariablesT ]]= None ,
202
+ ignore_operation_servers : bool = False ,
203
+ ssl_ca_cert : Optional [str ]= None ,
204
+ retries : Optional [int ] = None ,
205
+ * ,
206
+ debug : Optional [bool ] = None ,
207
+ ) -> None :
98
208
"""Constructor
99
209
"""
100
210
self ._base_path = "http://localhost:8989" if host is None else host
@@ -218,7 +328,7 @@ def __init__(self, host=None,
218
328
"""date format
219
329
"""
220
330
221
- def __deepcopy__ (self , memo ) :
331
+ def __deepcopy__ (self , memo : Dict [ int , Any ]) -> Self :
222
332
cls = self .__class__
223
333
result = cls .__new__ (cls )
224
334
memo [id (self )] = result
@@ -232,11 +342,11 @@ def __deepcopy__(self, memo):
232
342
result .debug = self .debug
233
343
return result
234
344
235
- def __setattr__ (self , name , value ) :
345
+ def __setattr__ (self , name : str , value : Any ) -> None :
236
346
object .__setattr__ (self , name , value )
237
347
238
348
@classmethod
239
- def set_default (cls , default ) :
349
+ def set_default (cls , default : Optional [ Self ]) -> None :
240
350
"""Set default instance of configuration.
241
351
242
352
It stores default configuration, which can be
@@ -247,7 +357,7 @@ def set_default(cls, default):
247
357
cls ._default = default
248
358
249
359
@classmethod
250
- def get_default_copy (cls ):
360
+ def get_default_copy (cls ) -> Self :
251
361
"""Deprecated. Please use `get_default` instead.
252
362
253
363
Deprecated. Please use `get_default` instead.
@@ -257,7 +367,7 @@ def get_default_copy(cls):
257
367
return cls .get_default ()
258
368
259
369
@classmethod
260
- def get_default (cls ):
370
+ def get_default (cls ) -> Self :
261
371
"""Return the default configuration.
262
372
263
373
This method returns newly created, based on default constructor,
@@ -267,11 +377,11 @@ def get_default(cls):
267
377
:return: The configuration object.
268
378
"""
269
379
if cls ._default is None :
270
- cls ._default = Configuration ()
380
+ cls ._default = cls ()
271
381
return cls ._default
272
382
273
383
@property
274
- def logger_file (self ):
384
+ def logger_file (self ) -> Optional [ str ] :
275
385
"""The logger file.
276
386
277
387
If the logger_file is None, then add stream handler and remove file
@@ -283,7 +393,7 @@ def logger_file(self):
283
393
return self .__logger_file
284
394
285
395
@logger_file .setter
286
- def logger_file (self , value ) :
396
+ def logger_file (self , value : Optional [ str ]) -> None :
287
397
"""The logger file.
288
398
289
399
If the logger_file is None, then add stream handler and remove file
@@ -302,7 +412,7 @@ def logger_file(self, value):
302
412
logger .addHandler (self .logger_file_handler )
303
413
304
414
@property
305
- def debug (self ):
415
+ def debug (self ) -> bool :
306
416
"""Debug status
307
417
308
418
:param value: The debug status, True or False.
@@ -311,7 +421,7 @@ def debug(self):
311
421
return self .__debug
312
422
313
423
@debug .setter
314
- def debug (self , value ) :
424
+ def debug (self , value : bool ) -> None :
315
425
"""Debug status
316
426
317
427
:param value: The debug status, True or False.
@@ -333,7 +443,7 @@ def debug(self, value):
333
443
httplib .HTTPConnection .debuglevel = 0
334
444
335
445
@property
336
- def logger_format (self ):
446
+ def logger_format (self ) -> str :
337
447
"""The logger format.
338
448
339
449
The logger_formatter will be updated when sets logger_format.
@@ -344,7 +454,7 @@ def logger_format(self):
344
454
return self .__logger_format
345
455
346
456
@logger_format .setter
347
- def logger_format (self , value ) :
457
+ def logger_format (self , value : str ) -> None :
348
458
"""The logger format.
349
459
350
460
The logger_formatter will be updated when sets logger_format.
@@ -355,7 +465,7 @@ def logger_format(self, value):
355
465
self .__logger_format = value
356
466
self .logger_formatter = logging .Formatter (self .__logger_format )
357
467
358
- def get_api_key_with_prefix (self , identifier , alias = None ):
468
+ def get_api_key_with_prefix (self , identifier : str , alias : Optional [ str ] = None ) -> Optional [ str ] :
359
469
"""Gets API key (with prefix if set).
360
470
361
471
:param identifier: The identifier of apiKey.
@@ -372,7 +482,9 @@ def get_api_key_with_prefix(self, identifier, alias=None):
372
482
else :
373
483
return key
374
484
375
- def get_basic_auth_token (self ):
485
+ return None
486
+
487
+ def get_basic_auth_token (self ) -> Optional [str ]:
376
488
"""Gets HTTP basic authentication header (string).
377
489
378
490
:return: The token for basic HTTP authentication.
@@ -387,12 +499,12 @@ def get_basic_auth_token(self):
387
499
basic_auth = username + ':' + password
388
500
).get ('authorization' )
389
501
390
- def auth_settings (self ):
502
+ def auth_settings (self )-> AuthSettings :
391
503
"""Gets Auth Settings dict for api client.
392
504
393
505
:return: The Auth Settings information dict.
394
506
"""
395
- auth = {}
507
+ auth : AuthSettings = {}
396
508
if 'X-Api-Key' in self .api_key :
397
509
auth ['X-Api-Key' ] = {
398
510
'type' : 'api_key' ,
@@ -413,7 +525,7 @@ def auth_settings(self):
413
525
}
414
526
return auth
415
527
416
- def to_debug_report (self ):
528
+ def to_debug_report (self ) -> str :
417
529
"""Gets the essential information for debugging.
418
530
419
531
:return: The report for debugging.
@@ -425,7 +537,7 @@ def to_debug_report(self):
425
537
"SDK Package Version: {v}" .\
426
538
format (env = sys .platform , pyversion = sys .version , v = "1.0.2" ) # x-release-please-version
427
539
428
- def get_host_settings (self ):
540
+ def get_host_settings (self ) -> List [ HostSetting ] :
429
541
"""Gets an array of host settings
430
542
431
543
:return: An array of host settings
@@ -451,7 +563,12 @@ def get_host_settings(self):
451
563
}
452
564
]
453
565
454
- def get_host_from_settings (self , index , variables = None , servers = None ):
566
+ def get_host_from_settings (
567
+ self ,
568
+ index : Optional [int ],
569
+ variables : Optional [ServerVariablesT ]= None ,
570
+ servers : Optional [List [HostSetting ]]= None ,
571
+ ) -> str :
455
572
"""Gets host URL based on the index and variables
456
573
:param index: array index of the host settings
457
574
:param variables: hash of variable and the corresponding value
@@ -491,12 +608,12 @@ def get_host_from_settings(self, index, variables=None, servers=None):
491
608
return url
492
609
493
610
@property
494
- def host (self ):
611
+ def host (self ) -> str :
495
612
"""Return generated host."""
496
613
return self .get_host_from_settings (self .server_index , variables = self .server_variables )
497
614
498
615
@host .setter
499
- def host (self , value ) :
616
+ def host (self , value : str ) -> None :
500
617
"""Fix base path."""
501
618
self ._base_path = value
502
619
self .server_index = None
0 commit comments