Merge branch 'master' of github.com:wordnik/swagger-codegen

This commit is contained in:
Tony Tam 2013-10-22 12:08:56 -07:00
commit 59da358eb5
20 changed files with 317 additions and 127 deletions

View File

@ -159,7 +159,7 @@ class ApiClient:
instance = objClass()
for attr, attrType in instance.swaggerTypes.iteritems():
if attr in obj:
if obj is not None and attr in obj and type(obj) in [list, dict]:
value = obj[attr]
if attrType in ['str', 'int', 'long', 'float', 'bool']:
attrType = eval(attrType)

View File

@ -33,7 +33,7 @@ class PetApi(object):
"""Find pet by ID
Args:
petId, str: ID of pet that needs to be fetched (required)
petId, int: ID of pet that needs to be fetched (required)
Returns: Pet
"""
@ -47,7 +47,7 @@ class PetApi(object):
params[key] = val
del params['kwargs']
resourcePath = '/pet.{format}/{petId}'
resourcePath = '/pet/{petId}'
resourcePath = resourcePath.replace('{format}', 'json')
method = 'GET'
@ -70,6 +70,155 @@ class PetApi(object):
return responseObject
def deletePet(self, petId, **kwargs):
"""Deletes a pet
Args:
petId, str: Pet id to delete (required)
Returns:
"""
allParams = ['petId']
params = locals()
for (key, val) in params['kwargs'].items():
if key not in allParams:
raise TypeError("Got an unexpected keyword argument '%s' to method deletePet" % key)
params[key] = val
del params['kwargs']
resourcePath = '/pet/{petId}'
resourcePath = resourcePath.replace('{format}', 'json')
method = 'DELETE'
queryParams = {}
headerParams = {}
if ('petId' in params):
replacement = str(self.apiClient.toPathValue(params['petId']))
resourcePath = resourcePath.replace('{' + 'petId' + '}',
replacement)
postData = (params['body'] if 'body' in params else None)
response = self.apiClient.callAPI(resourcePath, method, queryParams,
postData, headerParams)
def partialUpdate(self, petId, body, **kwargs):
"""partial updates to a pet
Args:
petId, str: ID of pet that needs to be fetched (required)
body, Pet: Pet object that needs to be added to the store (required)
Returns: Array[Pet]
"""
allParams = ['petId', 'body']
params = locals()
for (key, val) in params['kwargs'].items():
if key not in allParams:
raise TypeError("Got an unexpected keyword argument '%s' to method partialUpdate" % key)
params[key] = val
del params['kwargs']
resourcePath = '/pet/{petId}'
resourcePath = resourcePath.replace('{format}', 'json')
method = 'PATCH'
queryParams = {}
headerParams = {}
if ('petId' in params):
replacement = str(self.apiClient.toPathValue(params['petId']))
resourcePath = resourcePath.replace('{' + 'petId' + '}',
replacement)
postData = (params['body'] if 'body' in params else None)
response = self.apiClient.callAPI(resourcePath, method, queryParams,
postData, headerParams)
if not response:
return None
responseObject = self.apiClient.deserialize(response, 'Array[Pet]')
return responseObject
def updatePetWithForm(self, petId, **kwargs):
"""Updates a pet in the store with form data
Args:
petId, str: ID of pet that needs to be updated (required)
name, str: Updated name of the pet (optional)
status, str: Updated status of the pet (optional)
Returns:
"""
allParams = ['petId', 'name', 'status']
params = locals()
for (key, val) in params['kwargs'].items():
if key not in allParams:
raise TypeError("Got an unexpected keyword argument '%s' to method updatePetWithForm" % key)
params[key] = val
del params['kwargs']
resourcePath = '/pet/{petId}'
resourcePath = resourcePath.replace('{format}', 'json')
method = 'POST'
queryParams = {}
headerParams = {}
if ('petId' in params):
replacement = str(self.apiClient.toPathValue(params['petId']))
resourcePath = resourcePath.replace('{' + 'petId' + '}',
replacement)
postData = (params['body'] if 'body' in params else None)
response = self.apiClient.callAPI(resourcePath, method, queryParams,
postData, headerParams)
def uploadFile(self, **kwargs):
"""uploads an image
Args:
additionalMetadata, str: Additional data to pass to server (optional)
body, File: file to upload (optional)
Returns:
"""
allParams = ['additionalMetadata', 'body']
params = locals()
for (key, val) in params['kwargs'].items():
if key not in allParams:
raise TypeError("Got an unexpected keyword argument '%s' to method uploadFile" % key)
params[key] = val
del params['kwargs']
resourcePath = '/pet/uploadImage'
resourcePath = resourcePath.replace('{format}', 'json')
method = 'POST'
queryParams = {}
headerParams = {}
postData = (params['body'] if 'body' in params else None)
response = self.apiClient.callAPI(resourcePath, method, queryParams,
postData, headerParams)
def addPet(self, body, **kwargs):
"""Add a new pet to the store
@ -88,7 +237,7 @@ class PetApi(object):
params[key] = val
del params['kwargs']
resourcePath = '/pet.{format}'
resourcePath = '/pet'
resourcePath = resourcePath.replace('{format}', 'json')
method = 'POST'
@ -120,7 +269,7 @@ class PetApi(object):
params[key] = val
del params['kwargs']
resourcePath = '/pet.{format}'
resourcePath = '/pet'
resourcePath = resourcePath.replace('{format}', 'json')
method = 'PUT'
@ -140,7 +289,7 @@ class PetApi(object):
Args:
status, str: Status values that need to be considered for filter (required)
Returns: list[Pet]
Returns: Array[Pet]
"""
allParams = ['status']
@ -152,7 +301,7 @@ class PetApi(object):
params[key] = val
del params['kwargs']
resourcePath = '/pet.{format}/findByStatus'
resourcePath = '/pet/findByStatus'
resourcePath = resourcePath.replace('{format}', 'json')
method = 'GET'
@ -169,7 +318,7 @@ class PetApi(object):
if not response:
return None
responseObject = self.apiClient.deserialize(response, 'list[Pet]')
responseObject = self.apiClient.deserialize(response, 'Array[Pet]')
return responseObject
@ -179,7 +328,7 @@ class PetApi(object):
Args:
tags, str: Tags to filter by (required)
Returns: list[Pet]
Returns: Array[Pet]
"""
allParams = ['tags']
@ -191,7 +340,7 @@ class PetApi(object):
params[key] = val
del params['kwargs']
resourcePath = '/pet.{format}/findByTags'
resourcePath = '/pet/findByTags'
resourcePath = resourcePath.replace('{format}', 'json')
method = 'GET'
@ -208,7 +357,7 @@ class PetApi(object):
if not response:
return None
responseObject = self.apiClient.deserialize(response, 'list[Pet]')
responseObject = self.apiClient.deserialize(response, 'Array[Pet]')
return responseObject

View File

@ -47,7 +47,7 @@ class StoreApi(object):
params[key] = val
del params['kwargs']
resourcePath = '/store.{format}/order/{orderId}'
resourcePath = '/store/order/{orderId}'
resourcePath = resourcePath.replace('{format}', 'json')
method = 'GET'
@ -88,7 +88,7 @@ class StoreApi(object):
params[key] = val
del params['kwargs']
resourcePath = '/store.{format}/order/{orderId}'
resourcePath = '/store/order/{orderId}'
resourcePath = resourcePath.replace('{format}', 'json')
method = 'DELETE'
@ -124,7 +124,7 @@ class StoreApi(object):
params[key] = val
del params['kwargs']
resourcePath = '/store.{format}/order'
resourcePath = '/store/order'
resourcePath = resourcePath.replace('{format}', 'json')
method = 'POST'

View File

@ -29,38 +29,6 @@ class UserApi(object):
self.apiClient = apiClient
def createUsersWithArrayInput(self, body, **kwargs):
"""Creates list of users with given input array
Args:
body, list[User]: List of user object (required)
Returns:
"""
allParams = ['body']
params = locals()
for (key, val) in params['kwargs'].items():
if key not in allParams:
raise TypeError("Got an unexpected keyword argument '%s' to method createUsersWithArrayInput" % key)
params[key] = val
del params['kwargs']
resourcePath = '/user.{format}/createWithArray'
resourcePath = resourcePath.replace('{format}', 'json')
method = 'POST'
queryParams = {}
headerParams = {}
postData = (params['body'] if 'body' in params else None)
response = self.apiClient.callAPI(resourcePath, method, queryParams,
postData, headerParams)
def createUser(self, body, **kwargs):
"""Create user
@ -79,7 +47,39 @@ class UserApi(object):
params[key] = val
del params['kwargs']
resourcePath = '/user.{format}'
resourcePath = '/user'
resourcePath = resourcePath.replace('{format}', 'json')
method = 'POST'
queryParams = {}
headerParams = {}
postData = (params['body'] if 'body' in params else None)
response = self.apiClient.callAPI(resourcePath, method, queryParams,
postData, headerParams)
def createUsersWithArrayInput(self, body, **kwargs):
"""Creates list of users with given input array
Args:
body, list[User]: List of user object (required)
Returns:
"""
allParams = ['body']
params = locals()
for (key, val) in params['kwargs'].items():
if key not in allParams:
raise TypeError("Got an unexpected keyword argument '%s' to method createUsersWithArrayInput" % key)
params[key] = val
del params['kwargs']
resourcePath = '/user/createWithArray'
resourcePath = resourcePath.replace('{format}', 'json')
method = 'POST'
@ -97,7 +97,7 @@ class UserApi(object):
"""Creates list of users with given list input
Args:
body, List[User]: List of user object (required)
body, list[User]: List of user object (required)
Returns:
"""
@ -111,7 +111,7 @@ class UserApi(object):
params[key] = val
del params['kwargs']
resourcePath = '/user.{format}/createWithList'
resourcePath = '/user/createWithList'
resourcePath = resourcePath.replace('{format}', 'json')
method = 'POST'
@ -144,7 +144,7 @@ class UserApi(object):
params[key] = val
del params['kwargs']
resourcePath = '/user.{format}/{username}'
resourcePath = '/user/{username}'
resourcePath = resourcePath.replace('{format}', 'json')
method = 'PUT'
@ -180,7 +180,7 @@ class UserApi(object):
params[key] = val
del params['kwargs']
resourcePath = '/user.{format}/{username}'
resourcePath = '/user/{username}'
resourcePath = resourcePath.replace('{format}', 'json')
method = 'DELETE'
@ -216,7 +216,7 @@ class UserApi(object):
params[key] = val
del params['kwargs']
resourcePath = '/user.{format}/{username}'
resourcePath = '/user/{username}'
resourcePath = resourcePath.replace('{format}', 'json')
method = 'GET'
@ -258,7 +258,7 @@ class UserApi(object):
params[key] = val
del params['kwargs']
resourcePath = '/user.{format}/login'
resourcePath = '/user/login'
resourcePath = resourcePath.replace('{format}', 'json')
method = 'GET'
@ -298,7 +298,7 @@ class UserApi(object):
params[key] = val
del params['kwargs']
resourcePath = '/user.{format}/logout'
resourcePath = '/user/logout'
resourcePath = resourcePath.replace('{format}', 'json')
method = 'GET'

