-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathasync_api.mustache
More file actions
296 lines (262 loc) · 11.5 KB
/
async_api.mustache
File metadata and controls
296 lines (262 loc) · 11.5 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
# coding: utf-8
{{>partial_header}}
import re # noqa: F401
import io
import warnings
from pydantic.v1 import validate_arguments, ValidationError
from typing_extensions import Annotated
from typing import overload, Optional, Union, Awaitable
{{#imports}}
{{import}}
{{/imports}}
from {{packageName}}.async_api_client import AsyncApiClient
from {{packageName}}.api_response import ApiResponse
from {{packageName}}.exceptions import ( # noqa: F401
ApiTypeError,
ApiValueError
)
{{#operations}}
class Async{{classname}}(object):
"""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):
if api_client is None:
api_client = AsyncApiClient.get_default()
self.api_client = api_client
self.line_base_path = "{{basePath}}"
{{#operation}}
@overload
async def {{operationId}}(self, {{#allParams}}{{paramName}} : {{{vendorExtensions.x-py-typing}}}{{^required}} = None{{/required}}, {{/allParams}}**kwargs) -> {{{returnType}}}{{^returnType}}None{{/returnType}}: # noqa: E501
...
@overload
def {{operationId}}(self, {{#allParams}}{{paramName}} : {{{vendorExtensions.x-py-typing}}}{{^required}} = None{{/required}}, {{/allParams}}async_req: Optional[bool]=True, **kwargs) -> {{{returnType}}}{{^returnType}}None{{/returnType}}: # noqa: E501
...
@validate_arguments
def {{operationId}}(self, {{#allParams}}{{paramName}} : {{{vendorExtensions.x-py-typing}}}{{^required}} = None{{/required}}, {{/allParams}}async_req: Optional[bool]=None, **kwargs) -> Union[{{{returnType}}}{{^returnType}}None{{/returnType}}, Awaitable[{{{returnType}}}{{^returnType}}None{{/returnType}}]]: # noqa: E501
"""{{#isDeprecated}}(Deprecated) {{/isDeprecated}}{{{summary}}}
{{#notes}}
{{{.}}}
{{/notes}}
{{#allParams}}
:param {{paramName}}:{{#description}} {{{.}}}{{/description}}{{#required}} (required){{/required}}{{#optional}}(optional){{/optional}}
:type {{paramName}}: {{dataType}}{{#optional}}, optional{{/optional}}
{{/allParams}}
:param async_req: Whether to execute the request asynchronously.
:type async_req: bool, optional
:param _request_timeout: timeout setting for this request. If one
number provided, it will be total request
timeout. It can also be a pair (tuple) of
(connection, read) timeouts.
:return: Returns the result object.
:rtype: {{returnType}}{{^returnType}}None{{/returnType}}
"""
kwargs['_return_http_data_only'] = True
if '_preload_content' in kwargs:
raise ValueError("Error! Please call the {{operationId}}_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data")
if async_req is not None:
kwargs['async_req'] = async_req
return self.{{operationId}}_with_http_info({{#allParams}}{{paramName}}, {{/allParams}}**kwargs) # noqa: E501
@validate_arguments
def {{operationId}}_with_http_info(self, {{#allParams}}{{paramName}} : {{{vendorExtensions.x-py-typing}}}{{^required}} = None{{/required}}, {{/allParams}}**kwargs) -> ApiResponse: # noqa: E501
"""{{#isDeprecated}}(Deprecated) {{/isDeprecated}}{{{summary}}}
{{#notes}}
{{{.}}}
{{/notes}}
{{#allParams}}
:param {{paramName}}:{{#description}} {{{.}}}{{/description}}{{#required}} (required){{/required}}{{#optional}}(optional){{/optional}}
:type {{paramName}}: {{dataType}}{{#optional}}, optional{{/optional}}
{{/allParams}}
:param async_req: Whether to execute the request asynchronously.
:type async_req: bool, optional
:param _preload_content: if False, the ApiResponse.data will
be set to none and raw_data will store the
HTTP response body without reading/decoding.
Default is True.
:type _preload_content: bool, optional
:param _return_http_data_only: response data instead of ApiResponse
object with status code, headers, etc
:type _return_http_data_only: bool, optional
:param _request_timeout: timeout setting for this request. If one
number provided, it will be total request
timeout. It can also be a pair (tuple) of
(connection, read) timeouts.
:param _request_auth: set to override the auth_settings for an a single
request; this effectively ignores the authentication
in the spec for a single request.
:type _request_auth: dict, optional
:type _content_type: string, optional: force content-type for the request
:return: Returns the result object.
:rtype: {{#returnType}}tuple({{.}}, status_code(int), headers(HTTPHeaderDict)){{/returnType}}{{^returnType}}None{{/returnType}}
"""
{{#isDeprecated}}
warnings.warn("{{{httpMethod}}} {{{path}}} is deprecated.", DeprecationWarning)
{{/isDeprecated}}
{{#servers.0}}
_hosts = [
{{#servers}}
'{{{url}}}'{{^-last}},{{/-last}}
{{/servers}}
]
_host = _hosts[0]
if kwargs.get('_host_index'):
_host_index = int(kwargs.get('_host_index'))
if _host_index < 0 or _host_index >= len(_hosts):
raise ApiValueError(
"Invalid host index. Must be 0 <= index < %s"
% len(_host)
)
_host = _hosts[_host_index]
{{/servers.0}}
{{^servers.0}}
_host = self.line_base_path
{{/servers.0}}
_params = locals()
_all_params = [
{{#allParams}}
'{{paramName}}'{{^-last}},{{/-last}}
{{/allParams}}
]
_all_params.extend(
[
'async_req',
'_return_http_data_only',
'_preload_content',
'_request_timeout',
'_request_auth',
'_content_type',
'_headers'
]
)
# validate the arguments
for _key, _val in _params['kwargs'].items():
if _key not in _all_params{{#servers.0}} and _key != "_host_index"{{/servers.0}}:
raise ApiTypeError(
"Got an unexpected keyword argument '%s'"
" to method {{operationId}}" % _key
)
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
# process the path parameters
_path_params = {}
{{#pathParams}}
if _params['{{paramName}}']:
_path_params['{{baseName}}'] = _params['{{paramName}}']
{{#isArray}}
_collection_formats['{{baseName}}'] = '{{collectionFormat}}'
{{/isArray}}
{{/pathParams}}
# process the query parameters
_query_params = []
{{#queryParams}}
if _params.get('{{paramName}}') is not None: # noqa: E501
{{#isDateTime}}
if isinstance(_params['{{paramName}}'], datetime):
_query_params.append(('{{baseName}}', _params['{{paramName}}'].strftime(self.api_client.configuration.datetime_format)))
else:
_query_params.append(('{{baseName}}', _params['{{paramName}}']))
{{/isDateTime}}
{{^isDateTime}}
{{#isDate}}
if isinstance(_params['{{paramName}}'], datetime):
_query_params.append(('{{baseName}}', _params['{{paramName}}'].strftime(self.api_client.configuration.date_format)))
else:
_query_params.append(('{{baseName}}', _params['{{paramName}}']))
{{/isDate}}
{{^isDate}}
_query_params.append(('{{baseName}}', _params['{{paramName}}']{{#isEnumRef}}.value{{/isEnumRef}}))
{{/isDate}}
{{/isDateTime}}
{{#isArray}}
_collection_formats['{{baseName}}'] = '{{collectionFormat}}'
{{/isArray}}
{{/queryParams}}
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
{{#headerParams}}
if _params['{{paramName}}']:
_header_params['{{baseName}}'] = _params['{{paramName}}']
{{#isArray}}
_collection_formats['{{baseName}}'] = '{{collectionFormat}}'
{{/isArray}}
{{/headerParams}}
# process the form parameters
_form_params = []
_files = {}
{{#formParams}}
if _params['{{paramName}}']:
{{^isFile}}
_form_params.append(('{{{baseName}}}', _params['{{paramName}}']))
{{/isFile}}
{{#isFile}}
_files['{{{baseName}}}'] = _params['{{paramName}}']
{{/isFile}}
{{#isArray}}
_collection_formats['{{{baseName}}}'] = '{{collectionFormat}}'
{{/isArray}}
{{/formParams}}
# process the body parameter
_body_params = None
{{#bodyParam}}
if _params['{{paramName}}'] is not None:
_body_params = _params['{{paramName}}']
{{#isBinary}}
# convert to byte array if the input is a file name (str)
if isinstance(_body_params, str):
with io.open(_body_params, "rb") as _fp:
_body_params_from_file = _fp.read()
_body_params = _body_params_from_file
{{/isBinary}}
{{/bodyParam}}
{{#hasProduces}}
# set the HTTP header `Accept`
_header_params['Accept'] = self.api_client.select_header_accept(
[{{#produces}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/produces}}]) # noqa: E501
{{/hasProduces}}
{{#hasConsumes}}
# set the HTTP header `Content-Type`
_content_types_list = _params.get('_content_type',
self.api_client.select_header_content_type(
[{{#consumes}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/consumes}}]))
if _content_types_list:
_header_params['Content-Type'] = _content_types_list
{{/hasConsumes}}
# authentication setting
_auth_settings = [{{#authMethods}}'{{name}}'{{^-last}}, {{/-last}}{{/authMethods}}] # noqa: E501
{{#returnType}}
{{#responses}}
{{#-first}}
_response_types_map = {
{{/-first}}
{{^isWildcard}}
'{{code}}': {{#dataType}}"{{.}}"{{/dataType}}{{^dataType}}None{{/dataType}},
{{/isWildcard}}
{{#-last}}
}
{{/-last}}
{{/responses}}
{{/returnType}}
{{^returnType}}
_response_types_map = {}
{{/returnType}}
return self.api_client.call_api(
'{{{path}}}', '{{httpMethod}}',
_path_params,
_query_params,
_header_params,
body=_body_params,
post_params=_form_params,
files=_files,
response_types_map=_response_types_map,
auth_settings=_auth_settings,
async_req=_params.get('async_req'),
_return_http_data_only=_params.get('_return_http_data_only'), # noqa: E501
_preload_content=_params.get('_preload_content', True),
_request_timeout=_params.get('_request_timeout'),
_host=_host,
collection_formats=_collection_formats,
_request_auth=_params.get('_request_auth'))
{{/operation}}
{{/operations}}