[python-experimental] simplifies json serialization (#7061)

* Requires python >= 3.5, adds type hints to call_api method

* Adds type hints to files_parameters and __call_api

* Adds and uses a new json encoded to prepare data before it is sent

* Removes nose name from gitlab testing invocations

* Also updates travis to py>=3.5

* Collapses encoder back into sanitize_for_serialization
This commit is contained in:
Justin Black
2020-07-28 08:16:19 -07:00
committed by GitHub
parent fa75469828
commit 798ad2f87d
26 changed files with 331 additions and 311 deletions

View File

@@ -17,7 +17,7 @@ For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
## Requirements.
Python 3.4+
Python >= 3.5
## Installation & Usage
### pip install

View File

@@ -17,7 +17,7 @@ For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
## Requirements.
Python 2.7 and 3.4+
Python >= 3.5
## Installation & Usage

View File

@@ -5,8 +5,10 @@ import json
import atexit
import mimetypes
from multiprocessing.pool import ThreadPool
import io
import os
import re
import typing
from urllib.parse import quote
{{#tornado}}
@@ -54,9 +56,6 @@ class ApiClient(object):
to the API. More threads means more concurrent API requests.
"""
PRIMITIVE_TYPES = (
float, bool, bytes, str, int
)
_pool = None
def __init__(self, configuration=None, header_name=None, header_value=None,
@@ -114,12 +113,24 @@ class ApiClient(object):
@tornado.gen.coroutine
{{/tornado}}
{{#asyncio}}async {{/asyncio}}def __call_api(
self, resource_path, method, path_params=None,
query_params=None, header_params=None, body=None, post_params=None,
files=None, response_type=None, auth_settings=None,
_return_http_data_only=None, collection_formats=None,
_preload_content=True, _request_timeout=None, _host=None,
_check_type=None):
self,
resource_path: str,
method: str,
path_params: typing.Optional[typing.Dict[str, typing.Any]] = None,
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, typing.Tuple]] = None,
_host: typing.Optional[str] = None,
_check_type: typing.Optional[bool] = None
):
config = self.configuration
@@ -232,9 +243,9 @@ class ApiClient(object):
response_data.getheaders()))
{{/tornado}}
def sanitize_for_serialization(self, obj):
@classmethod
def sanitize_for_serialization(cls, obj):
"""Builds a JSON POST object.
If obj is None, return None.
If obj is str, int, long, float, bool, return directly.
If obj is datetime.datetime, datetime.date
@@ -242,35 +253,24 @@ 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.
:param obj: The data to serialize.
:return: The serialized form of data.
"""
if obj is None:
return None
elif isinstance(obj, self.PRIMITIVE_TYPES):
if isinstance(obj, (ModelNormal, ModelComposed)):
return {
key: cls.sanitize_for_serialization(val) for key, val in model_to_dict(obj, serialize=True).items()
}
elif isinstance(obj, (str, int, float, none_type, bool)):
return obj
elif isinstance(obj, list):
return [self.sanitize_for_serialization(sub_obj)
for sub_obj in obj]
elif isinstance(obj, tuple):
return tuple(self.sanitize_for_serialization(sub_obj)
for sub_obj in obj)
elif isinstance(obj, (datetime, date)):
return obj.isoformat()
if isinstance(obj, dict):
obj_dict = obj
elif isinstance(obj, ModelNormal) or isinstance(obj, ModelComposed):
# Convert model obj to dict
# Convert attribute name to json key in
# model definition for request
obj_dict = model_to_dict(obj, serialize=True)
elif isinstance(obj, ModelSimple):
return self.sanitize_for_serialization(obj.value)
return {key: self.sanitize_for_serialization(val)
for key, val in obj_dict.items()}
return cls.sanitize_for_serialization(obj.value)
elif isinstance(obj, (list, tuple)):
return [cls.sanitize_for_serialization(item) for item in obj]
if isinstance(obj, dict):
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):
"""Deserializes response into an object.
@@ -317,13 +317,26 @@ class ApiClient(object):
)
return deserialized_data
def call_api(self, resource_path, method,
path_params=None, query_params=None, header_params=None,
body=None, post_params=None, files=None,
response_type=None, auth_settings=None, async_req=None,
_return_http_data_only=None, collection_formats=None,
_preload_content=True, _request_timeout=None, _host=None,
_check_type=None):
def call_api(
self,
resource_path: str,
method: str,
path_params: typing.Optional[typing.Dict[str, typing.Any]] = None,
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,
async_req: typing.Optional[bool] = 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, typing.Tuple]] = None,
_host: typing.Optional[str] = None,
_check_type: typing.Optional[bool] = None
):
"""Makes the HTTP request (synchronous) and returns deserialized data.
To make an async_req request, set the async_req parameter.
@@ -490,7 +503,7 @@ class ApiClient(object):
new_params.append((k, v))
return new_params
def files_parameters(self, files=None):
def files_parameters(self, files: typing.Optional[typing.Dict[str, typing.List[io.IOBase]]] = None):
"""Builds form parameters.
:param files: None or a dict with key=param_name and
@@ -566,7 +579,7 @@ class ApiClient(object):
:param resource_path: A string representation of the HTTP request resource path.
:param method: A string representation of the HTTP request method.
:param body: A object representing the body of the HTTP request.
The object type is the return value of sanitize_for_serialization().
The object type is the return value of _encoder.default().
"""
if not auth_settings:
return

View File

@@ -3,7 +3,7 @@
stages:
- test
.nosetest:
.tests:
stage: test
script:
- pip install -r requirements.txt
@@ -15,21 +15,15 @@ stages:
- pytest --cov={{{packageName}}}
{{/useNose}}
nosetest-3.3:
extends: .nosetest
image: python:3.3-alpine
nosetest-3.4:
extends: .nosetest
image: python:3.4-alpine
nosetest-3.5:
extends: .nosetest
test-3.5:
extends: .tests
image: python:3.5-alpine
nosetest-3.6:
extends: .nosetest
test-3.6:
extends: .tests
image: python:3.6-alpine
nosetest-3.7:
extends: .nosetest
test-3.7:
extends: .tests
image: python:3.7-alpine
nosetest-3.8:
extends: .nosetest
test-3.8:
extends: .tests
image: python:3.8-alpine

View File

@@ -41,7 +41,7 @@ setup(
author_email="{{#infoEmail}}{{infoEmail}}{{/infoEmail}}{{^infoEmail}}team@openapitools.org{{/infoEmail}}",
url="{{packageUrl}}",
keywords=["OpenAPI", "OpenAPI-Generator", "{{{appName}}}"],
python_requires=">=3.3",
python_requires=">=3.5",
install_requires=REQUIRES,
packages=find_packages(exclude=["test", "tests"]),
include_package_data=True,

View File

@@ -1,9 +1,6 @@
# ref: https://docs.travis-ci.com/user/languages/python
language: python
python:
- "3.2"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
- "3.7"

View File

@@ -3,28 +3,22 @@
stages:
- test
.nosetest:
.tests:
stage: test
script:
- pip install -r requirements.txt
- pip install -r test-requirements.txt
- pytest --cov=petstore_api
nosetest-3.3:
extends: .nosetest
image: python:3.3-alpine
nosetest-3.4:
extends: .nosetest
image: python:3.4-alpine
nosetest-3.5:
extends: .nosetest
test-3.5:
extends: .tests
image: python:3.5-alpine
nosetest-3.6:
extends: .nosetest
test-3.6:
extends: .tests
image: python:3.6-alpine
nosetest-3.7:
extends: .nosetest
test-3.7:
extends: .tests
image: python:3.7-alpine
nosetest-3.8:
extends: .nosetest
test-3.8:
extends: .tests
image: python:3.8-alpine

View File

@@ -1,9 +1,6 @@
# ref: https://docs.travis-ci.com/user/languages/python
language: python
python:
- "3.2"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
- "3.7"

View File

@@ -9,7 +9,7 @@ This Python package is automatically generated by the [OpenAPI Generator](https:
## Requirements.
Python 3.4+
Python >= 3.5
## Installation & Usage
### pip install

View File

@@ -13,8 +13,10 @@ import json
import atexit
import mimetypes
from multiprocessing.pool import ThreadPool
import io
import os
import re
import typing
from urllib.parse import quote
@@ -59,9 +61,6 @@ class ApiClient(object):
to the API. More threads means more concurrent API requests.
"""
PRIMITIVE_TYPES = (
float, bool, bytes, str, int
)
_pool = None
def __init__(self, configuration=None, header_name=None, header_value=None,
@@ -116,12 +115,24 @@ class ApiClient(object):
self.default_headers[header_name] = header_value
def __call_api(
self, resource_path, method, path_params=None,
query_params=None, header_params=None, body=None, post_params=None,
files=None, response_type=None, auth_settings=None,
_return_http_data_only=None, collection_formats=None,
_preload_content=True, _request_timeout=None, _host=None,
_check_type=None):
self,
resource_path: str,
method: str,
path_params: typing.Optional[typing.Dict[str, typing.Any]] = None,
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, typing.Tuple]] = None,
_host: typing.Optional[str] = None,
_check_type: typing.Optional[bool] = None
):
config = self.configuration
@@ -220,9 +231,9 @@ class ApiClient(object):
return (return_data, response_data.status,
response_data.getheaders())
def sanitize_for_serialization(self, obj):
@classmethod
def sanitize_for_serialization(cls, obj):
"""Builds a JSON POST object.
If obj is None, return None.
If obj is str, int, long, float, bool, return directly.
If obj is datetime.datetime, datetime.date
@@ -230,35 +241,24 @@ 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.
:param obj: The data to serialize.
:return: The serialized form of data.
"""
if obj is None:
return None
elif isinstance(obj, self.PRIMITIVE_TYPES):
if isinstance(obj, (ModelNormal, ModelComposed)):
return {
key: cls.sanitize_for_serialization(val) for key, val in model_to_dict(obj, serialize=True).items()
}
elif isinstance(obj, (str, int, float, none_type, bool)):
return obj
elif isinstance(obj, list):
return [self.sanitize_for_serialization(sub_obj)
for sub_obj in obj]
elif isinstance(obj, tuple):
return tuple(self.sanitize_for_serialization(sub_obj)
for sub_obj in obj)
elif isinstance(obj, (datetime, date)):
return obj.isoformat()
if isinstance(obj, dict):
obj_dict = obj
elif isinstance(obj, ModelNormal) or isinstance(obj, ModelComposed):
# Convert model obj to dict
# Convert attribute name to json key in
# model definition for request
obj_dict = model_to_dict(obj, serialize=True)
elif isinstance(obj, ModelSimple):
return self.sanitize_for_serialization(obj.value)
return {key: self.sanitize_for_serialization(val)
for key, val in obj_dict.items()}
return cls.sanitize_for_serialization(obj.value)
elif isinstance(obj, (list, tuple)):
return [cls.sanitize_for_serialization(item) for item in obj]
if isinstance(obj, dict):
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):
"""Deserializes response into an object.
@@ -305,13 +305,26 @@ class ApiClient(object):
)
return deserialized_data
def call_api(self, resource_path, method,
path_params=None, query_params=None, header_params=None,
body=None, post_params=None, files=None,
response_type=None, auth_settings=None, async_req=None,
_return_http_data_only=None, collection_formats=None,
_preload_content=True, _request_timeout=None, _host=None,
_check_type=None):
def call_api(
self,
resource_path: str,
method: str,
path_params: typing.Optional[typing.Dict[str, typing.Any]] = None,
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,
async_req: typing.Optional[bool] = 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, typing.Tuple]] = None,
_host: typing.Optional[str] = None,
_check_type: typing.Optional[bool] = None
):
"""Makes the HTTP request (synchronous) and returns deserialized data.
To make an async_req request, set the async_req parameter.
@@ -478,7 +491,7 @@ class ApiClient(object):
new_params.append((k, v))
return new_params
def files_parameters(self, files=None):
def files_parameters(self, files: typing.Optional[typing.Dict[str, typing.List[io.IOBase]]] = None):
"""Builds form parameters.
:param files: None or a dict with key=param_name and
@@ -554,7 +567,7 @@ class ApiClient(object):
:param resource_path: A string representation of the HTTP request resource path.
:param method: A string representation of the HTTP request method.
:param body: A object representing the body of the HTTP request.
The object type is the return value of sanitize_for_serialization().
The object type is the return value of _encoder.default().
"""
if not auth_settings:
return

