Repository: microsoft/kiota (csharp)

Issue:
C# AnyOf array or string not creating array type
When trying to create an anyOf type I get an object type rather than an array.
The FooResponseObject property is not a `List<FooResponseObject>` as expected.

**Yaml to reproduce:**
```yaml
openapi: 3.0.1
info:
  title: Test API
  version: 1.0.0
paths:
  /foo:
    get:
      responses:
        200:
          description: "OK"
          content:
            application/json:
              schema:
                oneOf:         # <--- create a union type
                - type: string # <--- string |
                - type: array  # <--- FooResponseObject[]
                  items:
                    $ref: "#/components/schemas/FooResponseObject"
components:
  schemas:
    FooResponseObject:
      type: object
      properties:
        id:
          type: string
        name:
          type: string
```

**Output from Kiota:**
```c#
public class FooGetResponse : IComposedTypeWrapper, IParsable {
    /// <summary>Composed type representation for type FooResponseObject</summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
    public HrOn.Client.Foo.FooResponseObject? FooResponseObject { get; set; }
#nullable restore
#else
    public HrOn.Client.Foo.FooResponseObject FooResponseObject { get; set; }
#endif
    /// <summary>Composed type representation for type string</summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
    public string? String { get; set; }
#nullable restore
#else
    public string String { get; set; }
#endif
    /// <summary>
    /// Creates a new instance of the appropriate class based on discriminator value
    /// </summary>
    /// <param name="parseNode">The parse node to use to read the discriminator value and create the object</param>
    public static FooGetResponse CreateFromDiscriminatorValue(IParseNode parseNode) {
        _ = parseNode ?? throw new ArgumentNullException(nameof(parseNode));
        var mappingValue = parseNode.GetChildNode("")?.GetStringValue();
        var result = new FooGetResponse();
        if("".Equals(mappingValue, StringComparison.OrdinalIgnoreCase)) {
            result.FooResponseObject = new HrOn.Client.Foo.FooResponseObject();
        }
        else if(parseNode.GetStringValue() is string stringValue) {
            result.String = stringValue;
        }
        return result;
    }
    /// <summary>
    /// The deserialization information for the current model
    /// </summary>
    public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers() {
        if(FooResponseObject != null) {
            return FooResponseObject.GetFieldDeserializers();
        }
        return new Dictionary<string, Action<IParseNode>>();
    }
    /// <summary>
    /// Serializes information the current object
    /// </summary>
    /// <param name="writer">Serialization writer to use to serialize this model</param>
    public virtual void Serialize(ISerializationWriter writer) {
        _ = writer ?? throw new ArgumentNullException(nameof(writer));
        if(FooResponseObject != null) {
            writer.WriteObjectValue<HrOn.Client.Foo.FooResponseObject>(null, FooResponseObject);
        }
        else if(String != null) {
            writer.WriteStringValue(null, String);
        }
    }
}
```

Pull request description:
Adds support for AnyOf arrays as described in

 fixes #3786

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bfe99242ef..6d92ee4710 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 - Fixed a bug where paths with parameters in the same position but different names would make generation fail. [#3756](https://github.com/microsoft/kiota/issues/3756)
 - Fixed a bug where a property named constructor would make generation fail. [#3756](https://github.com/microsoft/kiota/issues/3756)
 - Removed reflection for Java enum deserialization. [microsoft/kiota-java#843](https://github.com/microsoft/kiota-java/pull/843)
+- Added support for AnyOf arrays. [#3786](https://github.com/microsoft/kiota/pull/3792)
 
 ## [1.8.2] - 2023-11-08
 
diff --git a/src/Kiota.Builder/KiotaBuilder.cs b/src/Kiota.Builder/KiotaBuilder.cs
index 866d2b1fee..cd4c41799a 100644
--- a/src/Kiota.Builder/KiotaBuilder.cs
+++ b/src/Kiota.Builder/KiotaBuilder.cs
@@ -1719,6 +1719,7 @@ private CodeTypeBase CreateComposedModelDeclaration(OpenApiUrlTreeNode currentNo
                 return new CodeType
                 {
                     TypeDefinition = AddModelDeclarationIfDoesntExist(currentNode, targetSchema, className, shortestNamespace),
+                    CollectionKind = targetSchema.IsArray() ? CodeTypeBase.CodeTypeCollectionKind.Complex : default
                 };// so we don't create unnecessary union types when anyOf was used only for nullable.
             }
         }
@@ -1757,6 +1758,7 @@ private CodeTypeBase CreateComposedModelDeclaration(OpenApiUrlTreeNode currentNo
             var declarationType = new CodeType
             {
                 TypeDefinition = AddModelDeclarationIfDoesntExist(currentNode, currentSchema, className, shortestNamespace),
+                CollectionKind = currentSchema.IsArray() ? CodeTypeBase.CodeTypeCollectionKind.Complex : default
             };
             if (!unionType.ContainsType(declarationType))
                 unionType.AddType(declarationType);


Test patch:
diff --git a/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs b/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs
index 76d25f805b..153be20b73 100644
--- a/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs
+++ b/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs
@@ -3501,6 +3501,48 @@ public void UnionOfPrimitiveTypesWorks()
         Assert.Contains("double", typeNames);
     }
     [Fact]
+    public async Task AnyOfArrayWorks()
+    {
+        var tempFilePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
+        await using var fs = await GetDocumentStream(@"openapi: 3.0.0
+info:
+  title: AnyOf Array
+  version: 1.0.0
+paths:
+  /foo:
+    get:
+      responses:
+        200:
+          description: ""OK""
+          content:
+            application/json:
+              schema:
+                anyOf:
+                - type: string
+                - type: array
+                  items:
+                    $ref: ""#/components/schemas/FooResponseObject""
+components:
+  schemas:
+    FooResponseObject:
+      type: object
+      properties:
+        id:
+          type: string
+        name:
+          type: string");
+        var mockLogger = new Mock<ILogger<KiotaBuilder>>();
+        var builder = new KiotaBuilder(mockLogger.Object, new GenerationConfiguration { ClientClassName = "Graph", OpenAPIFilePath = tempFilePath }, _httpClient);
+        var document = await builder.CreateOpenApiDocumentAsync(fs);
+        var node = builder.CreateUriSpace(document);
+        var codeModel = builder.CreateSourceModel(node);
+        var response = codeModel.FindChildByName<CodeMethod>("GetAsFooGetResponse");
+        var unionType = response.ReturnType as CodeIntersectionType;
+
+        Assert.Equal(2, unionType.Types.Count());
+        Assert.Single(unionType.Types.Where(x => x.Name == "FooResponseObject" && x.IsCollection));
+    }
+    [Fact]
     public void UnionOfInlineSchemasWorks()
     {
         var simpleObjet = new OpenApiSchema