@@ -114,130 +114,63 @@ class ApiClient(object):
114114 { {/tornado} }
115115 { {#asyncio} }async { {/asyncio} }def _call_api(
116116 self,
117- resource_path: str,
118117 method: str,
119- path_params: typing.Optional[typing.Dict[ str, typing.Any]] = None ,
118+ url: str,
120119 query_params: typing.Optional[typing.List[typing.Tuple[str, typing.Any]]] = None,
121120 header_params: typing.Optional[typing.Dict[str, typing.Any]] = None,
122121 body: typing.Optional[typing.Any] = None,
123122 post_params: typing.Optional[typing.List[typing.Tuple[str, typing.Any]]] = None,
124- files: typing.Optional[typing.Dict[str, typing.List[io.IOBase]]] = None,
125123 response_type: typing.Optional[typing.Tuple[typing.Any]] = None,
126- auth_settings: typing.Optional[typing.List[str]] = None,
127124 _return_http_data_only: typing.Optional[bool] = None,
128- collection_formats: typing.Optional[typing.Dict[str, str]] = None,
129125 _preload_content: bool = True,
130126 _request_timeout: typing.Optional[typing.Union[int, float, typing.Tuple]] = None,
131- _host: typing.Optional[str] = None,
132127 _check_type: typing.Optional[bool] = None
133128 ):
134-
135- config = self.configuration
136-
137- # header parameters
138- header_params = header_params or { }
139- header_params.update(self.default_headers)
140- if self.cookie:
141- header_params['Cookie'] = self.cookie
142- if header_params:
143- header_params = self.sanitize_for_serialization(header_params)
144- header_params = dict(self.parameters_to_tuples(header_params,
145- collection_formats))
146-
147- # path parameters
148- if path_params:
149- path_params = self.sanitize_for_serialization(path_params)
150- path_params = self.parameters_to_tuples(path_params,
151- collection_formats)
152- for k, v in path_params:
153- # specified safe chars, encode everything
154- resource_path = resource_path.replace(
155- '{% s} ' % k,
156- quote(str(v), safe=config.safe_chars_for_path_param)
157- )
158-
159- # query parameters
160- if query_params:
161- query_params = self.sanitize_for_serialization(query_params)
162- query_params = self.parameters_to_tuples(query_params,
163- collection_formats)
164-
165- # post parameters
166- if post_params or files:
167- post_params = post_params if post_params else []
168- post_params = self.sanitize_for_serialization(post_params)
169- post_params = self.parameters_to_tuples(post_params,
170- collection_formats)
171- post_params.extend(self.files_parameters(files))
172- if header_params['Content-Type'].startswith("multipart"):
173- post_params = self.parameters_to_multipart(post_params, (dict,))
174-
175- # body
176- if body:
177- body = self.sanitize_for_serialization(body)
178-
179- # auth setting
180- self.update_params_for_auth(header_params, query_params,
181- auth_settings, resource_path, method, body)
182-
183- # request url
184- if _host is None:
185- url = self.configuration.host + resource_path
186- else:
187- # use server/host defined in path or operation instead
188- url = _host + resource_path
189-
190129 # perform request and return response
191- response_data = { {#asyncio} }await { {/asyncio} }{ {#tornado} }yield { {/tornado} }self.rest_client.request(
130+ response = { {#asyncio} }await { {/asyncio} }{ {#tornado} }yield { {/tornado} }self.rest_client.request(
192131 method, url, query_params=query_params, headers=header_params,
193132 post_params=post_params, body=body,
194133 _preload_content=_preload_content,
195134 _request_timeout=_request_timeout)
196135
197- self.last_response = response_data
198-
199- return_data = response_data
200-
201136 if not _preload_content:
202137 { {^tornado} }
203- return return_data
138+ return response
204139 { {/tornado} }
205140 { {#tornado} }
206- raise tornado.gen.Return(return_data )
141+ raise tornado.gen.Return(response )
207142 { {/tornado} }
208143
209144 # deserialize response data
210145 if response_type:
211- if response_type != (file_type,):
146+ if response_type == (file_type,):
147+ content_disposition = response.getheader("Content-Disposition")
148+ return_data = deserialize_file(response.data, self.configuration, content_disposition=content_disposition)
149+ else:
212150 encoding = "utf-8"
213- content_type = response_data .getheader(' content-type' )
151+ content_type = response .getheader(" content-type" )
214152 if content_type is not None:
215153 match = re.search(r"charset=([a-zA-Z\-\d]+)[\s\;]?", content_type)
216154 if match:
217155 encoding = match.group(1)
218- response_data.data = response_data .data.decode(encoding)
156+ response_data = response .data.decode(encoding)
219157
220- return_data = self.deserialize(
221- response_data,
222- response_type,
223- _check_type
224- )
158+ return_data = self.deserialize(response_data, response_type, _check_type)
225159 else:
226160 return_data = None
227161
228162{ {^tornado} }
229163 if _return_http_data_only:
230- return ( return_data)
164+ return return_data
231165 else:
232- return (return_data, response_data.status,
233- response_data.getheaders())
166+ return (return_data, response.status, response.getheaders())
234167{ {/tornado} }
235168{ {#tornado} }
236169 if _return_http_data_only:
237170 raise tornado.gen.Return(return_data)
238171 else:
239- raise tornado.gen.Return((return_data, response_data .status,
240- response_data .getheaders()))
172+ raise tornado.gen.Return((return_data, response .status,
173+ response .getheaders()))
241174{ {/tornado} }
242175
243176 def parameters_to_multipart(self, params, collection_types):
@@ -250,7 +183,7 @@ class ApiClient(object):
250183 new_params = []
251184 if collection_types is None:
252185 collection_types = (dict)
253- for k, v in params.items() if isinstance(params, dict) else params: # noqa: E501
186+ for k, v in params.items() if isinstance(params, dict) else params:
254187 if isinstance(v, collection_types): # v is instance of collection_type, formatting as application/json
255188 v = json.dumps(v, ensure_ascii=False).encode("utf-8")
256189 field = RequestField(k, v)
@@ -292,10 +225,10 @@ class ApiClient(object):
292225 return { key: cls.sanitize_for_serialization(val) for key, val in obj.items()}
293226 raise ApiValueError('Unable to prepare type { } for serialization'.format(obj.__class__.__name__))
294227
295- def deserialize(self, response , response_type, _check_type):
228+ def deserialize(self, response_data , response_type, _check_type):
296229 """Deserializes response into an object.
297230
298- :param response: RESTResponse object to be deserialized.
231+ :param response_data: Response data to be deserialized.
299232 :param response_type: For the response, a tuple containing:
300233 valid classes
301234 a list containing valid classes (for list schemas)
@@ -312,18 +245,11 @@ class ApiClient(object):
312245
313246 :return: deserialized object.
314247 """
315- # handle file downloading
316- # save response body into a tmp file and return the instance
317- if response_type == (file_type,):
318- content_disposition = response.getheader("Content-Disposition")
319- return deserialize_file(response.data, self.configuration,
320- content_disposition=content_disposition)
321-
322248 # fetch data from response object
323249 try:
324- received_data = json.loads(response.data )
250+ received_data = json.loads(response_data )
325251 except ValueError:
326- received_data = response.data
252+ received_data = response_data
327253
328254 # store our data under the key of 'received_data' so users have some
329255 # context if they are deserializing a string and the data type is wrong
@@ -410,27 +336,70 @@ class ApiClient(object):
410336 If parameter async_req is False or missing,
411337 then the method will return the response directly.
412338 """
339+ # header parameters
340+ header_params = header_params or { }
341+ header_params.update(self.default_headers)
342+ if self.cookie:
343+ header_params["Cookie"] = self.cookie
344+ if header_params:
345+ header_params = self.sanitize_for_serialization(header_params)
346+ header_params = dict(self.parameters_to_tuples(header_params, collection_formats))
347+
348+ # path parameters
349+ if path_params:
350+ path_params = self.sanitize_for_serialization(path_params)
351+ path_params = self.parameters_to_tuples(path_params, collection_formats)
352+ for k, v in path_params:
353+ # specified safe chars, encode everything
354+ resource_path = resource_path.replace("{% s} " % k, quote(str(v), safe=self.configuration.safe_chars_for_path_param))
355+
356+ # query parameters
357+ if query_params:
358+ query_params = self.sanitize_for_serialization(query_params)
359+ query_params = self.parameters_to_tuples(query_params, collection_formats)
360+
361+ # post parameters
362+ if post_params or files:
363+ post_params = post_params if post_params else []
364+ post_params = self.sanitize_for_serialization(post_params)
365+ post_params = self.parameters_to_tuples(post_params, collection_formats)
366+ post_params.extend(self.files_parameters(files))
367+ if header_params["Content-Type"].startswith("multipart"):
368+ post_params = self.parameters_to_multipart(post_params, (dict))
369+
370+ # body
371+ if body:
372+ body = self.sanitize_for_serialization(body)
373+
374+ # auth setting
375+ self.update_params_for_auth(header_params, query_params, auth_settings, resource_path, method, body)
376+
377+ # request url
378+ if _host is None:
379+ url = self.configuration.host + resource_path
380+ else:
381+ # use server/host defined in path or operation instead
382+ url = _host + resource_path
383+
413384 if not async_req:
414- return self._call_api(resource_path, method,
415- path_params, query_params, header_params,
416- body, post_params, files,
417- response_type, auth_settings,
418- _return_http_data_only, collection_formats,
419- _preload_content, _request_timeout, _host,
420- _check_type)
421-
422- return self.pool.apply_async(self._call_api, (resource_path,
423- method, path_params,
424- query_params,
425- header_params, body,
426- post_params, files,
427- response_type,
428- auth_settings,
429- _return_http_data_only,
430- collection_formats,
431- _preload_content,
432- _request_timeout,
433- _host, _check_type))
385+ return self._call_api(method, url,
386+ query_params, header_params,
387+ body, post_params,
388+ response_type,
389+ _return_http_data_only,
390+ _preload_content, _request_timeout,
391+ _check_type)
392+
393+ return self.pool.apply_async(self._call_api, (method, url,
394+ query_params,
395+ header_params,
396+ body,
397+ post_params,
398+ response_type,
399+ _return_http_data_only,
400+ _preload_content,
401+ _request_timeout,
402+ _check_type))
434403
435404 def parameters_to_tuples(self, params, collection_formats):
436405 """Get parameters as list of tuples, formatting collections.
@@ -442,7 +411,7 @@ class ApiClient(object):
442411 new_params = []
443412 if collection_formats is None:
444413 collection_formats = { }
445- for k, v in params.items() if isinstance(params, dict) else params: # noqa: E501
414+ for k, v in params.items() if isinstance(params, dict) else params:
446415 if k in collection_formats:
447416 collection_format = collection_formats[k]
448417 if collection_format == 'multi':
@@ -597,7 +566,7 @@ class Endpoint(object):
597566 'allowed_values' (dict): the allowed values (enum) dictionaries
598567 'openapi_types' (dict): param_name to openapi type
599568 'attribute' (str): camelCase name
600- 'location' (str): 'body', 'file', 'form', 'header', 'path', 'query'
569+ 'location' (str): 'body', 'file', 'form', 'header', 'path', 'query'
601570 'collection_format' (str): `csv` etc.
602571 headers_map (dict): see below key value pairs
603572 'accept' (list): list of Accept header strings
0 commit comments