-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.mustache
234 lines (208 loc) · 7.57 KB
/
api.mustache
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
# coding: utf-8
{{>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
{{#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:
if api_client is None:
api_client = ApiClient.get_default()
self.api_client = api_client
{{#operation}}
@validate_call
{{#asyncio}}async {{/asyncio}}def {{operationId}}{{>partial_api_args}} -> {{{returnType}}}{{^returnType}}None{{/returnType}}:
{{>partial_api}}
response_data = {{#asyncio}}await {{/asyncio}}self.api_client.call_api(
*_param,
_request_timeout=_request_timeout
)
{{#asyncio}}await {{/asyncio}}response_data.read()
return self.api_client.response_deserialize(
response_data=response_data,
response_types_map=_response_types_map,
).data
@validate_call
{{#asyncio}}async {{/asyncio}}def {{operationId}}_with_http_info{{>partial_api_args}} -> ApiResponse[{{{returnType}}}{{^returnType}}None{{/returnType}}]:
{{>partial_api}}
response_data = {{#asyncio}}await {{/asyncio}}self.api_client.call_api(
*_param,
_request_timeout=_request_timeout
)
{{#asyncio}}await {{/asyncio}}response_data.read()
return self.api_client.response_deserialize(
response_data=response_data,
response_types_map=_response_types_map,
)
@validate_call
{{#asyncio}}async {{/asyncio}}def {{operationId}}_without_preload_content{{>partial_api_args}} -> RESTResponseType:
{{>partial_api}}
response_data = {{#asyncio}}await {{/asyncio}}self.api_client.call_api(
*_param,
_request_timeout=_request_timeout
)
return response_data.response
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]] = {}
_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()
else:
_body_params = {{paramName}}
{{/isBinary}}
{{^isBinary}}
_body_params = {{paramName}}
{{/isBinary}}
{{/bodyParam}}
{{#constantParams}}
{{#isQueryParam}}
# Set client side default value of Query Param "{{baseName}}".
_query_params['{{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`
_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}}