|
44 | 44 | import java.util.regex.Pattern; |
45 | 45 | import java.util.stream.Collectors; |
46 | 46 |
|
47 | | -import static org.openapitools.codegen.CodegenConstants.*; |
48 | 47 | import static org.openapitools.codegen.languages.CSharpClientCodegen.GENERICHOST; |
49 | 48 | import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER; |
50 | 49 | import static org.openapitools.codegen.utils.StringUtils.camelize; |
@@ -1164,12 +1163,7 @@ protected void processOperation(CodegenOperation operation) { |
1164 | 1163 | } |
1165 | 1164 |
|
1166 | 1165 | String[] nestedTypes = {"List", "Collection", "ICollection", "Dictionary"}; |
1167 | | - String dataType = operation.returnProperty.items.dataType; |
1168 | | - if (!GENERICHOST.equals(getLibrary())) { |
1169 | | - if (operation.returnProperty.items.isNullable && (this.nullReferenceTypesFlag || operation.returnProperty.items.isEnum || getValueTypes().contains(dataType)) && !dataType.endsWith("?")) { |
1170 | | - dataType += "?"; |
1171 | | - } |
1172 | | - } |
| 1166 | + String dataType = getNullablePropertyType(operation.returnProperty.items); |
1173 | 1167 |
|
1174 | 1168 | for (String nestedType : nestedTypes) { |
1175 | 1169 | if (operation.returnType.contains("<" + nestedType + ">")) { |
@@ -1442,18 +1436,21 @@ private String getArrayTypeDeclaration(Schema arr) { |
1442 | 1436 | String arrayType = typeMapping.get("array"); |
1443 | 1437 | StringBuilder instantiationType = new StringBuilder(arrayType); |
1444 | 1438 | Schema<?> items = ModelUtils.getSchemaItems(arr); |
1445 | | - String nestedType = getTypeDeclaration(items); |
| 1439 | + String nestedType = getNullableSchemaType(items); |
1446 | 1440 |
|
1447 | | - if (!GENERICHOST.equals(getLibrary())) { |
1448 | | - if (ModelUtils.isNullable(items) && (this.nullReferenceTypesFlag || ModelUtils.isEnumSchema(items) || getValueTypes().contains(nestedType)) && !nestedType.endsWith("?")) { |
1449 | | - nestedType += "?"; |
1450 | | - } |
1451 | | - } |
1452 | 1441 | // TODO: We may want to differentiate here between generics and primitive arrays. |
1453 | 1442 | instantiationType.append("<").append(nestedType).append(">"); |
1454 | 1443 | return instantiationType.toString(); |
1455 | 1444 | } |
1456 | 1445 |
|
| 1446 | + protected String getNullablePropertyType(CodegenProperty property) { |
| 1447 | + return property.dataType; |
| 1448 | + } |
| 1449 | + |
| 1450 | + protected String getNullableSchemaType(Schema<?> items) { |
| 1451 | + return getTypeDeclaration(items); |
| 1452 | + } |
| 1453 | + |
1457 | 1454 | @Override |
1458 | 1455 | public String toInstantiationType(Schema p) { |
1459 | 1456 | if (ModelUtils.isArraySchema(p)) { |
|
0 commit comments