From f18244e12bb2c950e00075041cabd7063c86a3c8 Mon Sep 17 00:00:00 2001 From: Hugo Mercado Date: Tue, 5 Sep 2023 08:15:42 -0500 Subject: [PATCH] set discriminator property name for all schemas --- .../v3/generators/DefaultCodegenConfig.java | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java b/src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java index a3d62e5f9e..d3e5af8315 100644 --- a/src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java +++ b/src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java @@ -1344,6 +1344,9 @@ public CodegenModel fromModel(String name, Schema schema, Map al codegenModel.getVendorExtensions().put(CodegenConstants.IS_ALIAS_EXT_NAME, typeAliases.containsKey(name)); codegenModel.discriminator = schema.getDiscriminator(); + if (codegenModel.discriminator != null && codegenModel.discriminator.getPropertyName() != null) { + codegenModel.discriminator.setPropertyName(toVarName(codegenModel.discriminator.getPropertyName())); + } if (schema.getXml() != null) { codegenModel.xmlPrefix = schema.getXml().getPrefix(); @@ -1404,11 +1407,6 @@ else if (schema instanceof ComposedSchema) { final List allOf = composed.getAllOf(); // interfaces (intermediate models) if (allOf != null && !allOf.isEmpty()) { - - if (codegenModel.discriminator != null && codegenModel.discriminator.getPropertyName() != null) { - codegenModel.discriminator.setPropertyName(toVarName(codegenModel.discriminator.getPropertyName())); - } - for (int i = 0; i < allOf.size(); i++) { if (i == 0 && !copyFistAllOfProperties) { continue; @@ -1435,16 +1433,6 @@ else if (schema instanceof ComposedSchema) { } } - final List oneOf = composed.getOneOf(); - if (oneOf != null && !oneOf.isEmpty()) { - if (schema.getDiscriminator() != null) { - codegenModel.discriminator = schema.getDiscriminator(); - if (codegenModel.discriminator != null && codegenModel.discriminator.getPropertyName() != null) { - codegenModel.discriminator.setPropertyName(toVarName(codegenModel.discriminator.getPropertyName())); - } - } - } - if (parent != null) { codegenModel.parentSchema = parentName; codegenModel.parent = typeMapping.containsKey(parentName) ? typeMapping.get(parentName): toModelName(parentName);