mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-07 19:08:52 +00:00
add model attribute name json key mapping in python clent
This commit is contained in:
parent
fe82d7dc05
commit
07237f8eb9
@ -17,12 +17,17 @@ Copyright 2015 Reverb Technologies, Inc.
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
|
||||
class {{classname}}:
|
||||
class {{classname}}(object):
|
||||
"""NOTE: This class is auto generated by the swagger code generator program.
|
||||
Do not edit the class manually."""
|
||||
|
||||
|
||||
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 = {
|
||||
{{#vars}}
|
||||
'{{name}}': '{{{datatype}}}'{{#hasMore}},
|
||||
@ -30,6 +35,11 @@ class {{classname}}:
|
||||
{{/vars}}{{newline}}
|
||||
}
|
||||
|
||||
self.attributeMap = {
|
||||
{{#vars}}
|
||||
'{{name}}': '{{baseName}}'{{#hasMore}},{{/hasMore}}
|
||||
{{/vars}}
|
||||
}
|
||||
|
||||
{{#vars}}
|
||||
{{#description}}#{{description}}
|
||||
|
@ -131,10 +131,14 @@ class ApiClient(object):
|
||||
if isinstance(obj, dict):
|
||||
objDict = obj
|
||||
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)
|
||||
for (key, val) in objDict.iteritems()
|
||||
if key != 'swaggerTypes'}
|
||||
for (key, val) in objDict.iteritems()}
|
||||
|
||||
def buildMultipartFormData(self, postData, files):
|
||||
def escape_quotes(s):
|
||||
@ -199,8 +203,8 @@ class ApiClient(object):
|
||||
instance = objClass()
|
||||
|
||||
for attr, attrType in instance.swaggerTypes.iteritems():
|
||||
if obj is not None and attr in obj and type(obj) in [list, dict]:
|
||||
value = obj[attr]
|
||||
if obj is not None and instance.attributeMap[attr] in obj and type(obj) in [list, dict]:
|
||||
value = obj[instance.attributeMap[attr]]
|
||||
if attrType in ['str', 'int', 'long', 'float', 'bool']:
|
||||
attrType = eval(attrType)
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user