-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Expand file tree
/
Copy pathapi.mustache
More file actions
364 lines (317 loc) · 12 KB
/
Copy pathapi.mustache
File metadata and controls
364 lines (317 loc) · 12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
{{>partial_header}}
import warnings
from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt
from typing import Any, Dict, List, Optional, Tuple, Union
from typing_extensions import Annotated
{{#imports}}
{{import}}
{{/imports}}
from {{packageName}}.api_client import ApiClient, RequestSerialized
from {{packageName}}.api_response import ApiResponse
from {{packageName}}.rest import RESTResponseType
{{#supportHttpxSync}}
from {{packageName}}.sync_helper import run_sync
{{/supportHttpxSync}}
{{#operations}}
class {{classname}}:
"""NOTE: This class is auto generated by OpenAPI Generator
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""
def __init__(self, api_client=None) -> None:
{{#useIndependentImplicitClients}}
# api_client remains publicly assignable. Retain the client acquired at
# construction so reassignment cannot transfer or discard ownership.
if api_client is None:
api_client, owns_api_client = ApiClient._get_default_or_new()
else:
owns_api_client = False
{{/useIndependentImplicitClients}}
{{^useIndependentImplicitClients}}
if api_client is None:
api_client = ApiClient.get_default()
{{/useIndependentImplicitClients}}
self.api_client = api_client
{{#useIndependentImplicitClients}}
self._owned_api_client: Optional[ApiClient] = (
api_client if owns_api_client else None
)
{{#async}}
async def close(self) -> None:
owned_api_client = self._owned_api_client
self._owned_api_client = None
if owned_api_client is not None:
await owned_api_client.close()
async def __aenter__(self):
return self
async def __aexit__(self, exc_type, exc_value, traceback):
await self.close()
{{#supportHttpxSync}}
def close_sync(self) -> None:
run_sync(self.close())
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, traceback):
self.close_sync()
{{/supportHttpxSync}}
{{/async}}
{{^async}}
def close(self) -> None:
owned_api_client = self._owned_api_client
self._owned_api_client = None
if owned_api_client is not None:
owned_api_client.close()
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, traceback):
self.close()
{{/async}}
{{/useIndependentImplicitClients}}
{{#operation}}
@validate_call
{{#async}}async {{/async}}def {{operationId}}{{>partial_api_args}} -> {{{returnType}}}{{^returnType}}None{{/returnType}}:
{{>partial_api}}
response_data = {{#async}}await {{/async}}self.api_client.call_api(
*_param,
_request_timeout=_request_timeout
)
{{#async}}await {{/async}}response_data.read()
return self.api_client.response_deserialize(
response_data=response_data,
response_types_map=_response_types_map,
).data
@validate_call
{{#async}}async {{/async}}def {{operationId}}_with_http_info{{>partial_api_args}} -> ApiResponse[{{{returnType}}}{{^returnType}}None{{/returnType}}]:
{{>partial_api}}
response_data = {{#async}}await {{/async}}self.api_client.call_api(
*_param,
_request_timeout=_request_timeout
)
{{#async}}await {{/async}}response_data.read()
return self.api_client.response_deserialize(
response_data=response_data,
response_types_map=_response_types_map,
)
@validate_call
{{#async}}async {{/async}}def {{operationId}}_without_preload_content{{>partial_api_args}} -> RESTResponseType:
{{>partial_api}}
response_data = {{#async}}await {{/async}}self.api_client.call_api(
*_param,
_request_timeout=_request_timeout
)
return response_data.response
{{#supportHttpxSync}}
@validate_call
def {{operationId}}_sync{{>partial_api_args}} -> {{{returnType}}}{{^returnType}}None{{/returnType}}:
"""{{#isDeprecated}}(Deprecated) {{/isDeprecated}}{{{summary}}}{{^summary}}{{operationId}}{{/summary}} (synchronous)
Synchronous variant of :meth:`{{operationId}}`. It calls the asynchronous
method and blocks until it completes.
""" # noqa: E501
return run_sync(
self.{{operationId}}(
{{#allParams}}
{{paramName}}={{paramName}},
{{/allParams}}
_request_timeout=_request_timeout,
_request_auth=_request_auth,
_content_type=_content_type,
_headers=_headers,
_host_index=_host_index,
)
)
@validate_call
def {{operationId}}_sync_with_http_info{{>partial_api_args}} -> ApiResponse[{{{returnType}}}{{^returnType}}None{{/returnType}}]:
"""{{#isDeprecated}}(Deprecated) {{/isDeprecated}}{{{summary}}}{{^summary}}{{operationId}}{{/summary}} (synchronous)
Synchronous variant of :meth:`{{operationId}}_with_http_info`. It calls the
asynchronous method and blocks until it completes.
""" # noqa: E501
return run_sync(
self.{{operationId}}_with_http_info(
{{#allParams}}
{{paramName}}={{paramName}},
{{/allParams}}
_request_timeout=_request_timeout,
_request_auth=_request_auth,
_content_type=_content_type,
_headers=_headers,
_host_index=_host_index,
)
)
@validate_call
def {{operationId}}_sync_without_preload_content{{>partial_api_args}} -> RESTResponseType:
"""{{#isDeprecated}}(Deprecated) {{/isDeprecated}}{{{summary}}}{{^summary}}{{operationId}}{{/summary}} (synchronous)
Synchronous variant of :meth:`{{operationId}}_without_preload_content`. It calls
the asynchronous method and blocks until it completes.
""" # noqa: E501
return run_sync(
self.{{operationId}}_without_preload_content(
{{#allParams}}
{{paramName}}={{paramName}},
{{/allParams}}
_request_timeout=_request_timeout,
_request_auth=_request_auth,
_content_type=_content_type,
_headers=_headers,
_host_index=_host_index,
)
)
{{/supportHttpxSync}}
def _{{operationId}}_serialize(
self,
{{#allParams}}
{{paramName}},
{{/allParams}}
_request_auth,
_content_type,
_headers,
_host_index,
) -> RequestSerialized:
{{#servers.0}}
_hosts = [{{#servers}}
'{{{url}}}'{{^-last}},{{/-last}}{{/servers}}
]
_host = _hosts[_host_index]
{{/servers.0}}
{{^servers.0}}
_host = None
{{/servers.0}}
_collection_formats: Dict[str, str] = {
{{#allParams}}
{{#isArray}}
'{{baseName}}': '{{collectionFormat}}',
{{/isArray}}
{{/allParams}}
}
_path_params: Dict[str, str] = {}
_query_params: List[Tuple[str, str]] = []
_header_params: Dict[str, Optional[str]] = _headers or {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[
str, Union[str, bytes, List[str], List[bytes], List[Tuple[str, bytes]]]
] = {}
_body_params: Optional[bytes] = None
# process the path parameters
{{#pathParams}}
if {{paramName}} is not None:
_path_params['{{baseName}}'] = {{paramName}}{{#isEnumRef}}.value{{/isEnumRef}}
{{/pathParams}}
# process the query parameters
{{#queryParams}}
if {{paramName}} is not None:
{{#isDateTime}}
if isinstance({{paramName}}, datetime):
_query_params.append(
(
'{{baseName}}',
{{paramName}}.strftime(
self.api_client.configuration.datetime_format
)
)
)
else:
_query_params.append(('{{baseName}}', {{paramName}}))
{{/isDateTime}}
{{#isDate}}
if isinstance({{paramName}}, date):
_query_params.append(
(
'{{baseName}}',
{{paramName}}.strftime(
self.api_client.configuration.date_format
)
)
)
else:
_query_params.append(('{{baseName}}', {{paramName}}))
{{/isDate}}
{{^isDateTime}}{{^isDate}}
_query_params.append(('{{baseName}}', {{paramName}}{{#isEnumRef}}.value{{/isEnumRef}}))
{{/isDate}}{{/isDateTime}}
{{/queryParams}}
# process the header parameters
{{#headerParams}}
if {{paramName}} is not None:
_header_params['{{baseName}}'] = {{paramName}}
{{/headerParams}}
# process the form parameters
{{#formParams}}
if {{paramName}} is not None:
{{#isFile}}
_files['{{{baseName}}}'] = {{paramName}}
{{/isFile}}
{{^isFile}}
_form_params.append(('{{{baseName}}}', {{paramName}}))
{{/isFile}}
{{/formParams}}
# process the body parameter
{{#bodyParam}}
if {{paramName}} is not None:
{{#isBinary}}
# convert to byte array if the input is a file name (str)
if isinstance({{paramName}}, str):
with open({{paramName}}, "rb") as _fp:
_body_params = _fp.read()
elif isinstance({{paramName}}, tuple):
# drop the filename from the tuple
_body_params = {{paramName}}[1]
else:
_body_params = {{paramName}}
{{/isBinary}}
{{^isBinary}}
_body_params = {{paramName}}
{{/isBinary}}
{{/bodyParam}}
{{#constantParams}}
{{#isQueryParam}}
# Set client side default value of Query Param "{{baseName}}".
_query_params.append(('{{baseName}}', {{#_enum}}'{{{.}}}'{{/_enum}}))
{{/isQueryParam}}
{{#isHeaderParam}}
# Set client side default value of Header Param "{{baseName}}".
_header_params['{{baseName}}'] = {{#_enum}}'{{{.}}}'{{/_enum}}
{{/isHeaderParam}}
{{/constantParams}}
{{#hasProduces}}
# set the HTTP header `Accept`
if 'Accept' not in _header_params:
_header_params['Accept'] = self.api_client.select_header_accept(
[{{#produces}}
'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/produces}}
]
)
{{/hasProduces}}
{{#hasConsumes}}
# set the HTTP header `Content-Type`
if _content_type:
_header_params['Content-Type'] = _content_type
else:
_default_content_type = (
self.api_client.select_header_content_type(
[{{#consumes}}
'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/consumes}}
]
)
)
if _default_content_type is not None:
_header_params['Content-Type'] = _default_content_type
{{/hasConsumes}}
# authentication setting
_auth_settings: List[str] = [{{#authMethods}}
'{{name}}'{{^-last}}, {{/-last}}{{/authMethods}}
]
return self.api_client.param_serialize(
method='{{httpMethod}}',
resource_path='{{{path}}}',
path_params=_path_params,
query_params=_query_params,
header_params=_header_params,
body=_body_params,
post_params=_form_params,
files=_files,
auth_settings=_auth_settings,
collection_formats=_collection_formats,
_host=_host,
_request_auth=_request_auth
)
{{/operation}}
{{/operations}}