forked from loafle/openapi-generator-original
Change reserved word handling in python client.
* First, remove the beginning underscores. * Then, append underscore if the var is reserved word or number.
This commit is contained in:
@@ -202,11 +202,9 @@ class ApiClient(object):
|
||||
# and attributes which value is not None.
|
||||
# Convert attribute name to json key in
|
||||
# model definition for request.
|
||||
obj_dict = {obj.attribute_map[key[1:]]: val
|
||||
for key, val in iteritems(obj.__dict__)
|
||||
if key != 'swagger_types'
|
||||
and key != 'attribute_map'
|
||||
and val is not None}
|
||||
obj_dict = {obj.attribute_map[attr]: getattr(obj, attr)
|
||||
for attr, _ in iteritems(obj.swagger_types)
|
||||
if getattr(obj, attr) is not None}
|
||||
|
||||
return {key: self.sanitize_for_serialization(val)
|
||||
for key, val in iteritems(obj_dict)}
|
||||
|
||||
@@ -23,9 +23,9 @@ import urllib3
|
||||
try:
|
||||
import httplib
|
||||
except ImportError:
|
||||
# python3
|
||||
# for python3
|
||||
import http.client as httplib
|
||||
|
||||
|
||||
import sys
|
||||
import logging
|
||||
|
||||
|
||||
@@ -86,18 +86,17 @@ class {{classname}}(object):
|
||||
"""
|
||||
result = {}
|
||||
|
||||
for name, prop in iteritems(self.__dict__):
|
||||
if name == "attribute_map" or name == "swagger_types":
|
||||
continue
|
||||
if isinstance(prop, list):
|
||||
result[name[1:]] = list(map(
|
||||
for attr, _ in iteritems(self.swagger_types):
|
||||
value = getattr(self, attr)
|
||||
if isinstance(value, list):
|
||||
result[attr] = list(map(
|
||||
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
|
||||
prop
|
||||
value
|
||||
))
|
||||
elif hasattr(prop, "to_dict"):
|
||||
result[name[1:]] = prop.to_dict()
|
||||
elif hasattr(value, "to_dict"):
|
||||
result[attr] = value.to_dict()
|
||||
else:
|
||||
result[name[1:]] = prop
|
||||
result[attr] = value
|
||||
|
||||
return result
|
||||
|
||||
|
||||
Reference in New Issue
Block a user