update and fix python samples (#489)

* fix: update petstore samples for python, fix broken tests

* chore: entries for python-asyncio/tornado in gitignore
This commit is contained in:
Tomasz Prus
2018-07-08 09:29:55 +02:00
committed by William Cheng
parent 950c584485
commit 96e86ac03e
62 changed files with 2594 additions and 20 deletions

View File

@@ -42,6 +42,8 @@ from petstore_api.models.dog import Dog
from petstore_api.models.enum_arrays import EnumArrays
from petstore_api.models.enum_class import EnumClass
from petstore_api.models.enum_test import EnumTest
from petstore_api.models.file import File
from petstore_api.models.file_schema_test_class import FileSchemaTestClass
from petstore_api.models.format_test import FormatTest
from petstore_api.models.has_only_read_only import HasOnlyReadOnly
from petstore_api.models.list import List
@@ -57,5 +59,6 @@ from petstore_api.models.outer_enum import OuterEnum
from petstore_api.models.pet import Pet
from petstore_api.models.read_only_first import ReadOnlyFirst
from petstore_api.models.special_model_name import SpecialModelName
from petstore_api.models.string_boolean_map import StringBooleanMap
from petstore_api.models.tag import Tag
from petstore_api.models.user import User

View File

@@ -396,6 +396,101 @@ class FakeApi(object):
_request_timeout=params.get('_request_timeout'),
collection_formats=collection_formats)
def test_body_with_file_schema(self, file_schema_test_class, **kwargs): # noqa: E501
"""test_body_with_file_schema # noqa: E501
For this test, the body for this request much reference a schema named `File`. # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async=True
>>> thread = api.test_body_with_file_schema(file_schema_test_class, async=True)
>>> result = thread.get()
:param async bool
:param FileSchemaTestClass file_schema_test_class: (required)
:return: None
If the method is called asynchronously,
returns the request thread.
"""
kwargs['_return_http_data_only'] = True
if kwargs.get('async'):
return self.test_body_with_file_schema_with_http_info(file_schema_test_class, **kwargs) # noqa: E501
else:
(data) = self.test_body_with_file_schema_with_http_info(file_schema_test_class, **kwargs) # noqa: E501
return data
def test_body_with_file_schema_with_http_info(self, file_schema_test_class, **kwargs): # noqa: E501
"""test_body_with_file_schema # noqa: E501
For this test, the body for this request much reference a schema named `File`. # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async=True
>>> thread = api.test_body_with_file_schema_with_http_info(file_schema_test_class, async=True)
>>> result = thread.get()
:param async bool
:param FileSchemaTestClass file_schema_test_class: (required)
:return: None
If the method is called asynchronously,
returns the request thread.
"""
all_params = ['file_schema_test_class'] # noqa: E501
all_params.append('async')
all_params.append('_return_http_data_only')
all_params.append('_preload_content')
all_params.append('_request_timeout')
params = locals()
for key, val in six.iteritems(params['kwargs']):
if key not in all_params:
raise TypeError(
"Got an unexpected keyword argument '%s'"
" to method test_body_with_file_schema" % key
)
params[key] = val
del params['kwargs']
# verify the required parameter 'file_schema_test_class' is set
if ('file_schema_test_class' not in params or
params['file_schema_test_class'] is None):
raise ValueError("Missing the required parameter `file_schema_test_class` when calling `test_body_with_file_schema`") # noqa: E501
collection_formats = {}
path_params = {}
query_params = []
header_params = {}
form_params = []
local_var_files = {}
body_params = None
if 'file_schema_test_class' in params:
body_params = params['file_schema_test_class']
# HTTP header `Content-Type`
header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501
['application/json']) # noqa: E501
# Authentication setting
auth_settings = [] # noqa: E501
return self.api_client.call_api(
'/fake/body-with-file-schema', 'PUT',
path_params,
query_params,
header_params,
body=body_params,
post_params=form_params,
files=local_var_files,
response_type=None, # noqa: E501
auth_settings=auth_settings,
async=params.get('async'),
_return_http_data_only=params.get('_return_http_data_only'),
_preload_content=params.get('_preload_content', True),
_request_timeout=params.get('_request_timeout'),
collection_formats=collection_formats)
def test_body_with_query_params(self, query, user, **kwargs): # noqa: E501
"""test_body_with_query_params # noqa: E501

View File

@@ -803,3 +803,112 @@ class PetApi(object):
_preload_content=params.get('_preload_content', True),
_request_timeout=params.get('_request_timeout'),
collection_formats=collection_formats)
def upload_file_with_required_file(self, pet_id, file, **kwargs): # noqa: E501
"""uploads an image (required) # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async=True
>>> thread = api.upload_file_with_required_file(pet_id, file, async=True)
>>> result = thread.get()
:param async bool
:param int pet_id: ID of pet to update (required)
:param file file: file to upload (required)
:param str additional_metadata: Additional data to pass to server
:return: ApiResponse
If the method is called asynchronously,
returns the request thread.
"""
kwargs['_return_http_data_only'] = True
if kwargs.get('async'):
return self.upload_file_with_required_file_with_http_info(pet_id, file, **kwargs) # noqa: E501
else:
(data) = self.upload_file_with_required_file_with_http_info(pet_id, file, **kwargs) # noqa: E501
return data
def upload_file_with_required_file_with_http_info(self, pet_id, file, **kwargs): # noqa: E501
"""uploads an image (required) # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async=True
>>> thread = api.upload_file_with_required_file_with_http_info(pet_id, file, async=True)
>>> result = thread.get()
:param async bool
:param int pet_id: ID of pet to update (required)
:param file file: file to upload (required)
:param str additional_metadata: Additional data to pass to server
:return: ApiResponse
If the method is called asynchronously,
returns the request thread.
"""
all_params = ['pet_id', 'file', 'additional_metadata'] # noqa: E501
all_params.append('async')
all_params.append('_return_http_data_only')
all_params.append('_preload_content')
all_params.append('_request_timeout')
params = locals()
for key, val in six.iteritems(params['kwargs']):
if key not in all_params:
raise TypeError(
"Got an unexpected keyword argument '%s'"
" to method upload_file_with_required_file" % key
)
params[key] = val
del params['kwargs']
# verify the required parameter 'pet_id' is set
if ('pet_id' not in params or
params['pet_id'] is None):
raise ValueError("Missing the required parameter `pet_id` when calling `upload_file_with_required_file`") # noqa: E501
# verify the required parameter 'file' is set
if ('file' not in params or
params['file'] is None):
raise ValueError("Missing the required parameter `file` when calling `upload_file_with_required_file`") # noqa: E501
collection_formats = {}
path_params = {}
if 'pet_id' in params:
path_params['petId'] = params['pet_id'] # noqa: E501
query_params = []
header_params = {}
form_params = []
local_var_files = {}
if 'additional_metadata' in params:
form_params.append(('additionalMetadata', params['additional_metadata'])) # noqa: E501
if 'file' in params:
local_var_files['file'] = params['file'] # noqa: E501
body_params = None
# HTTP header `Accept`
header_params['Accept'] = self.api_client.select_header_accept(
['application/json']) # noqa: E501
# HTTP header `Content-Type`
header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501
['multipart/form-data']) # noqa: E501
# Authentication setting
auth_settings = ['petstore_auth'] # noqa: E501
return self.api_client.call_api(
'/fake/{petId}/uploadImageWithRequiredFile', 'POST',
path_params,
query_params,
header_params,
body=body_params,
post_params=form_params,
files=local_var_files,
response_type='ApiResponse', # noqa: E501
auth_settings=auth_settings,
async=params.get('async'),
_return_http_data_only=params.get('_return_http_data_only'),
_preload_content=params.get('_preload_content', True),
_request_timeout=params.get('_request_timeout'),
collection_formats=collection_formats)

View File

@@ -545,7 +545,7 @@ class ApiClient(object):
return data
def __deserialize_object(self, value):
"""Return a original value.
"""Return an original value.
:return: object.
"""

