Skip to content

Commit

Permalink
Merge pull request #4700 from microsoft/andrueastman/untypedResponse
Browse files Browse the repository at this point in the history
Fixes missing `CreateFromDiscriminatorValue` parameter in dotnet.
  • Loading branch information
andrueastman authored May 22, 2024
2 parents 7d47d04 + 397cd9e commit 659da5b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions tests/Kiota.Builder.Tests/Writers/CSharp/CodeMethodWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, ParsableFactory<IParsable>>", result);
Assert.Contains("<exception cref=", result);
Assert.Contains("{ \"XXX\", ErrorXXX.CreateFromDiscriminatorValue },", result);
Assert.Contains("SendAsync", result);
Assert.Contains("UntypedNode.CreateFromDiscriminatorValue", result);
Assert.Contains(AsyncKeyword, result);
Assert.Contains("await", result);
Assert.Contains("cancellationToken", result);
AssertExtensions.CurlyBracesAreClosed(result, 1);
}
[Fact]
public void WritesRequestGeneratorBodyForMultipart()
{
setup();
Expand Down

0 comments on commit 659da5b

Please sign in to comment.