forked from loafle/openapi-generator-original
Merge pull request #600 from wing328/python_variable_naming
Fixed parameter name, better naming convention for python client
This commit is contained in:
commit
555ef7677d
@ -114,4 +114,71 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
// TODO: Support Python def value
|
// TODO: Support Python def value
|
||||||
return "null";
|
return "null";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toVarName(String name) {
|
||||||
|
// replace - with _ e.g. created-at => created_at
|
||||||
|
name = name.replaceAll("-", "_");
|
||||||
|
|
||||||
|
// if it's all uppper case, convert to lower case
|
||||||
|
if (name.matches("^[A-Z_]*$"))
|
||||||
|
name = name.toLowerCase();
|
||||||
|
|
||||||
|
// camelize (lower first character) the variable name
|
||||||
|
// petId => pet_id
|
||||||
|
name = underscore(name);
|
||||||
|
|
||||||
|
// for reserved word or word starting with number, append _
|
||||||
|
if(reservedWords.contains(name) || name.matches("^\\d.*"))
|
||||||
|
name = escapeReservedWord(name);
|
||||||
|
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toParamName(String name) {
|
||||||
|
// should be the same as variable name
|
||||||
|
return toVarName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toModelName(String name) {
|
||||||
|
// model name cannot use reserved keyword, e.g. return
|
||||||
|
if(reservedWords.contains(name))
|
||||||
|
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||||
|
|
||||||
|
// camelize the model name
|
||||||
|
// phone_number => PhoneNumber
|
||||||
|
return camelize(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toModelFilename(String name) {
|
||||||
|
// model name cannot use reserved keyword, e.g. return
|
||||||
|
if(reservedWords.contains(name))
|
||||||
|
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||||
|
|
||||||
|
// underscore the model file name
|
||||||
|
// PhoneNumber.rb => phone_number.rb
|
||||||
|
return underscore(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toApiFilename(String name) {
|
||||||
|
// replace - with _ e.g. created-at => created_at
|
||||||
|
name = name.replaceAll("-", "_");
|
||||||
|
|
||||||
|
// e.g. PhoneNumberApi.rb => phone_number_api.rb
|
||||||
|
return underscore(name) + "_api";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toApiName(String name) {
|
||||||
|
if(name.length() == 0)
|
||||||
|
return "DefaultApi";
|
||||||
|
// e.g. phone_number_api => PhoneNumberApi
|
||||||
|
return camelize(name) + "Api";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -68,12 +68,12 @@ class {{classname}}(object):
|
|||||||
|
|
||||||
{{#queryParams}}
|
{{#queryParams}}
|
||||||
if ('{{paramName}}' in params):
|
if ('{{paramName}}' in params):
|
||||||
queryParams['{{paramName}}'] = self.apiClient.toPathValue(params['{{paramName}}'])
|
queryParams['{{baseName}}'] = self.apiClient.toPathValue(params['{{paramName}}'])
|
||||||
{{/queryParams}}
|
{{/queryParams}}
|
||||||
|
|
||||||
{{#headerParams}}
|
{{#headerParams}}
|
||||||
if ('{{paramName}}' in params):
|
if ('{{paramName}}' in params):
|
||||||
headerParams['{{paramName}}'] = params['{{paramName}}']
|
headerParams['{{baseName}}'] = params['{{paramName}}']
|
||||||
{{/headerParams}}
|
{{/headerParams}}
|
||||||
|
|
||||||
{{#pathParams}}
|
{{#pathParams}}
|
||||||
@ -86,7 +86,7 @@ class {{classname}}(object):
|
|||||||
|
|
||||||
{{#formParams}}
|
{{#formParams}}
|
||||||
if ('{{paramName}}' in params):
|
if ('{{paramName}}' in params):
|
||||||
{{#notFile}}formParams['{{paramName}}'] = params['{{paramName}}']{{/notFile}}{{#isFile}}files['{{paramName}}'] = params['{{paramName}}']{{/isFile}}
|
{{#notFile}}formParams['{{baseName}}'] = params['{{paramName}}']{{/notFile}}{{#isFile}}files['{{baseName}}'] = params['{{paramName}}']{{/isFile}}
|
||||||
{{/formParams}}
|
{{/formParams}}
|
||||||
|
|
||||||
{{#bodyParam}}
|
{{#bodyParam}}
|
||||||
|
@ -31,13 +31,13 @@ class Order(object):
|
|||||||
'id': 'long',
|
'id': 'long',
|
||||||
|
|
||||||
|
|
||||||
'petId': 'long',
|
'pet_id': 'long',
|
||||||
|
|
||||||
|
|
||||||
'quantity': 'int',
|
'quantity': 'int',
|
||||||
|
|
||||||
|
|
||||||
'shipDate': 'DateTime',
|
'ship_date': 'DateTime',
|
||||||
|
|
||||||
|
|
||||||
'status': 'str',
|
'status': 'str',
|
||||||
@ -51,11 +51,11 @@ class Order(object):
|
|||||||
|
|
||||||
'id': 'id',
|
'id': 'id',
|
||||||
|
|
||||||
'petId': 'petId',
|
'pet_id': 'petId',
|
||||||
|
|
||||||
'quantity': 'quantity',
|
'quantity': 'quantity',
|
||||||
|
|
||||||
'shipDate': 'shipDate',
|
'ship_date': 'shipDate',
|
||||||
|
|
||||||
'status': 'status',
|
'status': 'status',
|
||||||
|
|
||||||
@ -68,13 +68,13 @@ class Order(object):
|
|||||||
self.id = None # long
|
self.id = None # long
|
||||||
|
|
||||||
|
|
||||||
self.petId = None # long
|
self.pet_id = None # long
|
||||||
|
|
||||||
|
|
||||||
self.quantity = None # int
|
self.quantity = None # int
|
||||||
|
|
||||||
|
|
||||||
self.shipDate = None # DateTime
|
self.ship_date = None # DateTime
|
||||||
|
|
||||||
#Order Status
|
#Order Status
|
||||||
|
|
@ -37,7 +37,7 @@ class Pet(object):
|
|||||||
'name': 'str',
|
'name': 'str',
|
||||||
|
|
||||||
|
|
||||||
'photoUrls': 'list[str]',
|
'photo_urls': 'list[str]',
|
||||||
|
|
||||||
|
|
||||||
'tags': 'list[Tag]',
|
'tags': 'list[Tag]',
|
||||||
@ -55,7 +55,7 @@ class Pet(object):
|
|||||||
|
|
||||||
'name': 'name',
|
'name': 'name',
|
||||||
|
|
||||||
'photoUrls': 'photoUrls',
|
'photo_urls': 'photoUrls',
|
||||||
|
|
||||||
'tags': 'tags',
|
'tags': 'tags',
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ class Pet(object):
|
|||||||
self.name = None # str
|
self.name = None # str
|
||||||
|
|
||||||
|
|
||||||
self.photoUrls = None # list[str]
|
self.photo_urls = None # list[str]
|
||||||
|
|
||||||
|
|
||||||
self.tags = None # list[Tag]
|
self.tags = None # list[Tag]
|
@ -34,10 +34,10 @@ class User(object):
|
|||||||
'username': 'str',
|
'username': 'str',
|
||||||
|
|
||||||
|
|
||||||
'firstName': 'str',
|
'first_name': 'str',
|
||||||
|
|
||||||
|
|
||||||
'lastName': 'str',
|
'last_name': 'str',
|
||||||
|
|
||||||
|
|
||||||
'email': 'str',
|
'email': 'str',
|
||||||
@ -49,7 +49,7 @@ class User(object):
|
|||||||
'phone': 'str',
|
'phone': 'str',
|
||||||
|
|
||||||
|
|
||||||
'userStatus': 'int'
|
'user_status': 'int'
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,9 +59,9 @@ class User(object):
|
|||||||
|
|
||||||
'username': 'username',
|
'username': 'username',
|
||||||
|
|
||||||
'firstName': 'firstName',
|
'first_name': 'firstName',
|
||||||
|
|
||||||
'lastName': 'lastName',
|
'last_name': 'lastName',
|
||||||
|
|
||||||
'email': 'email',
|
'email': 'email',
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ class User(object):
|
|||||||
|
|
||||||
'phone': 'phone',
|
'phone': 'phone',
|
||||||
|
|
||||||
'userStatus': 'userStatus'
|
'user_status': 'userStatus'
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,10 +81,10 @@ class User(object):
|
|||||||
self.username = None # str
|
self.username = None # str
|
||||||
|
|
||||||
|
|
||||||
self.firstName = None # str
|
self.first_name = None # str
|
||||||
|
|
||||||
|
|
||||||
self.lastName = None # str
|
self.last_name = None # str
|
||||||
|
|
||||||
|
|
||||||
self.email = None # str
|
self.email = None # str
|
||||||
@ -97,5 +97,5 @@ class User(object):
|
|||||||
|
|
||||||
#User Status
|
#User Status
|
||||||
|
|
||||||
self.userStatus = None # int
|
self.user_status = None # int
|
||||||
|
|
@ -272,14 +272,14 @@ class PetApi(object):
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|
||||||
petId, long: ID of pet that needs to be fetched (required)
|
pet_id, long: ID of pet that needs to be fetched (required)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Returns: Pet
|
Returns: Pet
|
||||||
"""
|
"""
|
||||||
|
|
||||||
allParams = ['petId']
|
allParams = ['pet_id']
|
||||||
|
|
||||||
params = locals()
|
params = locals()
|
||||||
for (key, val) in params['kwargs'].iteritems():
|
for (key, val) in params['kwargs'].iteritems():
|
||||||
@ -306,8 +306,8 @@ class PetApi(object):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ('petId' in params):
|
if ('pet_id' in params):
|
||||||
replacement = str(self.apiClient.toPathValue(params['petId']))
|
replacement = str(self.apiClient.toPathValue(params['pet_id']))
|
||||||
replacement = urllib.quote(replacement)
|
replacement = urllib.quote(replacement)
|
||||||
resourcePath = resourcePath.replace('{' + 'petId' + '}',
|
resourcePath = resourcePath.replace('{' + 'petId' + '}',
|
||||||
replacement)
|
replacement)
|
||||||
@ -337,7 +337,7 @@ class PetApi(object):
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|
||||||
petId, str: ID of pet that needs to be updated (required)
|
pet_id, str: ID of pet that needs to be updated (required)
|
||||||
|
|
||||||
|
|
||||||
name, str: Updated name of the pet (required)
|
name, str: Updated name of the pet (required)
|
||||||
@ -350,7 +350,7 @@ class PetApi(object):
|
|||||||
Returns:
|
Returns:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
allParams = ['petId', 'name', 'status']
|
allParams = ['pet_id', 'name', 'status']
|
||||||
|
|
||||||
params = locals()
|
params = locals()
|
||||||
for (key, val) in params['kwargs'].iteritems():
|
for (key, val) in params['kwargs'].iteritems():
|
||||||
@ -377,8 +377,8 @@ class PetApi(object):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ('petId' in params):
|
if ('pet_id' in params):
|
||||||
replacement = str(self.apiClient.toPathValue(params['petId']))
|
replacement = str(self.apiClient.toPathValue(params['pet_id']))
|
||||||
replacement = urllib.quote(replacement)
|
replacement = urllib.quote(replacement)
|
||||||
resourcePath = resourcePath.replace('{' + 'petId' + '}',
|
resourcePath = resourcePath.replace('{' + 'petId' + '}',
|
||||||
replacement)
|
replacement)
|
||||||
@ -411,14 +411,14 @@ class PetApi(object):
|
|||||||
api_key, str: (required)
|
api_key, str: (required)
|
||||||
|
|
||||||
|
|
||||||
petId, long: Pet id to delete (required)
|
pet_id, long: Pet id to delete (required)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
allParams = ['api_key', 'petId']
|
allParams = ['api_key', 'pet_id']
|
||||||
|
|
||||||
params = locals()
|
params = locals()
|
||||||
for (key, val) in params['kwargs'].iteritems():
|
for (key, val) in params['kwargs'].iteritems():
|
||||||
@ -448,8 +448,8 @@ class PetApi(object):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ('petId' in params):
|
if ('pet_id' in params):
|
||||||
replacement = str(self.apiClient.toPathValue(params['petId']))
|
replacement = str(self.apiClient.toPathValue(params['pet_id']))
|
||||||
replacement = urllib.quote(replacement)
|
replacement = urllib.quote(replacement)
|
||||||
resourcePath = resourcePath.replace('{' + 'petId' + '}',
|
resourcePath = resourcePath.replace('{' + 'petId' + '}',
|
||||||
replacement)
|
replacement)
|
||||||
@ -473,10 +473,10 @@ class PetApi(object):
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|
||||||
petId, long: ID of pet to update (required)
|
pet_id, long: ID of pet to update (required)
|
||||||
|
|
||||||
|
|
||||||
additionalMetadata, str: Additional data to pass to server (required)
|
additional_metadata, str: Additional data to pass to server (required)
|
||||||
|
|
||||||
|
|
||||||
file, file: file to upload (required)
|
file, file: file to upload (required)
|
||||||
@ -486,7 +486,7 @@ class PetApi(object):
|
|||||||
Returns:
|
Returns:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
allParams = ['petId', 'additionalMetadata', 'file']
|
allParams = ['pet_id', 'additional_metadata', 'file']
|
||||||
|
|
||||||
params = locals()
|
params = locals()
|
||||||
for (key, val) in params['kwargs'].iteritems():
|
for (key, val) in params['kwargs'].iteritems():
|
||||||
@ -513,16 +513,16 @@ class PetApi(object):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ('petId' in params):
|
if ('pet_id' in params):
|
||||||
replacement = str(self.apiClient.toPathValue(params['petId']))
|
replacement = str(self.apiClient.toPathValue(params['pet_id']))
|
||||||
replacement = urllib.quote(replacement)
|
replacement = urllib.quote(replacement)
|
||||||
resourcePath = resourcePath.replace('{' + 'petId' + '}',
|
resourcePath = resourcePath.replace('{' + 'petId' + '}',
|
||||||
replacement)
|
replacement)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ('additionalMetadata' in params):
|
if ('additional_metadata' in params):
|
||||||
formParams['additionalMetadata'] = params['additionalMetadata']
|
formParams['additionalMetadata'] = params['additional_metadata']
|
||||||
|
|
||||||
if ('file' in params):
|
if ('file' in params):
|
||||||
files['file'] = params['file']
|
files['file'] = params['file']
|
@ -154,14 +154,14 @@ class StoreApi(object):
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|
||||||
orderId, str: ID of pet that needs to be fetched (required)
|
order_id, str: ID of pet that needs to be fetched (required)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Returns: Order
|
Returns: Order
|
||||||
"""
|
"""
|
||||||
|
|
||||||
allParams = ['orderId']
|
allParams = ['order_id']
|
||||||
|
|
||||||
params = locals()
|
params = locals()
|
||||||
for (key, val) in params['kwargs'].iteritems():
|
for (key, val) in params['kwargs'].iteritems():
|
||||||
@ -188,8 +188,8 @@ class StoreApi(object):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ('orderId' in params):
|
if ('order_id' in params):
|
||||||
replacement = str(self.apiClient.toPathValue(params['orderId']))
|
replacement = str(self.apiClient.toPathValue(params['order_id']))
|
||||||
replacement = urllib.quote(replacement)
|
replacement = urllib.quote(replacement)
|
||||||
resourcePath = resourcePath.replace('{' + 'orderId' + '}',
|
resourcePath = resourcePath.replace('{' + 'orderId' + '}',
|
||||||
replacement)
|
replacement)
|
||||||
@ -219,14 +219,14 @@ class StoreApi(object):
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|
||||||
orderId, str: ID of the order that needs to be deleted (required)
|
order_id, str: ID of the order that needs to be deleted (required)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
allParams = ['orderId']
|
allParams = ['order_id']
|
||||||
|
|
||||||
params = locals()
|
params = locals()
|
||||||
for (key, val) in params['kwargs'].iteritems():
|
for (key, val) in params['kwargs'].iteritems():
|
||||||
@ -253,8 +253,8 @@ class StoreApi(object):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ('orderId' in params):
|
if ('order_id' in params):
|
||||||
replacement = str(self.apiClient.toPathValue(params['orderId']))
|
replacement = str(self.apiClient.toPathValue(params['order_id']))
|
||||||
replacement = urllib.quote(replacement)
|
replacement = urllib.quote(replacement)
|
||||||
resourcePath = resourcePath.replace('{' + 'orderId' + '}',
|
resourcePath = resourcePath.replace('{' + 'orderId' + '}',
|
||||||
replacement)
|
replacement)
|
Loading…
x
Reference in New Issue
Block a user