View File

@@ -30,6 +30,8 @@ from petstore_api.models.dog import Dog
from petstore_api.models.enum_arrays import EnumArrays
from petstore_api.models.enum_class import EnumClass
from petstore_api.models.enum_test import EnumTest
from petstore_api.models.file import File
from petstore_api.models.file_schema_test_class import FileSchemaTestClass
from petstore_api.models.format_test import FormatTest
from petstore_api.models.has_only_read_only import HasOnlyReadOnly
from petstore_api.models.list import List
@@ -45,5 +47,6 @@ from petstore_api.models.outer_enum import OuterEnum
from petstore_api.models.pet import Pet
from petstore_api.models.read_only_first import ReadOnlyFirst
from petstore_api.models.special_model_name import SpecialModelName
from petstore_api.models.string_boolean_map import StringBooleanMap
from petstore_api.models.tag import Tag
from petstore_api.models.user import User

View File

@@ -0,0 +1,114 @@
# coding: utf-8
"""
OpenAPI Petstore
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501
OpenAPI spec version: 1.0.0
Generated by: https://openapi-generator.tech
"""
import pprint
import re # noqa: F401
import six
class File(object):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""
"""
Attributes:
openapi_types (dict): The key is attribute name
and the value is attribute type.
attribute_map (dict): The key is attribute name
and the value is json key in definition.
"""
openapi_types = {
'source_uri': 'str'
}
attribute_map = {
'source_uri': 'sourceURI'
}
def __init__(self, source_uri=None): # noqa: E501
"""File - a model defined in OpenAPI""" # noqa: E501
self._source_uri = None
self.discriminator = None
if source_uri is not None:
self.source_uri = source_uri
@property
def source_uri(self):
"""Gets the source_uri of this File. # noqa: E501
Test capitalization # noqa: E501
:return: The source_uri of this File. # noqa: E501
:rtype: str
"""
return self._source_uri
@source_uri.setter
def source_uri(self, source_uri):
"""Sets the source_uri of this File.
Test capitalization # noqa: E501
:param source_uri: The source_uri of this File. # noqa: E501
:type: str
"""
self._source_uri = source_uri
def to_dict(self):
"""Returns the model properties as a dict"""
result = {}
for attr, _ in six.iteritems(self.openapi_types):
value = getattr(self, attr)
if isinstance(value, list):
result[attr] = list(map(
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
value
))
elif hasattr(value, "to_dict"):
result[attr] = value.to_dict()
elif isinstance(value, dict):
result[attr] = dict(map(
lambda item: (item[0], item[1].to_dict())
if hasattr(item[1], "to_dict") else item,
value.items()
))
else:
result[attr] = value
return result
def to_str(self):
"""Returns the string representation of the model"""
return pprint.pformat(self.to_dict())
def __repr__(self):
"""For `print` and `pprint`"""
return self.to_str()
def __eq__(self, other):
"""Returns true if both objects are equal"""
if not isinstance(other, File):
return False
return self.__dict__ == other.__dict__
def __ne__(self, other):
"""Returns true if both objects are not equal"""
return not self == other