View File

@@ -36,7 +36,7 @@ setup(
author_email="team@openapitools.org",
url="",
keywords=["OpenAPI", "OpenAPI-Generator", "OpenAPI Petstore"],
python_requires=">=3.3",
python_requires=">=3.5",
install_requires=REQUIRES,
packages=find_packages(exclude=["test", "tests"]),
include_package_data=True,

View File

@@ -3,28 +3,22 @@
stages:
- test
.nosetest:
.tests:
stage: test
script:
- pip install -r requirements.txt
- pip install -r test-requirements.txt
- pytest --cov=x_auth_id_alias
nosetest-3.3:
extends: .nosetest
image: python:3.3-alpine
nosetest-3.4:
extends: .nosetest
image: python:3.4-alpine
nosetest-3.5:
extends: .nosetest
test-3.5:
extends: .tests
image: python:3.5-alpine
nosetest-3.6:
extends: .nosetest
test-3.6:
extends: .tests
image: python:3.6-alpine
nosetest-3.7:
extends: .nosetest
test-3.7:
extends: .tests
image: python:3.7-alpine
nosetest-3.8:
extends: .nosetest
test-3.8:
extends: .tests
image: python:3.8-alpine

View File

@@ -1,9 +1,6 @@
# ref: https://docs.travis-ci.com/user/languages/python
language: python
python:
- "3.2"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
- "3.7"

View File

@@ -9,7 +9,7 @@ This Python package is automatically generated by the [OpenAPI Generator](https:
## Requirements.
Python 3.4+
Python >= 3.5
## Installation & Usage
### pip install

View File

@@ -36,7 +36,7 @@ setup(
author_email="team@openapitools.org",
url="",
keywords=["OpenAPI", "OpenAPI-Generator", "OpenAPI Extension x-auth-id-alias"],
python_requires=">=3.3",
python_requires=">=3.5",
install_requires=REQUIRES,
packages=find_packages(exclude=["test", "tests"]),
include_package_data=True,

View File

@@ -13,8 +13,10 @@ import json
import atexit
import mimetypes
from multiprocessing.pool import ThreadPool
import io
import os
import re
import typing
from urllib.parse import quote
@@ -59,9 +61,6 @@ class ApiClient(object):
to the API. More threads means more concurrent API requests.
"""
PRIMITIVE_TYPES = (
float, bool, bytes, str, int
)
_pool = None
def __init__(self, configuration=None, header_name=None, header_value=None,
@@ -116,12 +115,24 @@ class ApiClient(object):
self.default_headers[header_name] = header_value
def __call_api(
self, resource_path, method, path_params=None,
query_params=None, header_params=None, body=None, post_params=None,
files=None, response_type=None, auth_settings=None,
_return_http_data_only=None, collection_formats=None,
_preload_content=True, _request_timeout=None, _host=None,
_check_type=None):
self,
resource_path: str,
method: str,
path_params: typing.Optional[typing.Dict[str, typing.Any]] = None,
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, typing.Tuple]] = None,
_host: typing.Optional[str] = None,
_check_type: typing.Optional[bool] = None
):
config = self.configuration
@@ -220,9 +231,9 @@ class ApiClient(object):
return (return_data, response_data.status,
response_data.getheaders())
def sanitize_for_serialization(self, obj):
@classmethod
def sanitize_for_serialization(cls, obj):
"""Builds a JSON POST object.
If obj is None, return None.
If obj is str, int, long, float, bool, return directly.
If obj is datetime.datetime, datetime.date
@@ -230,35 +241,24 @@ 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.
:param obj: The data to serialize.
:return: The serialized form of data.
"""
if obj is None:
return None
elif isinstance(obj, self.PRIMITIVE_TYPES):
if isinstance(obj, (ModelNormal, ModelComposed)):
return {
key: cls.sanitize_for_serialization(val) for key, val in model_to_dict(obj, serialize=True).items()
}
elif isinstance(obj, (str, int, float, none_type, bool)):
return obj
elif isinstance(obj, list):
return [self.sanitize_for_serialization(sub_obj)
for sub_obj in obj]
elif isinstance(obj, tuple):
return tuple(self.sanitize_for_serialization(sub_obj)
for sub_obj in obj)
elif isinstance(obj, (datetime, date)):
return obj.isoformat()
if isinstance(obj, dict):
obj_dict = obj
elif isinstance(obj, ModelNormal) or isinstance(obj, ModelComposed):
# Convert model obj to dict
# Convert attribute name to json key in
# model definition for request
obj_dict = model_to_dict(obj, serialize=True)
elif isinstance(obj, ModelSimple):
return self.sanitize_for_serialization(obj.value)
return {key: self.sanitize_for_serialization(val)
for key, val in obj_dict.items()}
return cls.sanitize_for_serialization(obj.value)
elif isinstance(obj, (list, tuple)):
return [cls.sanitize_for_serialization(item) for item in obj]
if isinstance(obj, dict):
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):
"""Deserializes response into an object.
@@ -305,13 +305,26 @@ class ApiClient(object):
)
return deserialized_data
def call_api(self, resource_path, method,
path_params=None, query_params=None, header_params=None,
body=None, post_params=None, files=None,
response_type=None, auth_settings=None, async_req=None,
_return_http_data_only=None, collection_formats=None,
_preload_content=True, _request_timeout=None, _host=None,
_check_type=None):
def call_api(
self,
resource_path: str,
method: str,
path_params: typing.Optional[typing.Dict[str, typing.Any]] = None,
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,
async_req: typing.Optional[bool] = 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, typing.Tuple]] = None,
_host: typing.Optional[str] = None,
_check_type: typing.Optional[bool] = None
):
"""Makes the HTTP request (synchronous) and returns deserialized data.
To make an async_req request, set the async_req parameter.
@@ -478,7 +491,7 @@ class ApiClient(object):
new_params.append((k, v))
return new_params
def files_parameters(self, files=None):
def files_parameters(self, files: typing.Optional[typing.Dict[str, typing.List[io.IOBase]]] = None):
"""Builds form parameters.
:param files: None or a dict with key=param_name and
@@ -554,7 +567,7 @@ class ApiClient(object):
:param resource_path: A string representation of the HTTP request resource path.
:param method: A string representation of the HTTP request method.
:param body: A object representing the body of the HTTP request.
The object type is the return value of sanitize_for_serialization().
The object type is the return value of _encoder.default().
"""
if not auth_settings:
return

View File

@@ -3,28 +3,22 @@
stages:
- test
.nosetest:
.tests:
stage: test
script:
- pip install -r requirements.txt
- pip install -r test-requirements.txt
- pytest --cov=dynamic_servers
nosetest-3.3:
extends: .nosetest
image: python:3.3-alpine
nosetest-3.4:
extends: .nosetest
image: python:3.4-alpine
nosetest-3.5:
extends: .nosetest
test-3.5:
extends: .tests
image: python:3.5-alpine
nosetest-3.6:
extends: .nosetest
test-3.6:
extends: .tests
image: python:3.6-alpine
nosetest-3.7:
extends: .nosetest
test-3.7:
extends: .tests
image: python:3.7-alpine
nosetest-3.8:
extends: .nosetest
test-3.8:
extends: .tests
image: python:3.8-alpine

View File

@@ -1,9 +1,6 @@
# ref: https://docs.travis-ci.com/user/languages/python
language: python
python:
- "3.2"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
- "3.7"

View File

@@ -9,7 +9,7 @@ This Python package is automatically generated by the [OpenAPI Generator](https:
## Requirements.
Python 3.4+
Python >= 3.5
## Installation & Usage
### pip install

View File

@@ -13,8 +13,10 @@ import json
import atexit
import mimetypes
from multiprocessing.pool import ThreadPool
import io
import os
import re
import typing
from urllib.parse import quote
@@ -59,9 +61,6 @@ class ApiClient(object):
to the API. More threads means more concurrent API requests.
"""
PRIMITIVE_TYPES = (
float, bool, bytes, str, int
)
_pool = None
def __init__(self, configuration=None, header_name=None, header_value=None,
@@ -116,12 +115,24 @@ class ApiClient(object):
self.default_headers[header_name] = header_value
def __call_api(
self, resource_path, method, path_params=None,
query_params=None, header_params=None, body=None, post_params=None,
files=None, response_type=None, auth_settings=None,
_return_http_data_only=None, collection_formats=None,
_preload_content=True, _request_timeout=None, _host=None,
_check_type=None):
self,
resource_path: str,
method: str,
path_params: typing.Optional[typing.Dict[str, typing.Any]] = None,
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, typing.Tuple]] = None,
_host: typing.Optional[str] = None,
_check_type: typing.Optional[bool] = None
):
config = self.configuration
@@ -220,9 +231,9 @@ class ApiClient(object):
return (return_data, response_data.status,
response_data.getheaders())
def sanitize_for_serialization(self, obj):
@classmethod
def sanitize_for_serialization(cls, obj):
"""Builds a JSON POST object.
If obj is None, return None.
If obj is str, int, long, float, bool, return directly.
If obj is datetime.datetime, datetime.date
@@ -230,35 +241,24 @@ 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.
:param obj: The data to serialize.
:return: The serialized form of data.
"""
if obj is None:
return None
elif isinstance(obj, self.PRIMITIVE_TYPES):
if isinstance(obj, (ModelNormal, ModelComposed)):
return {
key: cls.sanitize_for_serialization(val) for key, val in model_to_dict(obj, serialize=True).items()
}
elif isinstance(obj, (str, int, float, none_type, bool)):
return obj
elif isinstance(obj, list):
return [self.sanitize_for_serialization(sub_obj)
for sub_obj in obj]
elif isinstance(obj, tuple):
return tuple(self.sanitize_for_serialization(sub_obj)
for sub_obj in obj)
elif isinstance(obj, (datetime, date)):
return obj.isoformat()
if isinstance(obj, dict):
obj_dict = obj
elif isinstance(obj, ModelNormal) or isinstance(obj, ModelComposed):
# Convert model obj to dict
# Convert attribute name to json key in
# model definition for request
obj_dict = model_to_dict(obj, serialize=True)
elif isinstance(obj, ModelSimple):
return self.sanitize_for_serialization(obj.value)
return {key: self.sanitize_for_serialization(val)
for key, val in obj_dict.items()}
return cls.sanitize_for_serialization(obj.value)
elif isinstance(obj, (list, tuple)):
return [cls.sanitize_for_serialization(item) for item in obj]
if isinstance(obj, dict):
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):
"""Deserializes response into an object.
@@ -305,13 +305,26 @@ class ApiClient(object):
)
return deserialized_data
def call_api(self, resource_path, method,
path_params=None, query_params=None, header_params=None,
body=None, post_params=None, files=None,
response_type=None, auth_settings=None, async_req=None,
_return_http_data_only=None, collection_formats=None,
_preload_content=True, _request_timeout=None, _host=None,
_check_type=None):
def call_api(
self,
resource_path: str,
method: str,
path_params: typing.Optional[typing.Dict[str, typing.Any]] = None,
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,
async_req: typing.Optional[bool] = 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, typing.Tuple]] = None,
_host: typing.Optional[str] = None,
_check_type: typing.Optional[bool] = None
):
"""Makes the HTTP request (synchronous) and returns deserialized data.
To make an async_req request, set the async_req parameter.
@@ -478,7 +491,7 @@ class ApiClient(object):
new_params.append((k, v))
return new_params
def files_parameters(self, files=None):
def files_parameters(self, files: typing.Optional[typing.Dict[str, typing.List[io.IOBase]]] = None):
"""Builds form parameters.
:param files: None or a dict with key=param_name and
@@ -554,7 +567,7 @@ class ApiClient(object):
:param resource_path: A string representation of the HTTP request resource path.
:param method: A string representation of the HTTP request method.
:param body: A object representing the body of the HTTP request.
The object type is the return value of sanitize_for_serialization().
The object type is the return value of _encoder.default().
"""
if not auth_settings:
return

