Skip to content

Commit 70ada0e

Browse files
committed
Merge branch 'devhl/21686-fix-response-datatype' of https://github.com/devhl-labs/openapi-generator into devhl-labs-devhl/21686-fix-response-datatype
2 parents b199901 + 21c9ffd commit 70ada0e

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -753,9 +753,13 @@ private String setUniquePropertyName(CodegenModel model, CodegenProperty propert
753753
return value;
754754
}
755755

756-
/**
757-
* Fixes nested maps so the generic type is defined
758-
* Convertes List<List>> to List<List<T>>
756+
/**
757+
* Ensures property name is unique and not a reserved word.
758+
* @param model
759+
* @param property
760+
* @param value
761+
* @param composedPropertyNames
762+
* @return
759763
*/
760764
private String patchPropertyName(CodegenModel model, CodegenProperty property, String value, Set<String> composedPropertyNames) {
761765
value = setUniquePropertyName(model, property, value);
@@ -794,6 +798,10 @@ private void patchPropertyVendorExtensions(CodegenProperty property) {
794798
protected void patchPropertyIsInherited(CodegenModel model, CodegenProperty property) {
795799
}
796800

801+
/**
802+
* Fixes nested maps so the generic type is defined
803+
* Convertes List<List>> to List<List<T>>
804+
*/
797805
private void patchNestedMaps(CodegenProperty property) {
798806
// Process nested types before making any replacements to ensure we have the correct inner type
799807
if (property.items != null) {
@@ -825,6 +833,41 @@ private void patchNestedMaps(CodegenProperty property) {
825833
}
826834
}
827835

836+
/**
837+
* Fixes nested maps so the generic type is defined
838+
* Convertes List<List>> to List<List<T>>
839+
*/
840+
private void patchNestedMaps(CodegenResponse response) {
841+
// Process nested types before making any replacements to ensure we have the correct inner type
842+
if (response.items != null) {
843+
patchNestedMaps(response.items);
844+
}
845+
846+
String[] nestedTypes = {"List", "Collection", "ICollection", "Dictionary"};
847+
848+
if (response.dataType != null) {
849+
String originalType = response.dataType;
850+
851+
for (String nestedType : nestedTypes) {
852+
// fix incorrect data types for maps of maps
853+
if (response.items != null) {
854+
if (response.dataType.contains(", " + nestedType + ">")) {
855+
response.dataType = response.dataType.replace(", " + nestedType + ">", ", " + response.items.datatypeWithEnum + ">");
856+
}
857+
858+
if (response.dataType.contains("<" + nestedType + ">")) {
859+
response.dataType = response.dataType.replace("<" + nestedType + ">", "<" + response.items.datatypeWithEnum + ">");
860+
}
861+
}
862+
}
863+
864+
// Only update dataType if we actually made changes
865+
if (!originalType.equals(response.dataType)) {
866+
response.dataType = response.dataType;
867+
}
868+
}
869+
}
870+
828871
protected void patchProperty(Map<String, CodegenModel> enumRefs, CodegenModel model, CodegenProperty property) {
829872
if (enumRefs.containsKey(property.dataType)) {
830873
// Handle any enum properties referred to by $ref.
@@ -962,6 +1005,7 @@ private void postProcessOperations(OperationMap operations, List<ModelMap> allMo
9621005
}
9631006
if (operation.responses != null) {
9641007
for (CodegenResponse response : operation.responses) {
1008+
patchNestedMaps(response);
9651009

9661010
if (response.returnProperty != null) {
9671011
Boolean isValueType = isValueType(response.returnProperty);

0 commit comments

Comments
 (0)