View File

@@ -0,0 +1,138 @@
# coding: utf-8
"""
OpenAPI Petstore
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501
OpenAPI spec version: 1.0.0
Generated by: https://openapi-generator.tech
"""
import pprint
import re # noqa: F401
import six
class FileSchemaTestClass(object):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""
"""
Attributes:
openapi_types (dict): The key is attribute name
and the value is attribute type.
attribute_map (dict): The key is attribute name
and the value is json key in definition.
"""
openapi_types = {
'file': 'File',
'files': 'list[File]'
}
attribute_map = {
'file': 'file',
'files': 'files'
}
def __init__(self, file=None, files=None): # noqa: E501
"""FileSchemaTestClass - a model defined in OpenAPI""" # noqa: E501
self._file = None
self._files = None
self.discriminator = None
if file is not None:
self.file = file
if files is not None:
self.files = files
@property
def file(self):
"""Gets the file of this FileSchemaTestClass. # noqa: E501
:return: The file of this FileSchemaTestClass. # noqa: E501
:rtype: File
"""
return self._file
@file.setter
def file(self, file):
"""Sets the file of this FileSchemaTestClass.
:param file: The file of this FileSchemaTestClass. # noqa: E501
:type: File
"""
self._file = file
@property
def files(self):
"""Gets the files of this FileSchemaTestClass. # noqa: E501
:return: The files of this FileSchemaTestClass. # noqa: E501
:rtype: list[File]
"""
return self._files
@files.setter
def files(self, files):
"""Sets the files of this FileSchemaTestClass.
:param files: The files of this FileSchemaTestClass. # noqa: E501
:type: list[File]
"""
self._files = files
def to_dict(self):
"""Returns the model properties as a dict"""
result = {}
for attr, _ in six.iteritems(self.openapi_types):
value = getattr(self, attr)
if isinstance(value, list):
result[attr] = list(map(
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
value
))
elif hasattr(value, "to_dict"):
result[attr] = value.to_dict()
elif isinstance(value, dict):
result[attr] = dict(map(
lambda item: (item[0], item[1].to_dict())
if hasattr(item[1], "to_dict") else item,
value.items()
))
else:
result[attr] = value
return result
def to_str(self):
"""Returns the string representation of the model"""
return pprint.pformat(self.to_dict())
def __repr__(self):
"""For `print` and `pprint`"""
return self.to_str()
def __eq__(self, other):
"""Returns true if both objects are equal"""
if not isinstance(other, FileSchemaTestClass):
return False
return self.__dict__ == other.__dict__
def __ne__(self, other):
"""Returns true if both objects are not equal"""
return not self == other

