forked from loafle/openapi-generator-original
Merge pull request #544 from geekerzp/develop_2.0_python_key_map
Support attribute key mapping in python client
This commit is contained in:
commit
81e1fd53e2
@ -17,12 +17,17 @@ Copyright 2015 Reverb Technologies, Inc.
|
|||||||
{{#models}}
|
{{#models}}
|
||||||
{{#model}}
|
{{#model}}
|
||||||
|
|
||||||
class {{classname}}:
|
class {{classname}}(object):
|
||||||
"""NOTE: This class is auto generated by the swagger code generator program.
|
"""NOTE: This class is auto generated by the swagger code generator program.
|
||||||
Do not edit the class manually."""
|
Do not edit the class manually."""
|
||||||
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
"""
|
||||||
|
Attributes:
|
||||||
|
swaggerTypes (dict): The key is attribute name and the value is attribute type.
|
||||||
|
attributeMap (dict): The key is attribute name and the value is json key in definition.
|
||||||
|
"""
|
||||||
self.swaggerTypes = {
|
self.swaggerTypes = {
|
||||||
{{#vars}}
|
{{#vars}}
|
||||||
'{{name}}': '{{{datatype}}}'{{#hasMore}},
|
'{{name}}': '{{{datatype}}}'{{#hasMore}},
|
||||||
@ -30,6 +35,11 @@ class {{classname}}:
|
|||||||
{{/vars}}{{newline}}
|
{{/vars}}{{newline}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.attributeMap = {
|
||||||
|
{{#vars}}
|
||||||
|
'{{name}}': '{{baseName}}'{{#hasMore}},{{/hasMore}}
|
||||||
|
{{/vars}}
|
||||||
|
}
|
||||||
|
|
||||||
{{#vars}}
|
{{#vars}}
|
||||||
{{#description}}#{{description}}
|
{{#description}}#{{description}}
|
||||||
|
@ -131,10 +131,14 @@ class ApiClient(object):
|
|||||||
if isinstance(obj, dict):
|
if isinstance(obj, dict):
|
||||||
objDict = obj
|
objDict = obj
|
||||||
else:
|
else:
|
||||||
objDict = obj.__dict__
|
# Convert model obj to dict except attributes `swaggerTypes`, `attributeMap`
|
||||||
|
# and attributes which value is not None.
|
||||||
|
# Convert attribute name to json key in model definition for request.
|
||||||
|
objDict = {obj.attributeMap[key]: val
|
||||||
|
for key, val in obj.__dict__.iteritems()
|
||||||
|
if key != 'swaggerTypes' and key != 'attributeMap' and val is not None}
|
||||||
return {key: ApiClient.sanitizeForSerialization(val)
|
return {key: ApiClient.sanitizeForSerialization(val)
|
||||||
for (key, val) in objDict.iteritems()
|
for (key, val) in objDict.iteritems()}
|
||||||
if key != 'swaggerTypes'}
|
|
||||||
|
|
||||||
def buildMultipartFormData(self, postData, files):
|
def buildMultipartFormData(self, postData, files):
|
||||||
def escape_quotes(s):
|
def escape_quotes(s):
|
||||||
@ -199,8 +203,8 @@ class ApiClient(object):
|
|||||||
instance = objClass()
|
instance = objClass()
|
||||||
|
|
||||||
for attr, attrType in instance.swaggerTypes.iteritems():
|
for attr, attrType in instance.swaggerTypes.iteritems():
|
||||||
if obj is not None and attr in obj and type(obj) in [list, dict]:
|
if obj is not None and instance.attributeMap[attr] in obj and type(obj) in [list, dict]:
|
||||||
value = obj[attr]
|
value = obj[instance.attributeMap[attr]]
|
||||||
if attrType in ['str', 'int', 'long', 'float', 'bool']:
|
if attrType in ['str', 'int', 'long', 'float', 'bool']:
|
||||||
attrType = eval(attrType)
|
attrType = eval(attrType)
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user