diff --git a/CHANGELOG.md b/CHANGELOG.md index 98616c366a..9aba71fd3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Aligns naming of sliced OpenAPI description generated by `plugin add` should be named `-openapi.json|yml` - Fixed RPC server to respect the `KIOTA_CONFIG_PREVIEW` flag. +- Fixed handling of nested arrays to be handled as `UntypedNode` instances [#4549](https://github.com/microsoft/kiota/issues/4549) ## [1.14.0] - 2024-05-02 diff --git a/src/Kiota.Builder/KiotaBuilder.cs b/src/Kiota.Builder/KiotaBuilder.cs index 5bcbcf7881..ef2920287b 100644 --- a/src/Kiota.Builder/KiotaBuilder.cs +++ b/src/Kiota.Builder/KiotaBuilder.cs @@ -1693,7 +1693,8 @@ private CodeTypeBase CreateModelDeclarations(OpenApiUrlTreeNode currentNode, Ope return CreateModelDeclarationAndType(currentNode, schema, operation, codeNamespace, suffix, response: responseValue, typeNameForInlineSchema: typeNameForInlineSchema, isRequestBody); } - if (schema.IsArray()) + if (schema.IsArray() && + !schema.Items.IsArray()) // Only handle collections of primitives and complex types. Otherwise, multi-dimensional arrays would be recursively unwrapped undesirably to lead to incorrect serialization types. { // collections at root return CreateCollectionModelDeclaration(currentNode, schema, operation, codeNamespace, typeNameForInlineSchema, isRequestBody); diff --git a/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs b/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs index 66c5469c5a..82dabd2d6a 100644 --- a/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs +++ b/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs @@ -1273,6 +1273,74 @@ public void OData_doubles_as_any_of() Assert.Equal("double", progressProp.Type.Name); } [Fact] + public void MultiNestedArraysSupportedAsUntypedNodes() + { + var fooSchema = new OpenApiSchema + { + Type = "object", + Properties = new Dictionary { + { + "sortBy", new OpenApiSchema { + Type = "array", + Items = new OpenApiSchema { + Type = "array", + Items = new OpenApiSchema { + Type = "string" + } + } + } + }, + }, + Reference = new OpenApiReference + { + Id = "#/components/schemas/bar.foo" + }, + UnresolvedReference = false + }; + var document = new OpenApiDocument + { + Paths = new OpenApiPaths + { + ["foos/{id}"] = new OpenApiPathItem + { + Operations = { + [OperationType.Get] = new OpenApiOperation + { + Responses = new OpenApiResponses { + ["200"] = new OpenApiResponse + { + Content = { + ["application/json"] = new OpenApiMediaType + { + Schema = fooSchema + } + } + } + } + } + } + }, + }, + Components = new OpenApiComponents + { + Schemas = new Dictionary { + { + "bar.foo", fooSchema + } + } + } + }; + var mockLogger = new CountLogger(); + var builder = new KiotaBuilder(mockLogger, new GenerationConfiguration { ClientClassName = "Graph", ApiRootUrl = "https://localhost" }, _httpClient); + var node = builder.CreateUriSpace(document); + var codeModel = builder.CreateSourceModel(node); + var fooClass = codeModel.FindNamespaceByName("ApiSdk.models").FindChildByName("foo"); + Assert.NotNull(fooClass); + var sortByProp = fooClass.FindChildByName("sortBy", false); + Assert.NotNull(sortByProp); + Assert.Equal(KiotaBuilder.UntypedNodeName, sortByProp.Type.Name);// nested array property an UntypedNode + } + [Fact] public void Object_Arrays_are_supported() { var userSchema = new OpenApiSchema