View File

@ -27,6 +27,8 @@ class Category:
}
#Category unique identifier
self.id = None # int
#Name of the category
self.name = None # str

View File

@ -23,17 +23,21 @@ class Order:
self.swaggerTypes = {
'id': 'int',
'petId': 'int',
'status': 'str',
'quantity': 'int',
'status': 'str',
'shipDate': 'datetime'
}
#Unique identifier for the order
self.id = None # int
#ID of pet being ordered
self.petId = None # int
#Order Status
self.status = None # str
#Number of pets ordered
self.quantity = None # int
#Status of the order
self.status = None # str
#Date shipped, only if it has been
self.shipDate = None # datetime

View File

@ -21,21 +21,26 @@ class Pet:
def __init__(self):
self.swaggerTypes = {
'tags': 'list[Tag]',
'id': 'int',
'category': 'Category',
'status': 'str',
'name': 'str',
'photoUrls': 'list[str]'
'photoUrls': 'list[str]',
'tags': 'list[Tag]',
'status': 'str'
}
self.tags = None # list[Tag]
#Unique identifier for the Pet
self.id = None # int
#Category the pet is in
self.category = None # Category
#Friendly name of the pet
self.name = None # str
#Image URLs
self.photoUrls = None # list[str]
#Tags assigned to this pet
self.tags = None # list[Tag]
#pet status in the store
self.status = None # str
self.name = None # str
self.photoUrls = None # list[str]

