diff --git a/modules/swagger-codegen/src/main/resources/python/model.mustache b/modules/swagger-codegen/src/main/resources/python/model.mustache index f6e95c72dc..ff81820ca3 100644 --- a/modules/swagger-codegen/src/main/resources/python/model.mustache +++ b/modules/swagger-codegen/src/main/resources/python/model.mustache @@ -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}} diff --git a/modules/swagger-codegen/src/main/resources/python/swagger.mustache b/modules/swagger-codegen/src/main/resources/python/swagger.mustache index 7864c20186..1cfc60981b 100644 --- a/modules/swagger-codegen/src/main/resources/python/swagger.mustache +++ b/modules/swagger-codegen/src/main/resources/python/swagger.mustache @@ -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: