Merge remote-tracking branch 'origin/5.1.x' into 6.0.x

This commit is contained in:
William Cheng
2021-01-18 12:40:31 +08:00
248 changed files with 4044 additions and 3425 deletions

View File

@@ -103,7 +103,7 @@ Use specific imports for apis and models like:
- `from dynamic_servers.api.default_api import DefaultApi`
- `from dynamic_servers.model.pet import Pet`
Solution 1:
Solution 2:
Before importing the package, adjust the maximum recursion limit as shown below:
```
import sys

View File

@@ -11,7 +11,7 @@
import re # noqa: F401
import sys # noqa: F401
from dynamic_servers.api_client import ApiClient, Endpoint
from dynamic_servers.api_client import ApiClient, Endpoint as _Endpoint
from dynamic_servers.model_utils import ( # noqa: F401
check_allowed_values,
check_validations,
@@ -96,7 +96,7 @@ class UsageApi(object):
kwargs['_host_index'] = kwargs.get('_host_index')
return self.call_with_http_info(**kwargs)
self.custom_server = Endpoint(
self.custom_server = _Endpoint(
settings={
'response_type': ({str: (bool, date, datetime, dict, float, int, list, str, none_type)},),
'auth': [],
@@ -250,7 +250,7 @@ class UsageApi(object):
kwargs['_host_index'] = kwargs.get('_host_index')
return self.call_with_http_info(**kwargs)
self.default_server = Endpoint(
self.default_server = _Endpoint(
settings={
'response_type': ({str: (bool, date, datetime, dict, float, int, list, str, none_type)},),
'auth': [],

View File

@@ -201,8 +201,6 @@ class ApiClient(object):
e.body = e.body.decode('utf-8')
raise e
content_type = response_data.getheader('content-type')
self.last_response = response_data
return_data = response_data
@@ -211,15 +209,17 @@ class ApiClient(object):
return (return_data)
return return_data
if response_type not in ["file", "bytes"]:
match = None
if content_type is not None:
match = re.search(r"charset=([a-zA-Z\-\d]+)[\s\;]?", content_type)
encoding = match.group(1) if match else "utf-8"
response_data.data = response_data.data.decode(encoding)
# deserialize response data
if response_type:
if response_type != (file_type,):
encoding = "utf-8"
content_type = response_data.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)
return_data = self.deserialize(
response_data,
response_type,
@@ -256,7 +256,7 @@ class ApiClient(object):
@classmethod
def sanitize_for_serialization(cls, obj):
"""Builds a JSON POST object.
"""Prepares data for transmission before it is sent with the rest client
If obj is None, return None.
If obj is str, int, long, float, bool, return directly.
If obj is datetime.datetime, datetime.date
@@ -264,6 +264,7 @@ class ApiClient(object):
If obj is list, sanitize each element in the list.
If obj is dict, return the dict.
If obj is OpenAPI model, return the properties dict.
If obj is io.IOBase, return the bytes
:param obj: The data to serialize.
:return: The serialized form of data.
"""
@@ -271,6 +272,8 @@ class ApiClient(object):
return {
key: cls.sanitize_for_serialization(val) for key, val in model_to_dict(obj, serialize=True).items()
}
elif isinstance(obj, io.IOBase):
return cls.get_file_data_and_close_file(obj)
elif isinstance(obj, (str, int, float, none_type, bool)):
return obj
elif isinstance(obj, (datetime, date)):
@@ -514,6 +517,12 @@ class ApiClient(object):
new_params.append((k, v))
return new_params
@staticmethod
def get_file_data_and_close_file(file_instance: io.IOBase) -> bytes:
file_data = file_instance.read()
file_instance.close()
return file_data
def files_parameters(self, files: typing.Optional[typing.Dict[str, typing.List[io.IOBase]]] = None):
"""Builds form parameters.
@@ -539,12 +548,11 @@ class ApiClient(object):
"for %s must be open." % param_name
)
filename = os.path.basename(file_instance.name)
filedata = file_instance.read()
filedata = self.get_file_data_and_close_file(file_instance)
mimetype = (mimetypes.guess_type(filename)[0] or
'application/octet-stream')
params.append(
tuple([param_name, tuple([filename, filedata, mimetype])]))
file_instance.close()
return params

View File

@@ -1493,10 +1493,13 @@ def model_to_dict(model_instance, serialize=True):
# exist in attribute_map
attr = model_instance.attribute_map.get(attr, attr)
if isinstance(value, list):
result[attr] = list(map(
lambda x: model_to_dict(x, serialize=serialize)
if hasattr(x, '_data_store') else x, value
))
if not value or isinstance(value[0], PRIMITIVE_TYPES):
# empty list or primitive types
result[attr] = value
elif isinstance(value[0], ModelSimple):
result[attr] = [x.value for x in value]
else:
result[attr] = [model_to_dict(x, serialize=serialize) for x in value]
elif isinstance(value, dict):
result[attr] = dict(map(
lambda item: (item[0],