diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java index 84c47521f1d0..fbfe2cf39a77 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java @@ -751,6 +751,37 @@ private void patchPropertyVendorExtensions(CodegenProperty property) { protected void patchPropertyIsInherited(CodegenModel model, CodegenProperty property) { } + private void patchNestedMaps(CodegenProperty property) { + // Process nested types before making any replacements to ensure we have the correct inner type + if (property.items != null) { + patchNestedMaps(property.items); + } + + String[] nestedTypes = {"List", "Collection", "ICollection", "Dictionary"}; + + if (property.datatypeWithEnum != null) { + String originalType = property.datatypeWithEnum; + + for (String nestedType : nestedTypes) { + // fix incorrect data types for maps of maps + if (property.items != null) { + if (property.datatypeWithEnum.contains(", " + nestedType + ">")) { + property.datatypeWithEnum = property.datatypeWithEnum.replace(", " + nestedType + ">", ", " + property.items.datatypeWithEnum + ">"); + } + + if (property.datatypeWithEnum.contains("<" + nestedType + ">")) { + property.datatypeWithEnum = property.datatypeWithEnum.replace("<" + nestedType + ">", "<" + property.items.datatypeWithEnum + ">"); + } + } + } + + // Only update dataType if we actually made changes + if (!originalType.equals(property.datatypeWithEnum)) { + property.dataType = property.datatypeWithEnum; + } + } + } + protected void patchProperty(Map enumRefs, CodegenModel model, CodegenProperty property) { if (enumRefs.containsKey(property.dataType)) { // Handle any enum properties referred to by $ref. @@ -770,20 +801,7 @@ protected void patchProperty(Map enumRefs, CodegenModel mo property.name = patchPropertyName(model, property.name, null); - String[] nestedTypes = {"List", "Collection", "ICollection", "Dictionary"}; - - Arrays.stream(nestedTypes).forEach(nestedType -> { - // fix incorrect data types for maps of maps - if (property.datatypeWithEnum.contains(", " + nestedType + ">") && property.items != null) { - property.datatypeWithEnum = property.datatypeWithEnum.replace(", " + nestedType + ">", ", " + property.items.datatypeWithEnum + ">"); - property.dataType = property.datatypeWithEnum; - } - - if (property.datatypeWithEnum.contains("<" + nestedType + ">") && property.items != null) { - property.datatypeWithEnum = property.datatypeWithEnum.replace("<" + nestedType + ">", "<" + property.items.datatypeWithEnum + ">"); - property.dataType = property.datatypeWithEnum; - } - }); + patchNestedMaps(property); // HOTFIX: https://github.com/OpenAPITools/openapi-generator/issues/14944 if (property.datatypeWithEnum.equals("decimal")) {