From 8b6887a09456d6db4edd08aec2923baca85e0aee Mon Sep 17 00:00:00 2001 From: Andrew Omondi Date: Mon, 6 May 2024 11:28:19 +0300 Subject: [PATCH 1/2] Fixes for multi dimensional arrays --- src/Kiota.Builder/KiotaBuilder.cs | 3 +- .../Kiota.Builder.Tests/KiotaBuilderTests.cs | 68 +++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) 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 From 4f0762ae83f797725cdc2135c3e1192453d38741 Mon Sep 17 00:00:00 2001 From: Andrew Omondi Date: Mon, 6 May 2024 12:21:48 +0300 Subject: [PATCH 2/2] Updates the changelog file --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d5b2b6b61..df485049c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,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