29
29
import frozendict
30
30
31
31
from openapi_client import exceptions , rest , schemas , security_schemes
32
- from openapi_client .configurations import schema_configuration , api_configuration
32
+ from openapi_client .configurations import api_configuration , schema_configuration as schema_configuration_
33
33
34
34
35
35
class RequestField (fields .RequestField ):
@@ -81,18 +81,16 @@ class ParameterStyle(enum.Enum):
81
81
DEEP_OBJECT = 'deepObject'
82
82
83
83
84
+ @dataclasses .dataclass
84
85
class PrefixSeparatorIterator :
85
86
# A class to store prefixes and separators for rfc6570 expansions
87
+ prefix : str
88
+ separator : str
89
+ first : bool = True
90
+ item_separator : str = dataclasses .field (init = False )
86
91
87
- def __init__ (self , prefix : str , separator : str ):
88
- self .prefix = prefix
89
- self .separator = separator
90
- self .first = True
91
- if separator in {'.' , '|' , '%20' }:
92
- item_separator = separator
93
- else :
94
- item_separator = ','
95
- self .item_separator = item_separator
92
+ def __post_init__ (self ):
93
+ self .item_separator = self .separator if self .separator in {'.' , '|' , '%20' } else ','
96
94
97
95
def __iter__ (self ):
98
96
return self
@@ -335,20 +333,13 @@ def _content_type_is_json(cls, content_type: str) -> bool:
335
333
return False
336
334
337
335
336
+ @dataclasses .dataclass
338
337
class Encoding :
339
- def __init__ (
340
- self ,
341
- content_type : str ,
342
- headers : typing .Optional [typing .Dict [str , 'HeaderParameter' ]] = None ,
343
- style : typing .Optional [ParameterStyle ] = None ,
344
- explode : bool = False ,
345
- allow_reserved : bool = False ,
346
- ):
347
- self .content_type = content_type
348
- self .headers = headers
349
- self .style = style
350
- self .explode = explode
351
- self .allow_reserved = allow_reserved
338
+ content_type : str
339
+ headers : typing .Optional [typing .Dict [str , 'HeaderParameter' ]] = None
340
+ style : typing .Optional [ParameterStyle ] = None
341
+ explode : bool = False
342
+ allow_reserved : bool = False
352
343
353
344
354
345
@dataclasses .dataclass
@@ -734,19 +725,6 @@ class ApiResponse:
734
725
body : typing .Union [schemas .Unset , schemas .Schema ] = schemas .unset
735
726
headers : typing .Union [schemas .Unset , typing .Dict [str , schemas .Schema ]] = schemas .unset
736
727
737
- def __init__ (
738
- self ,
739
- response : urllib3 .HTTPResponse ,
740
- body : typing .Union [schemas .Unset , schemas .Schema ] = schemas .unset ,
741
- headers : typing .Union [schemas .Unset , typing .Dict [str , schemas .Schema ]] = schemas .unset
742
- ):
743
- """
744
- pycharm needs this to prevent 'Unexpected argument' warnings
745
- """
746
- self .response = response
747
- self .body = body
748
- self .headers = headers
749
-
750
728
751
729
@dataclasses .dataclass
752
730
class ApiResponseWithoutDeserialization (ApiResponse ):
@@ -887,7 +865,7 @@ def __deserialize_multipart_form_data(
887
865
}
888
866
889
867
@classmethod
890
- def deserialize (cls , response : urllib3 .HTTPResponse , configuration : schema_configuration .SchemaConfiguration ) -> T :
868
+ def deserialize (cls , response : urllib3 .HTTPResponse , configuration : schema_configuration_ .SchemaConfiguration ) -> T :
891
869
content_type = response .headers .get ('content-type' )
892
870
deserialized_body = schemas .unset
893
871
streamed = response .supports_chunked_reads ()
@@ -939,6 +917,7 @@ def deserialize(cls, response: urllib3.HTTPResponse, configuration: schema_confi
939
917
)
940
918
941
919
920
+ @dataclasses .dataclass
942
921
class ApiClient :
943
922
"""Generic API client for OpenAPI client library builds.
944
923
@@ -952,37 +931,25 @@ class ApiClient:
952
931
Do not edit the class manually.
953
932
954
933
:param configuration: api_configuration.ApiConfiguration object for this client
955
- :param schema_configuration: schema_configuration.SchemaConfiguration object for this client
956
- :param header_name: a header to pass when making calls to the API.
957
- :param header_value: a header value to pass when making calls to
958
- the API.
959
- :param cookie: a cookie to include in the header when making calls
960
- to the API
934
+ :param schema_configuration: schema_configuration_.SchemaConfiguration object for this client
935
+ :param default_headers: any default headers to include when making calls to the API.
961
936
:param pool_threads: The number of threads to use for async requests
962
937
to the API. More threads means more concurrent API requests.
963
938
"""
964
-
965
- _pool = None
966
-
967
- def __init__ (
968
- self ,
969
- configuration : typing .Optional [api_configuration .ApiConfiguration ] = None ,
970
- schema_config : typing .Optional [schema_configuration .SchemaConfiguration ] = None ,
971
- header_name : typing .Optional [str ] = None ,
972
- header_value : typing .Optional [str ] = None ,
973
- cookie : typing .Optional [str ] = None ,
974
- pool_threads : int = 1
975
- ):
976
- self .configuration : api_configuration .ApiConfiguration = configuration or api_configuration .ApiConfiguration ()
977
- self .schema_configuration : schema_configuration .SchemaConfiguration = schema_config or schema_configuration .SchemaConfiguration ()
978
- self .pool_threads = pool_threads
979
- self .rest_client = rest .RESTClientObject (self .configuration )
980
- self .default_headers = _collections .HTTPHeaderDict ()
981
- if header_name is not None :
982
- self .default_headers [header_name ] = header_value
983
- self .cookie = cookie
984
- # Set default User-Agent.
939
+ configuration : api_configuration .ApiConfiguration = dataclasses .field (
940
+ default_factory = lambda : api_configuration .ApiConfiguration ())
941
+ schema_configuration : schema_configuration_ .SchemaConfiguration = dataclasses .field (
942
+ default_factory = lambda : schema_configuration_ .SchemaConfiguration ())
943
+ default_headers : _collections .HTTPHeaderDict = dataclasses .field (
944
+ default_factory = lambda : _collections .HTTPHeaderDict ())
945
+ pool_threads : int = 1
946
+ user_agent : str = dataclasses .field (init = False )
947
+ rest_client : rest .RESTClientObject = dataclasses .field (init = False )
948
+
949
+ def __post_init__ (self ):
950
+ self ._pool = None
985
951
self .user_agent = 'OpenAPI-JSON-Schema-Generator/1.0.0/python'
952
+ self .rest_client = rest .RESTClientObject (self .configuration )
986
953
987
954
def __enter__ (self ):
988
955
return self
@@ -1020,23 +987,46 @@ def user_agent(self, value):
1020
987
def set_default_header (self , header_name , header_value ):
1021
988
self .default_headers [header_name ] = header_value
1022
989
1023
- def __call_api (
990
+ def call_api (
1024
991
self ,
1025
992
resource_path : str ,
1026
993
method : str ,
1027
994
host : str ,
1028
995
headers : typing .Optional [_collections .HTTPHeaderDict ] = None ,
1029
- body : typing .Optional [ typing . Union [str , bytes ] ] = None ,
996
+ body : typing .Union [str , bytes , None ] = None ,
1030
997
fields : typing .Optional [typing .Tuple [typing .Tuple [str , str ], ...]] = None ,
1031
998
security_requirement_object : typing .Optional [security_schemes .SecurityRequirementObject ] = None ,
1032
999
stream : bool = False ,
1033
- timeout : typing .Optional [ typing . Union [int , typing .Tuple ] ] = None ,
1000
+ timeout : typing .Union [int , typing .Tuple , None ] = None ,
1034
1001
) -> urllib3 .HTTPResponse :
1002
+ """Makes the HTTP request (synchronous) and returns deserialized data.
1035
1003
1004
+ :param resource_path: Path to method endpoint.
1005
+ :param method: Method to call.
1006
+ :param headers: Header parameters to be
1007
+ placed in the request header.
1008
+ :param body: Request body.
1009
+ :param fields: Request post form parameters,
1010
+ for `application/x-www-form-urlencoded`, `multipart/form-data`
1011
+ :param security_requirement_object: The security requirement object, used to apply auth when making the call
1012
+ :param async_req: execute request asynchronously
1013
+ :param stream: if True, the urllib3.HTTPResponse object will
1014
+ be returned without reading/decoding response
1015
+ data. Also when True, if the openapi spec describes a file download,
1016
+ the data will be written to a local filesystem file and the schemas.BinarySchema
1017
+ instance will also inherit from FileSchema and schemas.FileIO
1018
+ Default is False.
1019
+ :type stream: bool, optional
1020
+ :param timeout: timeout setting for this request. If one
1021
+ number provided, it will be total request
1022
+ timeout. It can also be a pair (tuple) of
1023
+ (connection, read) timeouts.
1024
+ :param host: api endpoint host
1025
+ :return:
1026
+ the method will return the response directly.
1027
+ """
1036
1028
# header parameters
1037
1029
used_headers = _collections .HTTPHeaderDict (self .default_headers )
1038
- if self .cookie :
1039
- headers ['Cookie' ] = self .cookie
1040
1030
1041
1031
# auth setting
1042
1032
self .update_params_for_auth (
@@ -1047,7 +1037,7 @@ def __call_api(
1047
1037
body
1048
1038
)
1049
1039
1050
- # must happen after cookie setting and auth setting in case user is overriding those
1040
+ # must happen after auth setting in case user is overriding those
1051
1041
if headers :
1052
1042
used_headers .update (headers )
1053
1043
@@ -1066,91 +1056,15 @@ def __call_api(
1066
1056
)
1067
1057
return response
1068
1058
1069
- def call_api (
1070
- self ,
1071
- resource_path : str ,
1072
- method : str ,
1073
- host : str ,
1074
- headers : typing .Optional [_collections .HTTPHeaderDict ] = None ,
1075
- body : typing .Optional [typing .Union [str , bytes ]] = None ,
1076
- fields : typing .Optional [typing .Tuple [typing .Tuple [str , str ], ...]] = None ,
1077
- security_requirement_object : typing .Optional [security_schemes .SecurityRequirementObject ] = None ,
1078
- async_req : typing .Optional [bool ] = None ,
1079
- stream : bool = False ,
1080
- timeout : typing .Optional [typing .Union [int , typing .Tuple ]] = None ,
1081
- ) -> urllib3 .HTTPResponse :
1082
- """Makes the HTTP request (synchronous) and returns deserialized data.
1083
-
1084
- To make an async_req request, set the async_req parameter.
1085
-
1086
- :param resource_path: Path to method endpoint.
1087
- :param method: Method to call.
1088
- :param headers: Header parameters to be
1089
- placed in the request header.
1090
- :param body: Request body.
1091
- :param fields: Request post form parameters,
1092
- for `application/x-www-form-urlencoded`, `multipart/form-data`
1093
- :param security_requirement_object: The security requirement object, used to apply auth when making the call
1094
- :param async_req: execute request asynchronously
1095
- :type async_req: bool, optional TODO remove, unused
1096
- :param stream: if True, the urllib3.HTTPResponse object will
1097
- be returned without reading/decoding response
1098
- data. Also when True, if the openapi spec describes a file download,
1099
- the data will be written to a local filesystem file and the schemas.BinarySchema
1100
- instance will also inherit from FileSchema and schemas.FileIO
1101
- Default is False.
1102
- :type stream: bool, optional
1103
- :param timeout: timeout setting for this request. If one
1104
- number provided, it will be total request
1105
- timeout. It can also be a pair (tuple) of
1106
- (connection, read) timeouts.
1107
- :param host: api endpoint host
1108
- :return:
1109
- If async_req parameter is True,
1110
- the request will be called asynchronously.
1111
- The method will return the request thread.
1112
- If parameter async_req is False or missing,
1113
- then the method will return the response directly.
1114
- """
1115
-
1116
- if not async_req :
1117
- return self .__call_api (
1118
- resource_path ,
1119
- method ,
1120
- host ,
1121
- headers ,
1122
- body ,
1123
- fields ,
1124
- security_requirement_object ,
1125
- stream ,
1126
- timeout ,
1127
- )
1128
-
1129
- return self .pool .apply_async (
1130
- self .__call_api ,
1131
- (
1132
- resource_path ,
1133
- method ,
1134
- host ,
1135
- headers ,
1136
- body ,
1137
- json ,
1138
- fields ,
1139
- security_requirement_object ,
1140
- stream ,
1141
- timeout ,
1142
- )
1143
- )
1144
-
1145
1059
def request (
1146
1060
self ,
1147
1061
method : str ,
1148
1062
url : str ,
1149
1063
headers : typing .Optional [_collections .HTTPHeaderDict ] = None ,
1150
1064
fields : typing .Optional [typing .Tuple [typing .Tuple [str , str ], ...]] = None ,
1151
- body : typing .Optional [ typing . Union [str , bytes ] ] = None ,
1065
+ body : typing .Union [str , bytes , None ] = None ,
1152
1066
stream : bool = False ,
1153
- timeout : typing .Optional [ typing . Union [int , typing .Tuple ] ] = None ,
1067
+ timeout : typing .Union [int , typing .Tuple , None ] = None ,
1154
1068
) -> urllib3 .HTTPResponse :
1155
1069
"""Makes the HTTP request using RESTClient."""
1156
1070
if method == "get" :
@@ -1209,7 +1123,7 @@ def update_params_for_auth(
1209
1123
security_requirement_object : typing .Optional [security_schemes .SecurityRequirementObject ],
1210
1124
resource_path : str ,
1211
1125
method : str ,
1212
- body : typing .Optional [ typing . Union [str , bytes ] ] = None
1126
+ body : typing .Union [str , bytes , None ] = None
1213
1127
):
1214
1128
"""Updates header and query params based on authentication setting.
1215
1129
@@ -1233,16 +1147,14 @@ def update_params_for_auth(
1233
1147
scope_names
1234
1148
)
1235
1149
1236
-
1150
+ @ dataclasses . dataclass
1237
1151
class Api (TypedDictInputVerifier ):
1238
1152
"""NOTE: This class is auto generated by OpenAPI JSON Schema Generator
1239
1153
Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator
1240
1154
1241
1155
Do not edit the class manually.
1242
1156
"""
1243
-
1244
- def __init__ (self , api_client : typing .Optional [ApiClient ] = None ):
1245
- self .api_client : ApiClient = api_client or ApiClient ()
1157
+ api_client : ApiClient = dataclasses .field (default_factory = lambda : ApiClient ())
1246
1158
1247
1159
1248
1160
class SerializedRequestBody (typing_extensions .TypedDict , total = False ):
0 commit comments