View File

@@ -32,25 +32,35 @@ class MapTest(object):
"""
openapi_types = {
'map_map_of_string': 'dict(str, dict(str, str))',
'map_of_enum_string': 'dict(str, str)'
'map_of_enum_string': 'dict(str, str)',
'direct_map': 'dict(str, bool)',
'indirect_map': 'StringBooleanMap'
}
attribute_map = {
'map_map_of_string': 'map_map_of_string',
'map_of_enum_string': 'map_of_enum_string'
'map_of_enum_string': 'map_of_enum_string',
'direct_map': 'direct_map',
'indirect_map': 'indirect_map'
}
def __init__(self, map_map_of_string=None, map_of_enum_string=None): # noqa: E501
def __init__(self, map_map_of_string=None, map_of_enum_string=None, direct_map=None, indirect_map=None): # noqa: E501
"""MapTest - a model defined in OpenAPI""" # noqa: E501
self._map_map_of_string = None
self._map_of_enum_string = None
self._direct_map = None
self._indirect_map = None
self.discriminator = None
if map_map_of_string is not None:
self.map_map_of_string = map_map_of_string
if map_of_enum_string is not None:
self.map_of_enum_string = map_of_enum_string
if direct_map is not None:
self.direct_map = direct_map
if indirect_map is not None:
self.indirect_map = indirect_map
@property
def map_map_of_string(self):
@@ -101,6 +111,48 @@ class MapTest(object):
self._map_of_enum_string = map_of_enum_string
@property
def direct_map(self):
"""Gets the direct_map of this MapTest. # noqa: E501
:return: The direct_map of this MapTest. # noqa: E501
:rtype: dict(str, bool)
"""
return self._direct_map
@direct_map.setter
def direct_map(self, direct_map):
"""Sets the direct_map of this MapTest.
:param direct_map: The direct_map of this MapTest. # noqa: E501
:type: dict(str, bool)
"""
self._direct_map = direct_map
@property
def indirect_map(self):
"""Gets the indirect_map of this MapTest. # noqa: E501
:return: The indirect_map of this MapTest. # noqa: E501
:rtype: StringBooleanMap
"""
return self._indirect_map
@indirect_map.setter
def indirect_map(self, indirect_map):
"""Sets the indirect_map of this MapTest.
:param indirect_map: The indirect_map of this MapTest. # noqa: E501
:type: StringBooleanMap
"""
self._indirect_map = indirect_map
def to_dict(self):
"""Returns the model properties as a dict"""
result = {}

View File

@@ -0,0 +1,84 @@
# coding: utf-8
"""
OpenAPI Petstore
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501
OpenAPI spec version: 1.0.0
Generated by: https://openapi-generator.tech
"""
import pprint
import re # noqa: F401
import six
class StringBooleanMap(object):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""
"""
Attributes:
openapi_types (dict): The key is attribute name
and the value is attribute type.
attribute_map (dict): The key is attribute name
and the value is json key in definition.
"""
openapi_types = {
}
attribute_map = {
}
def __init__(self): # noqa: E501
"""StringBooleanMap - a model defined in OpenAPI""" # noqa: E501
self.discriminator = None
def to_dict(self):
"""Returns the model properties as a dict"""
result = {}
for attr, _ in six.iteritems(self.openapi_types):
value = getattr(self, attr)
if isinstance(value, list):
result[attr] = list(map(
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
value
))
elif hasattr(value, "to_dict"):
result[attr] = value.to_dict()
elif isinstance(value, dict):
result[attr] = dict(map(
lambda item: (item[0], item[1].to_dict())
if hasattr(item[1], "to_dict") else item,
value.items()
))
else:
result[attr] = value
return result
def to_str(self):
"""Returns the string representation of the model"""
return pprint.pformat(self.to_dict())
def __repr__(self):
"""For `print` and `pprint`"""
return self.to_str()
def __eq__(self, other):
"""Returns true if both objects are equal"""
if not isinstance(other, StringBooleanMap):
return False
return self.__dict__ == other.__dict__
def __ne__(self, other):
"""Returns true if both objects are not equal"""
return not self == other