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 178e54ec589f..ec07161ff199 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 @@ -1628,7 +1628,7 @@ public String getTypeDeclaration(Schema p) { Schema target = ModelUtils.isGenerateAliasAsModel() ? p : schema; if (ModelUtils.isArraySchema(target)) { Schema items = getSchemaItems(schema); - return getSchemaType(target) + "<" + getTypeDeclarationForArray(items) + ">"; + return typeMapping.get("array") + "<" + getTypeDeclarationForArray(items) + ">"; } else if (ModelUtils.isMapSchema(p)) { // Should we also support maps of maps? Schema inner = ModelUtils.getAdditionalProperties(p); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/csharpnetcore/CSharpModelTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/csharpnetcore/CSharpModelTest.java index 36bb4a9e4a8c..c9a085b71e2b 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/csharpnetcore/CSharpModelTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/csharpnetcore/CSharpModelTest.java @@ -368,11 +368,27 @@ public void nullablePropertyWithoutNullableReferenceTypesTest() { public void nullablePropertyWithNullableReferenceTypesTest() { final Schema model = new Schema() .description("a sample model") - .addProperties("id", new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT).nullable(true)) + .addProperties("id", new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT) + .nullable(true)) .addProperties("urls", new ArraySchema() - .items(new StringSchema()).nullable(true)) + .items(new StringSchema()) + .nullable(true)) .addProperties("name", new StringSchema().nullable(true)) - .addProperties("subObject", new Schema().addProperties("name", new StringSchema()).nullable(true)) + .addProperties("subObject", new Schema().addProperties("name", new StringSchema()) + .nullable(true)) + .addProperties("deepNullableAliasArray", new ArraySchema() + .items(new ArraySchema() + .items(new StringSchema() + .nullable(true)) + .nullable(true)) + .nullable(true)) + .addProperties("deepAliasArray", new ArraySchema() + .items(new ArraySchema() + .items(new StringSchema()))) + .addProperties("deepIntermediateNullableAliasArray", new ArraySchema() + .items(new ArraySchema() + .items(new StringSchema()) + .nullable(true))) .addRequiredItem("id"); final DefaultCodegen codegen = new AspNetServerCodegen(); codegen.processOpts(); @@ -385,7 +401,7 @@ public void nullablePropertyWithNullableReferenceTypesTest() { Assert.assertEquals(cm.name, "sample"); Assert.assertEquals(cm.classname, "Sample"); Assert.assertEquals(cm.description, "a sample model"); - Assert.assertEquals(cm.vars.size(), 4); + Assert.assertEquals(cm.vars.size(), 7); final CodegenProperty property1 = cm.vars.get(0); Assert.assertEquals(property1.baseName, "id"); @@ -398,7 +414,7 @@ public void nullablePropertyWithNullableReferenceTypesTest() { final CodegenProperty property2 = cm.vars.get(1); Assert.assertEquals(property2.baseName, "urls"); - Assert.assertEquals(property2.dataType, "List?"); + Assert.assertEquals(property2.dataType, "List"); Assert.assertEquals(property2.name, "Urls"); Assert.assertNull(property2.defaultValue); Assert.assertEquals(property2.baseType, "List?"); @@ -424,6 +440,33 @@ public void nullablePropertyWithNullableReferenceTypesTest() { Assert.assertEquals(property4.baseType, "Object?"); Assert.assertFalse(property4.required); Assert.assertFalse(property4.isPrimitiveType); + + final CodegenProperty property5 = cm.vars.get(4); + Assert.assertEquals(property5.baseName, "deepNullableAliasArray"); + Assert.assertEquals(property5.dataType, "List>"); + Assert.assertEquals(property5.name, "DeepNullableAliasArray"); + Assert.assertNull(property5.defaultValue); + Assert.assertEquals(property5.baseType, "List?"); + Assert.assertEquals(property5.containerType, "array"); + Assert.assertFalse(property5.required); + Assert.assertFalse(property5.isPrimitiveType); + Assert.assertTrue(property5.isContainer); + + final CodegenProperty property6 = cm.vars.get(5); + Assert.assertEquals(property6.baseName, "deepAliasArray"); + Assert.assertEquals(property6.dataType, "List>"); + Assert.assertEquals(property6.name, "DeepAliasArray"); + Assert.assertEquals(property6.baseType, "List"); + Assert.assertEquals(property6.containerType, "array"); + Assert.assertTrue(property6.isContainer); + + final CodegenProperty property7 = cm.vars.get(6); + Assert.assertEquals(property7.baseName, "deepIntermediateNullableAliasArray"); + Assert.assertEquals(property7.dataType, "List>"); + Assert.assertEquals(property7.name, "DeepIntermediateNullableAliasArray"); + Assert.assertEquals(property7.baseType, "List"); + Assert.assertEquals(property7.containerType, "array"); + Assert.assertTrue(property7.isContainer); } @Test(description = "convert a model with list property") diff --git a/modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml b/modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml index 6b565788598b..a9b677c1740b 100644 --- a/modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml @@ -2935,6 +2935,16 @@ components: description: list of named parameters for current message additionalProperties: type: string + ListAlias: + type: array + items: + type: string + DeepListAlias: + type: array + items: + type: array + items: + type: string TestResult: type: object allOf: diff --git a/samples/client/petstore/csharp/generichost/net4.7/FormModels/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net4.7/FormModels/api/openapi.yaml index 98095354ea32..dc3c6d2ecf6b 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/FormModels/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/api/openapi.yaml @@ -2687,6 +2687,16 @@ components: description: list of named parameters for current message type: object type: object + ListAlias: + items: + type: string + type: array + DeepListAlias: + items: + items: + type: string + type: array + type: array TestResult: allOf: - $ref: "#/components/schemas/Result" diff --git a/samples/client/petstore/csharp/generichost/net4.7/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net4.7/Petstore/api/openapi.yaml index 9d3b1ee3ad39..5966b9f8a330 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net4.7/Petstore/api/openapi.yaml @@ -2868,6 +2868,16 @@ components: description: list of named parameters for current message type: object type: object + ListAlias: + items: + type: string + type: array + DeepListAlias: + items: + items: + type: string + type: array + type: array TestResult: allOf: - $ref: "#/components/schemas/Result" diff --git a/samples/client/petstore/csharp/generichost/net4.8/FormModels/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net4.8/FormModels/api/openapi.yaml index 98095354ea32..dc3c6d2ecf6b 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/FormModels/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/api/openapi.yaml @@ -2687,6 +2687,16 @@ components: description: list of named parameters for current message type: object type: object + ListAlias: + items: + type: string + type: array + DeepListAlias: + items: + items: + type: string + type: array + type: array TestResult: allOf: - $ref: "#/components/schemas/Result" diff --git a/samples/client/petstore/csharp/generichost/net4.8/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net4.8/Petstore/api/openapi.yaml index 9d3b1ee3ad39..5966b9f8a330 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net4.8/Petstore/api/openapi.yaml @@ -2868,6 +2868,16 @@ components: description: list of named parameters for current message type: object type: object + ListAlias: + items: + type: string + type: array + DeepListAlias: + items: + items: + type: string + type: array + type: array TestResult: allOf: - $ref: "#/components/schemas/Result" diff --git a/samples/client/petstore/csharp/generichost/net8/FormModels/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net8/FormModels/api/openapi.yaml index 98095354ea32..dc3c6d2ecf6b 100644 --- a/samples/client/petstore/csharp/generichost/net8/FormModels/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/api/openapi.yaml @@ -2687,6 +2687,16 @@ components: description: list of named parameters for current message type: object type: object + ListAlias: + items: + type: string + type: array + DeepListAlias: + items: + items: + type: string + type: array + type: array TestResult: allOf: - $ref: "#/components/schemas/Result" diff --git a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/api/openapi.yaml index 9d3b1ee3ad39..5966b9f8a330 100644 --- a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/api/openapi.yaml @@ -2868,6 +2868,16 @@ components: description: list of named parameters for current message type: object type: object + ListAlias: + items: + type: string + type: array + DeepListAlias: + items: + items: + type: string + type: array + type: array TestResult: allOf: - $ref: "#/components/schemas/Result" diff --git a/samples/client/petstore/csharp/generichost/net8/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net8/Petstore/api/openapi.yaml index 9d3b1ee3ad39..5966b9f8a330 100644 --- a/samples/client/petstore/csharp/generichost/net8/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net8/Petstore/api/openapi.yaml @@ -2868,6 +2868,16 @@ components: description: list of named parameters for current message type: object type: object + ListAlias: + items: + type: string + type: array + DeepListAlias: + items: + items: + type: string + type: array + type: array TestResult: allOf: - $ref: "#/components/schemas/Result" diff --git a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/api/openapi.yaml index 9d3b1ee3ad39..5966b9f8a330 100644 --- a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/api/openapi.yaml @@ -2868,6 +2868,16 @@ components: description: list of named parameters for current message type: object type: object + ListAlias: + items: + type: string + type: array + DeepListAlias: + items: + items: + type: string + type: array + type: array TestResult: allOf: - $ref: "#/components/schemas/Result" diff --git a/samples/client/petstore/csharp/generichost/net9/FormModels/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net9/FormModels/api/openapi.yaml index 98095354ea32..dc3c6d2ecf6b 100644 --- a/samples/client/petstore/csharp/generichost/net9/FormModels/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/api/openapi.yaml @@ -2687,6 +2687,16 @@ components: description: list of named parameters for current message type: object type: object + ListAlias: + items: + type: string + type: array + DeepListAlias: + items: + items: + type: string + type: array + type: array TestResult: allOf: - $ref: "#/components/schemas/Result" diff --git a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/api/openapi.yaml index 9d3b1ee3ad39..5966b9f8a330 100644 --- a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/api/openapi.yaml @@ -2868,6 +2868,16 @@ components: description: list of named parameters for current message type: object type: object + ListAlias: + items: + type: string + type: array + DeepListAlias: + items: + items: + type: string + type: array + type: array TestResult: allOf: - $ref: "#/components/schemas/Result" diff --git a/samples/client/petstore/csharp/generichost/net9/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net9/Petstore/api/openapi.yaml index 9d3b1ee3ad39..5966b9f8a330 100644 --- a/samples/client/petstore/csharp/generichost/net9/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net9/Petstore/api/openapi.yaml @@ -2868,6 +2868,16 @@ components: description: list of named parameters for current message type: object type: object + ListAlias: + items: + type: string + type: array + DeepListAlias: + items: + items: + type: string + type: array + type: array TestResult: allOf: - $ref: "#/components/schemas/Result" diff --git a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/api/openapi.yaml index 9d3b1ee3ad39..5966b9f8a330 100644 --- a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/api/openapi.yaml @@ -2868,6 +2868,16 @@ components: description: list of named parameters for current message type: object type: object + ListAlias: + items: + type: string + type: array + DeepListAlias: + items: + items: + type: string + type: array + type: array TestResult: allOf: - $ref: "#/components/schemas/Result" diff --git a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/api/openapi.yaml index 9d3b1ee3ad39..5966b9f8a330 100644 --- a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/api/openapi.yaml @@ -2868,6 +2868,16 @@ components: description: list of named parameters for current message type: object type: object + ListAlias: + items: + type: string + type: array + DeepListAlias: + items: + items: + type: string + type: array + type: array TestResult: allOf: - $ref: "#/components/schemas/Result" diff --git a/samples/client/petstore/csharp/httpclient/net9/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/httpclient/net9/Petstore/api/openapi.yaml index 9d3b1ee3ad39..5966b9f8a330 100644 --- a/samples/client/petstore/csharp/httpclient/net9/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/httpclient/net9/Petstore/api/openapi.yaml @@ -2868,6 +2868,16 @@ components: description: list of named parameters for current message type: object type: object + ListAlias: + items: + type: string + type: array + DeepListAlias: + items: + items: + type: string + type: array + type: array TestResult: allOf: - $ref: "#/components/schemas/Result" diff --git a/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/api/openapi.yaml index 9d3b1ee3ad39..5966b9f8a330 100644 --- a/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/api/openapi.yaml @@ -2868,6 +2868,16 @@ components: description: list of named parameters for current message type: object type: object + ListAlias: + items: + type: string + type: array + DeepListAlias: + items: + items: + type: string + type: array + type: array TestResult: allOf: - $ref: "#/components/schemas/Result" diff --git a/samples/client/petstore/csharp/restsharp/net8/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/restsharp/net8/Petstore/api/openapi.yaml index 9d3b1ee3ad39..5966b9f8a330 100644 --- a/samples/client/petstore/csharp/restsharp/net8/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/restsharp/net8/Petstore/api/openapi.yaml @@ -2868,6 +2868,16 @@ components: description: list of named parameters for current message type: object type: object + ListAlias: + items: + type: string + type: array + DeepListAlias: + items: + items: + type: string + type: array + type: array TestResult: allOf: - $ref: "#/components/schemas/Result" diff --git a/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/api/openapi.yaml b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/api/openapi.yaml index 9d3b1ee3ad39..5966b9f8a330 100644 --- a/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/api/openapi.yaml +++ b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/api/openapi.yaml @@ -2868,6 +2868,16 @@ components: description: list of named parameters for current message type: object type: object + ListAlias: + items: + type: string + type: array + DeepListAlias: + items: + items: + type: string + type: array + type: array TestResult: allOf: - $ref: "#/components/schemas/Result" diff --git a/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/api/openapi.yaml index 9d3b1ee3ad39..5966b9f8a330 100644 --- a/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/api/openapi.yaml @@ -2868,6 +2868,16 @@ components: description: list of named parameters for current message type: object type: object + ListAlias: + items: + type: string + type: array + DeepListAlias: + items: + items: + type: string + type: array + type: array TestResult: allOf: - $ref: "#/components/schemas/Result" diff --git a/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/api/openapi.yaml index 9d3b1ee3ad39..5966b9f8a330 100644 --- a/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/api/openapi.yaml @@ -2868,6 +2868,16 @@ components: description: list of named parameters for current message type: object type: object + ListAlias: + items: + type: string + type: array + DeepListAlias: + items: + items: + type: string + type: array + type: array TestResult: allOf: - $ref: "#/components/schemas/Result"