From be3c2156a60de5998227673524003a51548ebf89 Mon Sep 17 00:00:00 2001 From: Anass Karbila Date: Tue, 17 Nov 2020 16:26:30 +0100 Subject: [PATCH] AbstractKotlinCodegen: always prefer parent type regardless of whether current model is discriminator --- .../codegen/languages/AbstractKotlinCodegen.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java index 3033dd101d90..741c8389a242 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java @@ -822,8 +822,17 @@ private CodegenModel reconcileProperties(CodegenModel codegenModel, Iterator iterator = codegenProperties.iterator(); while (iterator.hasNext()) { CodegenProperty codegenProperty = iterator.next(); - if (codegenProperty.baseName.equals(parentModelCodegenProperty.baseName) - && parentModelCodegenProperty.isEnum) { + if (codegenProperty.baseName.equals(parentModelCodegenProperty.baseName)) { + // If the current model is a discriminator type, while also being a parent + // the parent property should always be preferred. + // Remove the parent property from the inherited models. + if (codegenModel.discriminator != null) { + iterator.remove(); + codegenModel.allVars.remove(codegenProperty); + codegenModel.parentVars.remove(codegenProperty); + continue; + } + // We found a property in the child class that is // a duplicate of the one in the parent, // so mark it as inherited & copy the data type.