Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove python unused conversion arguments calls #714

Merged
Merged
  •  
  •  
  •  
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.5.1.dev2",
"regenerated": "2021-12-08 13:12:43.323885",
"spec_repo_commit": "42876d3"
"regenerated": "2021-12-09 16:56:42.148728",
"spec_repo_commit": "47e398e"
},
"v2": {
"apigentools_version": "1.5.1.dev2",
"regenerated": "2021-12-08 13:12:43.813509",
"spec_repo_commit": "42876d3"
"regenerated": "2021-12-09 16:56:42.659605",
"spec_repo_commit": "47e398e"
}
}
}
8 changes: 3 additions & 5 deletions .generator/templates/api.mustache
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
{{>partial_header}}

import re # noqa: F401
import sys # noqa: F401

from {{packageName}}.api_client import ApiClient, Endpoint as _Endpoint
from {{packageName}}.model_utils import ( # noqa: F401
date,
datetime,
file_type,
none_type,
validate_and_convert_types
)
{{#imports}}
{{{import}}}
Expand Down Expand Up @@ -107,7 +105,7 @@ class {{classname}}(object):
{{#exclusiveMaximum}}'exclusive_maximum'{{/exclusiveMaximum}}{{^exclusiveMaximum}}'inclusive_maximum'{{/exclusiveMaximum}}: {{maximum}},{{/maximum}}{{#minimum}}
{{#exclusiveMinimum}}'exclusive_minimum'{{/exclusiveMinimum}}{{^exclusiveMinimum}}'inclusive_minimum'{{/exclusiveMinimum}}: {{minimum}},{{/minimum}}{{#pattern}}
'regex': {
'pattern': r'{{{vendorExtensions.x-regex}}}', # noqa: E501{{#vendorExtensions.x-modifiers}}
'pattern': r'{{{vendorExtensions.x-regex}}}',{{#vendorExtensions.x-modifiers}}
{{#-first}}'flags': (re.{{.}}{{/-first}}{{^-first}} re.{{.}}{{/-first}}{{^-last}} | {{/-last}}{{#-last}}){{/-last}}{{/vendorExtensions.x-modifiers}}
},{{/pattern}}
},
Expand Down Expand Up @@ -164,10 +162,10 @@ class {{classname}}(object):
{{/requiredParams}}
**kwargs
):
"""{{#summary}}{{{.}}}{{/summary}}{{^summary}}{{operationId}}{{/summary}} # noqa: E501
"""{{#summary}}{{{.}}}{{/summary}}{{^summary}}{{operationId}}{{/summary}}

{{#notes}}
{{{notes}}} # noqa: E501
{{{notes}}}
{{/notes}}
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async_req=True
Expand Down
201 changes: 85 additions & 116 deletions .generator/templates/api_client.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -114,130 +114,63 @@ class ApiClient(object):
{{/tornado}}
{{#asyncio}}async {{/asyncio}}def _call_api(
self,
resource_path: str,
method: str,
path_params: typing.Optional[typing.Dict[str, typing.Any]] = None,
url: str,
query_params: typing.Optional[typing.List[typing.Tuple[str, typing.Any]]] = None,
header_params: typing.Optional[typing.Dict[str, typing.Any]] = None,
body: typing.Optional[typing.Any] = None,
post_params: typing.Optional[typing.List[typing.Tuple[str, typing.Any]]] = None,
files: typing.Optional[typing.Dict[str, typing.List[io.IOBase]]] = None,
response_type: typing.Optional[typing.Tuple[typing.Any]] = None,
auth_settings: typing.Optional[typing.List[str]] = None,
_return_http_data_only: typing.Optional[bool] = None,
collection_formats: typing.Optional[typing.Dict[str, str]] = None,
_preload_content: bool = True,
_request_timeout: typing.Optional[typing.Union[int, float, typing.Tuple]] = None,
_host: typing.Optional[str] = None,
_check_type: typing.Optional[bool] = None
):

config = self.configuration

# header parameters
header_params = header_params or {}
header_params.update(self.default_headers)
if self.cookie:
header_params['Cookie'] = self.cookie
if header_params:
header_params = self.sanitize_for_serialization(header_params)
header_params = dict(self.parameters_to_tuples(header_params,
collection_formats))

# path parameters
if path_params:
path_params = self.sanitize_for_serialization(path_params)
path_params = self.parameters_to_tuples(path_params,
collection_formats)
for k, v in path_params:
# specified safe chars, encode everything
resource_path = resource_path.replace(
'{%s}' % k,
quote(str(v), safe=config.safe_chars_for_path_param)
)

# query parameters
if query_params:
query_params = self.sanitize_for_serialization(query_params)
query_params = self.parameters_to_tuples(query_params,
collection_formats)

# post parameters
if post_params or files:
post_params = post_params if post_params else []
post_params = self.sanitize_for_serialization(post_params)
post_params = self.parameters_to_tuples(post_params,
collection_formats)
post_params.extend(self.files_parameters(files))
if header_params['Content-Type'].startswith("multipart"):
post_params = self.parameters_to_multipart(post_params, (dict,))

# body
if body:
body = self.sanitize_for_serialization(body)

# auth setting
self.update_params_for_auth(header_params, query_params,
auth_settings, resource_path, method, body)

# request url
if _host is None:
url = self.configuration.host + resource_path
else:
# use server/host defined in path or operation instead
url = _host + resource_path

# perform request and return response
response_data = {{#asyncio}}await {{/asyncio}}{{#tornado}}yield {{/tornado}}self.rest_client.request(
response = {{#asyncio}}await {{/asyncio}}{{#tornado}}yield {{/tornado}}self.rest_client.request(
method, url, query_params=query_params, headers=header_params,
post_params=post_params, body=body,
_preload_content=_preload_content,
_request_timeout=_request_timeout)

self.last_response = response_data

return_data = response_data

if not _preload_content:
{{^tornado}}
return return_data
return response
{{/tornado}}
{{#tornado}}
raise tornado.gen.Return(return_data)
raise tornado.gen.Return(response)
{{/tornado}}

# deserialize response data
if response_type:
if response_type != (file_type,):
if response_type == (file_type,):
content_disposition = response.getheader("Content-Disposition")
return_data = deserialize_file(response.data, self.configuration, content_disposition=content_disposition)
else:
encoding = "utf-8"
content_type = response_data.getheader('content-type')
content_type = response.getheader("content-type")
if content_type is not None:
match = re.search(r"charset=([a-zA-Z\-\d]+)[\s\;]?", content_type)
if match:
encoding = match.group(1)
response_data.data = response_data.data.decode(encoding)
response_data = response.data.decode(encoding)

return_data = self.deserialize(
response_data,
response_type,
_check_type
)
return_data = self.deserialize(response_data, response_type, _check_type)
else:
return_data = None

{{^tornado}}
if _return_http_data_only:
return (return_data)
return return_data
else:
return (return_data, response_data.status,
response_data.getheaders())
return (return_data, response.status, response.getheaders())
{{/tornado}}
{{#tornado}}
if _return_http_data_only:
raise tornado.gen.Return(return_data)
else:
raise tornado.gen.Return((return_data, response_data.status,
response_data.getheaders()))
raise tornado.gen.Return((return_data, response.status,
response.getheaders()))
{{/tornado}}

def parameters_to_multipart(self, params, collection_types):
Expand All @@ -250,7 +183,7 @@ class ApiClient(object):
new_params = []
if collection_types is None:
collection_types = (dict)
for k, v in params.items() if isinstance(params, dict) else params: # noqa: E501
for k, v in params.items() if isinstance(params, dict) else params:
if isinstance(v, collection_types): # v is instance of collection_type, formatting as application/json
v = json.dumps(v, ensure_ascii=False).encode("utf-8")
field = RequestField(k, v)
Expand Down Expand Up @@ -292,10 +225,10 @@ class ApiClient(object):
return {key: cls.sanitize_for_serialization(val) for key, val in obj.items()}
raise ApiValueError('Unable to prepare type {} for serialization'.format(obj.__class__.__name__))

def deserialize(self, response, response_type, _check_type):
def deserialize(self, response_data, response_type, _check_type):
"""Deserializes response into an object.

:param response: RESTResponse object to be deserialized.
:param response_data: Response data to be deserialized.
:param response_type: For the response, a tuple containing:
valid classes
a list containing valid classes (for list schemas)
Expand All @@ -312,18 +245,11 @@ class ApiClient(object):

:return: deserialized object.
"""
# handle file downloading
# save response body into a tmp file and return the instance
if response_type == (file_type,):
content_disposition = response.getheader("Content-Disposition")
return deserialize_file(response.data, self.configuration,
content_disposition=content_disposition)

# fetch data from response object
try:
received_data = json.loads(response.data)
received_data = json.loads(response_data)
except ValueError:
received_data = response.data
received_data = response_data

# store our data under the key of 'received_data' so users have some
# context if they are deserializing a string and the data type is wrong
Expand Down Expand Up @@ -410,27 +336,70 @@ class ApiClient(object):
If parameter async_req is False or missing,
then the method will return the response directly.
"""
# header parameters
header_params = header_params or {}
header_params.update(self.default_headers)
if self.cookie:
header_params["Cookie"] = self.cookie
if header_params:
header_params = self.sanitize_for_serialization(header_params)
header_params = dict(self.parameters_to_tuples(header_params, collection_formats))

# path parameters
if path_params:
path_params = self.sanitize_for_serialization(path_params)
path_params = self.parameters_to_tuples(path_params, collection_formats)
for k, v in path_params:
# specified safe chars, encode everything
resource_path = resource_path.replace("{%s}" % k, quote(str(v), safe=self.configuration.safe_chars_for_path_param))

# query parameters
if query_params:
query_params = self.sanitize_for_serialization(query_params)
query_params = self.parameters_to_tuples(query_params, collection_formats)

# post parameters
if post_params or files:
post_params = post_params if post_params else []
post_params = self.sanitize_for_serialization(post_params)
post_params = self.parameters_to_tuples(post_params, collection_formats)
post_params.extend(self.files_parameters(files))
if header_params["Content-Type"].startswith("multipart"):
post_params = self.parameters_to_multipart(post_params, (dict))

# body
if body:
body = self.sanitize_for_serialization(body)

# auth setting
self.update_params_for_auth(header_params, query_params, auth_settings, resource_path, method, body)

# request url
if _host is None:
url = self.configuration.host + resource_path
else:
# use server/host defined in path or operation instead
url = _host + resource_path

if not async_req:
return self._call_api(resource_path, method,
path_params, query_params, header_params,
body, post_params, files,
response_type, auth_settings,
_return_http_data_only, collection_formats,
_preload_content, _request_timeout, _host,
_check_type)

return self.pool.apply_async(self._call_api, (resource_path,
method, path_params,
query_params,
header_params, body,
post_params, files,
response_type,
auth_settings,
_return_http_data_only,
collection_formats,
_preload_content,
_request_timeout,
_host, _check_type))
return self._call_api(method, url,
query_params, header_params,
body, post_params,
response_type,
_return_http_data_only,
_preload_content, _request_timeout,
_check_type)

return self.pool.apply_async(self._call_api, (method, url,
query_params,
header_params,
body,
post_params,
response_type,
_return_http_data_only,
_preload_content,
_request_timeout,
_check_type))

def parameters_to_tuples(self, params, collection_formats):
"""Get parameters as list of tuples, formatting collections.
Expand All @@ -442,7 +411,7 @@ class ApiClient(object):
new_params = []
if collection_formats is None:
collection_formats = {}
for k, v in params.items() if isinstance(params, dict) else params: # noqa: E501
for k, v in params.items() if isinstance(params, dict) else params:
if k in collection_formats:
collection_format = collection_formats[k]
if collection_format == 'multi':
Expand Down Expand Up @@ -597,7 +566,7 @@ class Endpoint(object):
'allowed_values' (dict): the allowed values (enum) dictionaries
'openapi_types' (dict): param_name to openapi type
'attribute' (str): camelCase name
'location' (str): 'body', 'file', 'form', 'header', 'path', 'query'
'location' (str): 'body', 'file', 'form', 'header', 'path', 'query'
'collection_format' (str): `csv` etc.
headers_map (dict): see below key value pairs
'accept' (list): list of Accept header strings
Expand Down
1 change: 0 additions & 1 deletion .generator/templates/model.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ from {{packageName}}.model_utils import ( # noqa: F401
ModelNormal,
ModelSimple,
cached_property,
convert_js_args_to_python_args,
date,
datetime,
file_type,
Expand Down
Loading