View File

@@ -36,7 +36,7 @@ setup(
author_email="team@openapitools.org",
url="",
keywords=["OpenAPI", "OpenAPI-Generator", "OpenAPI Extension with dynamic servers"],
python_requires=">=3.3",
python_requires=">=3.5",
install_requires=REQUIRES,
packages=find_packages(exclude=["test", "tests"]),
include_package_data=True,

View File

@@ -3,28 +3,22 @@
stages:
- test
.nosetest:
.tests:
stage: test
script:
- pip install -r requirements.txt
- pip install -r test-requirements.txt
- pytest --cov=petstore_api
nosetest-3.3:
extends: .nosetest
image: python:3.3-alpine
nosetest-3.4:
extends: .nosetest
image: python:3.4-alpine
nosetest-3.5:
extends: .nosetest
test-3.5:
extends: .tests
image: python:3.5-alpine
nosetest-3.6:
extends: .nosetest
test-3.6:
extends: .tests
image: python:3.6-alpine
nosetest-3.7:
extends: .nosetest
test-3.7:
extends: .tests
image: python:3.7-alpine
nosetest-3.8:
extends: .nosetest
test-3.8:
extends: .tests
image: python:3.8-alpine

View File

@@ -1,9 +1,6 @@
# ref: https://docs.travis-ci.com/user/languages/python
language: python
python:
- "3.2"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
- "3.7"

View File

@@ -9,7 +9,7 @@ This Python package is automatically generated by the [OpenAPI Generator](https:
## Requirements.
Python 3.4+
Python >= 3.5
## Installation & Usage
### pip install

View File

@@ -13,8 +13,10 @@ import json
import atexit
import mimetypes
from multiprocessing.pool import ThreadPool
import io
import os
import re
import typing
from urllib.parse import quote
@@ -59,9 +61,6 @@ class ApiClient(object):
to the API. More threads means more concurrent API requests.
"""
PRIMITIVE_TYPES = (
float, bool, bytes, str, int
)
_pool = None
def __init__(self, configuration=None, header_name=None, header_value=None,
@@ -116,12 +115,24 @@ class ApiClient(object):
self.default_headers[header_name] = header_value
def __call_api(
self, resource_path, method, path_params=None,
query_params=None, header_params=None, body=None, post_params=None,
files=None, response_type=None, auth_settings=None,
_return_http_data_only=None, collection_formats=None,
_preload_content=True, _request_timeout=None, _host=None,
_check_type=None):
self,
resource_path: str,
method: str,
path_params: typing.Optional[typing.Dict[str, typing.Any]] = None,
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, typing.Tuple]] = None,
_host: typing.Optional[str] = None,
_check_type: typing.Optional[bool] = None
):
config = self.configuration
@@ -220,9 +231,9 @@ class ApiClient(object):
return (return_data, response_data.status,
response_data.getheaders())
def sanitize_for_serialization(self, obj):
@classmethod
def sanitize_for_serialization(cls, obj):
"""Builds a JSON POST object.
If obj is None, return None.
If obj is str, int, long, float, bool, return directly.
If obj is datetime.datetime, datetime.date
@@ -230,35 +241,24 @@ 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.
:param obj: The data to serialize.
:return: The serialized form of data.
"""
if obj is None:
return None
elif isinstance(obj, self.PRIMITIVE_TYPES):
if isinstance(obj, (ModelNormal, ModelComposed)):
return {
key: cls.sanitize_for_serialization(val) for key, val in model_to_dict(obj, serialize=True).items()
}
elif isinstance(obj, (str, int, float, none_type, bool)):
return obj
elif isinstance(obj, list):
return [self.sanitize_for_serialization(sub_obj)
for sub_obj in obj]
elif isinstance(obj, tuple):
return tuple(self.sanitize_for_serialization(sub_obj)
for sub_obj in obj)
elif isinstance(obj, (datetime, date)):
return obj.isoformat()
if isinstance(obj, dict):
obj_dict = obj
elif isinstance(obj, ModelNormal) or isinstance(obj, ModelComposed):
# Convert model obj to dict
# Convert attribute name to json key in
# model definition for request
obj_dict = model_to_dict(obj, serialize=True)
elif isinstance(obj, ModelSimple):
return self.sanitize_for_serialization(obj.value)
return {key: self.sanitize_for_serialization(val)
for key, val in obj_dict.items()}
return cls.sanitize_for_serialization(obj.value)
elif isinstance(obj, (list, tuple)):
return [cls.sanitize_for_serialization(item) for item in obj]
if isinstance(obj, dict):
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):
"""Deserializes response into an object.
@@ -305,13 +305,26 @@ class ApiClient(object):
)
return deserialized_data
def call_api(self, resource_path, method,
path_params=None, query_params=None, header_params=None,
body=None, post_params=None, files=None,
response_type=None, auth_settings=None, async_req=None,
_return_http_data_only=None, collection_formats=None,
_preload_content=True, _request_timeout=None, _host=None,
_check_type=None):
def call_api(
self,
resource_path: str,
method: str,
path_params: typing.Optional[typing.Dict[str, typing.Any]] = None,
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,
async_req: typing.Optional[bool] = 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, typing.Tuple]] = None,
_host: typing.Optional[str] = None,
_check_type: typing.Optional[bool] = None
):
"""Makes the HTTP request (synchronous) and returns deserialized data.
To make an async_req request, set the async_req parameter.
@@ -478,7 +491,7 @@ class ApiClient(object):
new_params.append((k, v))
return new_params
def files_parameters(self, files=None):
def files_parameters(self, files: typing.Optional[typing.Dict[str, typing.List[io.IOBase]]] = None):
"""Builds form parameters.
:param files: None or a dict with key=param_name and
@@ -554,7 +567,7 @@ class ApiClient(object):
:param resource_path: A string representation of the HTTP request resource path.
:param method: A string representation of the HTTP request method.
:param body: A object representing the body of the HTTP request.
The object type is the return value of sanitize_for_serialization().
The object type is the return value of _encoder.default().
"""
if not auth_settings:
return

View File

@@ -38,7 +38,7 @@ setup(
author_email="team@openapitools.org",
url="",
keywords=["OpenAPI", "OpenAPI-Generator", "OpenAPI Petstore"],
python_requires=">=3.3",
python_requires=">=3.5",
install_requires=REQUIRES,
packages=find_packages(exclude=["test", "tests"]),
include_package_data=True,