Add polymorphism support for python (#6208)

* Add polymorphism support for python

* Update api_client

* Remove leading spaces

* Bugfix

* Catch case where swagger_types is none but get_real_child_model is defined
This commit is contained in:
Jeff 2017-08-02 02:15:26 -07:00 committed by wing328
parent 34e5838924
commit 6e72018a64
2 changed files with 15 additions and 9 deletions

View File

@ -593,10 +593,12 @@ class ApiClient(object):
:param klass: class literal.
:return: model object.
"""
if not klass.swagger_types:
if not klass.swagger_types and not hasattr(klass, 'get_real_child_model'):
return data
kwargs = {}
if klass.swagger_types is not None:
for attr, attr_type in iteritems(klass.swagger_types):
if data is not None \
and klass.attribute_map[attr] in data \
@ -606,4 +608,8 @@ class ApiClient(object):
instance = klass(**kwargs)
if hasattr(instance, 'get_real_child_model'):
klass_name = instance.get_real_child_model(data)
if klass_name:
instance = self.__deserialize(data, klass_name)
return instance