mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-04 14:40:53 +00:00
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:
parent
34e5838924
commit
6e72018a64
@ -41,7 +41,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
// clear import mapping (from default generator) as python does not use it
|
// clear import mapping (from default generator) as python does not use it
|
||||||
// at the moment
|
// at the moment
|
||||||
importMapping.clear();
|
importMapping.clear();
|
||||||
|
|
||||||
supportsInheritance = true;
|
supportsInheritance = true;
|
||||||
modelPackage = "models";
|
modelPackage = "models";
|
||||||
apiPackage = "api";
|
apiPackage = "api";
|
||||||
|
@ -593,17 +593,23 @@ class ApiClient(object):
|
|||||||
:param klass: class literal.
|
:param klass: class literal.
|
||||||
:return: model object.
|
:return: model object.
|
||||||
"""
|
"""
|
||||||
if not klass.swagger_types:
|
|
||||||
|
if not klass.swagger_types and not hasattr(klass, 'get_real_child_model'):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
for attr, attr_type in iteritems(klass.swagger_types):
|
if klass.swagger_types is not None:
|
||||||
if data is not None \
|
for attr, attr_type in iteritems(klass.swagger_types):
|
||||||
and klass.attribute_map[attr] in data \
|
if data is not None \
|
||||||
and isinstance(data, (list, dict)):
|
and klass.attribute_map[attr] in data \
|
||||||
value = data[klass.attribute_map[attr]]
|
and isinstance(data, (list, dict)):
|
||||||
kwargs[attr] = self.__deserialize(value, attr_type)
|
value = data[klass.attribute_map[attr]]
|
||||||
|
kwargs[attr] = self.__deserialize(value, attr_type)
|
||||||
|
|
||||||
instance = klass(**kwargs)
|
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
|
return instance
|
||||||
|
Loading…
x
Reference in New Issue
Block a user