From 397cd9edcdbd6ca92320ed01b29e9547eb700868 Mon Sep 17 00:00:00 2001 From: Andrew Omondi Date: Wed, 22 May 2024 10:51:05 +0300 Subject: [PATCH] Fixes issue in dotnet --- CHANGELOG.md | 1 + .../Writers/CSharp/CodeMethodWriter.cs | 2 +- .../Writers/CSharp/CodeMethodWriterTests.cs | 26 +++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8898560629..a8523e155e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixes a bug where paths without operationIds would not be included in the generated plugins and ensured operationIds are cleaned up [#4642](https://github.com/microsoft/kiota/issues/4642) - Fixes a bug where models would be duplicated in some allOf scenarios [#4191](https://github.com/microsoft/kiota/issues/4191) - Fixes a bug where CLI Generation does not handle path parameters of type "string" and format "date", "date-time", "time", etc. [#4615](https://github.com/microsoft/kiota/issues/4615) +- Fixes a bug where request executors would be missing Untyped parameters in dotnet [#4692](https://github.com/microsoft/kiota/issues/4692) ## [1.14.0] - 2024-05-02 diff --git a/src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs index 889e348f43..66d29a759f 100644 --- a/src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs @@ -394,7 +394,7 @@ protected void WriteRequestExecutorBody(CodeMethod codeElement, RequestParams re writer.CloseBlock("};"); } var returnTypeCodeType = codeElement.ReturnType as CodeType; - var returnTypeFactory = returnTypeCodeType?.TypeDefinition is CodeClass + var returnTypeFactory = returnTypeCodeType?.TypeDefinition is CodeClass || (returnTypeCodeType != null && returnTypeCodeType.Name.Equals(KiotaBuilder.UntypedNodeName, StringComparison.OrdinalIgnoreCase)) ? $", {returnTypeWithoutCollectionInformation}.CreateFromDiscriminatorValue" : null; var prefix = (isVoid, codeElement.ReturnType.IsCollection) switch diff --git a/tests/Kiota.Builder.Tests/Writers/CSharp/CodeMethodWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/CSharp/CodeMethodWriterTests.cs index 06fdbf7d21..ae87bd46ba 100644 --- a/tests/Kiota.Builder.Tests/Writers/CSharp/CodeMethodWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/CSharp/CodeMethodWriterTests.cs @@ -482,6 +482,32 @@ public void WritesRequestExecutorBody() AssertExtensions.CurlyBracesAreClosed(result, 1); } [Fact] + public void WritesRequestExecutorBodyWithUntypedReturnValue() + { + setup(); + method.Kind = CodeMethodKind.RequestExecutor; + method.HttpMethod = HttpMethod.Get; + method.ReturnType = new CodeType { TypeDefinition = null, Name = KiotaBuilder.UntypedNodeName }; + var errorXXX = root.AddClass(new CodeClass + { + Name = "ErrorXXX", + }).First(); + method.AddErrorMapping("XXX", new CodeType { Name = "ErrorXXX", TypeDefinition = errorXXX }); + AddRequestBodyParameters(); + writer.Write(method); + var result = tw.ToString(); + Assert.Contains("var requestInfo", result); + Assert.Contains("var errorMapping = new Dictionary>", result); + Assert.Contains("