View File

@ -27,6 +27,8 @@ class Tag:
}
#Unique identifier for the tag
self.id = None # int
#Friendly name for the tag
self.name = None # str

View File

@ -22,24 +22,31 @@ class User:
def __init__(self):
self.swaggerTypes = {
'id': 'int',
'lastName': 'str',
'phone': 'str',
'username': 'str',
'email': 'str',
'userStatus': 'int',
'firstName': 'str',
'password': 'str'
'lastName': 'str',
'email': 'str',
'password': 'str',
'phone': 'str',
'userStatus': 'int'
}
#Unique identifier for the user
self.id = None # int
self.lastName = None # str
self.phone = None # str
#Unique username
self.username = None # str
#First name of the user
self.firstName = None # str
#Last name of the user
self.lastName = None # str
#Email address of the user
self.email = None # str
#Password name of the user
self.password = None # str
#Phone number of the user
self.phone = None # str
#User Status
self.userStatus = None # int
self.firstName = None # str
self.password = None # str

View File

@ -35,7 +35,7 @@ class ApiClient:
for param, value in headerParams.items():
headers[param] = value
headers['Content-type'] = 'application/json'
#headers['Content-type'] = 'application/json'
headers['api_key'] = self.apiKey
if self.cookie:
@ -43,15 +43,19 @@ class ApiClient:
data = None
if method == 'GET':
if queryParams:
# Need to remove None values, these should not be sent
sentQueryParams = {}
for param, value in queryParams.items():
if value != None:
sentQueryParams[param] = value
url = url + '?' + urllib.parse.urlencode(sentQueryParams)
if queryParams:
# Need to remove None values, these should not be sent
sentQueryParams = {}
for param, value in queryParams.items():
if value != None:
sentQueryParams[param] = value
url = url + '?' + urllib.parse.urlencode(sentQueryParams)
if method in ['GET']:
#Options to add statements later on and for compatibility
pass
elif method in ['POST', 'PUT', 'DELETE']:
@ -84,21 +88,21 @@ class ApiClient:
return data
def toPathValue(self, obj):
"""Serialize a list to a CSV string, if necessary.
"""Convert a string or object to a path-friendly value
Args:
obj -- data object to be serialized
obj -- object or string value
Returns:
string -- json serialization of object
string -- quoted value
"""
if type(obj) == list:
return ','.join(obj)
return urllib.parse.quote(','.join(obj))
else:
return obj
return urllib.parse.quote(str(obj))
def sanitizeForSerialization(self, obj):
"""Dump an object into JSON for POSTing."""
if not obj:
if type(obj) == type(None):
return None
elif type(obj) in [str, int, float, bool]:
return obj
@ -133,12 +137,12 @@ class ApiClient:
subClass = match.group(1)
return [self.deserialize(subObj, subClass) for subObj in obj]
if (objClass in ['int', 'float', 'dict', 'list', 'str']):
if (objClass in ['int', 'float', 'dict', 'list', 'str', 'bool', 'datetime']):
objClass = eval(objClass)
else: # not a native type, must be model class
objClass = eval(objClass + '.' + objClass)
if objClass in [str, int, float, bool]:
if objClass in [int, float, dict, list, str, bool]:
return objClass(obj)
elif objClass == datetime:
# Server will always return a time stamp in UTC, but with
@ -159,7 +163,12 @@ class ApiClient:
value = attrType(value)
except UnicodeEncodeError:
value = unicode(value)
except TypeError:
value = value
setattr(instance, attr, value)
elif (attrType == 'datetime'):
setattr(instance, attr, datetime.datetime.strptime(value[:-5],
"%Y-%m-%dT%H:%M:%S.%f"))
elif 'list[' in attrType:
match = re.match('list\[(.*)\]', attrType)
subClass = match.group(1)

View File

@ -239,3 +239,4 @@ class APIClient {
?>

View File

@ -36,7 +36,7 @@ class ApiClient:
for param, value in headerParams.iteritems():
headers[param] = value
headers['Content-type'] = 'application/json'
#headers['Content-type'] = 'application/json'
headers['api_key'] = self.apiKey
if self.cookie:
@ -44,15 +44,18 @@ class ApiClient:
data = None
if method == 'GET':
if queryParams:
# Need to remove None values, these should not be sent
sentQueryParams = {}
for param, value in queryParams.items():
if value != None:
sentQueryParams[param] = value
url = url + '?' + urllib.urlencode(sentQueryParams)
if queryParams:
# Need to remove None values, these should not be sent
sentQueryParams = {}
for param, value in queryParams.items():
if value != None:
sentQueryParams[param] = value
url = url + '?' + urllib.urlencode(sentQueryParams)
if method in ['GET']:
#Options to add statements later on and for compatibility
pass
elif method in ['POST', 'PUT', 'DELETE']:
@ -95,7 +98,7 @@ class ApiClient:
def sanitizeForSerialization(self, obj):
"""Dump an object into JSON for POSTing."""
if not obj:
if type(obj) == type(None):
return None
elif type(obj) in [str, int, long, float, bool]:
return obj
@ -156,7 +159,7 @@ class ApiClient:
instance = objClass()
for attr, attrType in instance.swaggerTypes.iteritems():
if attr in obj:
if obj is not None and attr in obj and type(obj) in [list, dict]:
value = obj[attr]
if attrType in ['str', 'int', 'long', 'float', 'bool']:
attrType = eval(attrType)
@ -164,6 +167,8 @@ class ApiClient:
value = attrType(value)
except UnicodeEncodeError:
value = unicode(value)
except TypeError:
value = value
setattr(instance, attr, value)
elif (attrType == 'datetime'):
setattr(instance, attr, datetime.datetime.strptime(value[:-5],

View File

@ -35,7 +35,7 @@ class ApiClient:
for param, value in headerParams.items():
headers[param] = value
headers['Content-type'] = 'application/json'
#headers['Content-type'] = 'application/json'
headers['api_key'] = self.apiKey
if self.cookie:
@ -43,15 +43,19 @@ class ApiClient:
data = None
if method == 'GET':
if queryParams:
# Need to remove None values, these should not be sent
sentQueryParams = {}
for param, value in queryParams.items():
if value != None:
sentQueryParams[param] = value
url = url + '?' + urllib.parse.urlencode(sentQueryParams)
if queryParams:
# Need to remove None values, these should not be sent
sentQueryParams = {}
for param, value in queryParams.items():
if value != None:
sentQueryParams[param] = value
url = url + '?' + urllib.parse.urlencode(sentQueryParams)
if method in ['GET']:
#Options to add statements later on and for compatibility
pass
elif method in ['POST', 'PUT', 'DELETE']:
@ -98,7 +102,7 @@ class ApiClient:
def sanitizeForSerialization(self, obj):
"""Dump an object into JSON for POSTing."""
if not obj:
if type(obj) == type(None):
return None
elif type(obj) in [str, int, float, bool]:
return obj
@ -159,6 +163,8 @@ class ApiClient:
value = attrType(value)
except UnicodeEncodeError:
value = unicode(value)
except TypeError:
value = value
setattr(instance, attr, value)
elif (attrType == 'datetime'):
setattr(instance, attr, datetime.datetime.strptime(value[:-5],

View File

@ -1,8 +1,8 @@
package com.wordnik.client.api
import com.wordnik.client.model.User
import com.wordnik.client.model.WordList
import com.wordnik.client.model.ApiTokenStatus
import com.wordnik.client.model.WordList
import com.wordnik.client.model.User
import com.wordnik.client.model.AuthenticationToken
import com.wordnik.client.common.ApiInvoker
import com.wordnik.client.common.ApiException

View File

@ -1,16 +1,16 @@
package com.wordnik.client.api
import com.wordnik.client.model.FrequencySummary
import com.wordnik.client.model.Bigram
import com.wordnik.client.model.WordObject
import com.wordnik.client.model.ExampleSearchResults
import com.wordnik.client.model.Example
import com.wordnik.client.model.Definition
import com.wordnik.client.model.ScrabbleScoreResult
import com.wordnik.client.model.TextPron
import com.wordnik.client.model.Example
import com.wordnik.client.model.Syllable
import com.wordnik.client.model.Related
import com.wordnik.client.model.Definition
import com.wordnik.client.model.AudioFile
import com.wordnik.client.model.ExampleSearchResults
import com.wordnik.client.model.WordObject
import com.wordnik.client.model.Bigram
import com.wordnik.client.model.Related
import com.wordnik.client.model.FrequencySummary
import com.wordnik.client.common.ApiInvoker
import com.wordnik.client.common.ApiException

View File

@ -1,8 +1,8 @@
package com.wordnik.client.api
import com.wordnik.client.model.WordListWord
import com.wordnik.client.model.WordList
import com.wordnik.client.model.StringValue
import com.wordnik.client.model.WordListWord
import com.wordnik.client.common.ApiInvoker
import com.wordnik.client.common.ApiException

View File

@ -1,7 +1,7 @@
package com.wordnik.client.api
import com.wordnik.client.model.DefinitionSearchResults
import com.wordnik.client.model.WordObject
import com.wordnik.client.model.DefinitionSearchResults
import com.wordnik.client.model.WordOfTheDay
import com.wordnik.client.model.WordSearchResults
import com.wordnik.client.common.ApiInvoker

View File

@ -1,11 +1,11 @@
package com.wordnik.client.model
import com.wordnik.client.model.Label
import com.wordnik.client.model.ExampleUsage
import com.wordnik.client.model.TextPron
import com.wordnik.client.model.Citation
import com.wordnik.client.model.Related
import com.wordnik.client.model.Note
import com.wordnik.client.model.Citation
import com.wordnik.client.model.TextPron
import com.wordnik.client.model.Label
import com.wordnik.client.model.Related
case class Definition (
extendedText: String,
text: String,

View File

@ -1,8 +1,8 @@
package com.wordnik.client.model
import com.wordnik.client.model.Sentence
import com.wordnik.client.model.ContentProvider
import com.wordnik.client.model.ScoredWord
import com.wordnik.client.model.ContentProvider
case class Example (
id: Long,
exampleId: Long,

View File

@ -1,8 +1,8 @@
package com.wordnik.client.model
import java.util.Date
import com.wordnik.client.model.SimpleExample
import com.wordnik.client.model.SimpleDefinition
import com.wordnik.client.model.SimpleExample
import com.wordnik.client.model.ContentProvider
case class WordOfTheDay (
id: Long,