forked from loafle/openapi-generator-original
[CORE] Fixes composed schema discriminator map (#4906)
* Adds addComposedMappedModels and testComposedSchemaOneOfDiscriminatorMap * Requires that discriminators be required properties * Strengthens discriminaotr validation, adds better error messages, adds schema oneof samples * Adds oneOf and anyOf invalidDiscriminator tests * Updates incorrect addOneOfInterfaceModel invocation * Runs ensure-up-to-date * Adds updates from Sebastien Rosset * Removes newlines * Uses df.isString * Fixes tests be correctly setting df.isString * Updates discriminatorExplicitMappingVerbose description per PR feedback * Adds description of how mappedModels is populated * Adds the suggestion exception raising when a MappedModel mappingName is null * Actually resolves merge conflicts * Switches two methods to package private because they are needed for testing * Allow nulls in MappedModel.getMappingName * Updates CLI flag name to legacyDiscriminatorBehavior, default=true Co-authored-by: William Cheng <wing328hk@gmail.com>
This commit is contained in:
@@ -625,9 +625,12 @@ class ApiClient(object):
|
||||
:param klass: class literal.
|
||||
:return: model object.
|
||||
"""
|
||||
has_discriminator = False
|
||||
if (hasattr(klass, 'get_real_child_model')
|
||||
and klass.discriminator_value_class_map):
|
||||
has_discriminator = True
|
||||
|
||||
if not klass.openapi_types and not hasattr(klass,
|
||||
'get_real_child_model'):
|
||||
if not klass.openapi_types and has_discriminator is False:
|
||||
return data
|
||||
|
||||
kwargs = {}
|
||||
@@ -641,7 +644,7 @@ class ApiClient(object):
|
||||
|
||||
instance = klass(**kwargs)
|
||||
|
||||
if hasattr(instance, 'get_real_child_model'):
|
||||
if has_discriminator:
|
||||
klass_name = instance.get_real_child_model(data)
|
||||
if klass_name:
|
||||
instance = self.__deserialize(data, klass_name)
|
||||
|
||||
Reference in New Issue
Block a user