From 0c9fcbce8c808cfcdfb13d44d30feb1ae31dca75 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Tue, 17 Dec 2024 08:18:40 -0500 Subject: [PATCH] fix: expected empty response in rest APIs Signed-off-by: Vincent Biret --- .../Functions.OpenApi/RestApiOperationRunner.cs | 4 +++- .../OpenApi/RestApiOperationRunnerTests.cs | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/dotnet/src/Functions/Functions.OpenApi/RestApiOperationRunner.cs b/dotnet/src/Functions/Functions.OpenApi/RestApiOperationRunner.cs index 9c1c2bcb1177..7c0ada6d830c 100644 --- a/dotnet/src/Functions/Functions.OpenApi/RestApiOperationRunner.cs +++ b/dotnet/src/Functions/Functions.OpenApi/RestApiOperationRunner.cs @@ -302,7 +302,9 @@ private async Task SendAsync( /// The operation response. private async Task ReadContentAndCreateOperationResponseAsync(HttpRequestMessage requestMessage, HttpResponseMessage responseMessage, object? payload, CancellationToken cancellationToken) { - if (responseMessage.StatusCode == HttpStatusCode.NoContent) + if (responseMessage.StatusCode == HttpStatusCode.NoContent || + (string.IsNullOrEmpty(responseMessage.Content.Headers.ContentType?.MediaType) && + (responseMessage.StatusCode is HttpStatusCode.Accepted or HttpStatusCode.Created))) { return new RestApiOperationResponse(null, null) { diff --git a/dotnet/src/Functions/Functions.UnitTests/OpenApi/RestApiOperationRunnerTests.cs b/dotnet/src/Functions/Functions.UnitTests/OpenApi/RestApiOperationRunnerTests.cs index 089644ad7848..fd48bbcb6a50 100644 --- a/dotnet/src/Functions/Functions.UnitTests/OpenApi/RestApiOperationRunnerTests.cs +++ b/dotnet/src/Functions/Functions.UnitTests/OpenApi/RestApiOperationRunnerTests.cs @@ -1136,11 +1136,14 @@ public async Task ItShouldReturnRequestUriAndContentAsync() Assert.Equal("{\"name\":\"fake-name-value\",\"attributes\":{\"enabled\":true}}", ((JsonObject)result.RequestPayload).ToJsonString()); } - [Fact] - public async Task ItShouldHandleNoContentAsync() + [InlineData(System.Net.HttpStatusCode.NoContent)] + [InlineData(System.Net.HttpStatusCode.Accepted)] + [InlineData(System.Net.HttpStatusCode.Created)] + [Theory] + public async Task ItShouldHandleNoContentAsync(System.Net.HttpStatusCode statusCode) { // Arrange - this._httpMessageHandlerStub!.ResponseToReturn = new HttpResponseMessage(System.Net.HttpStatusCode.NoContent); + this._httpMessageHandlerStub!.ResponseToReturn = new HttpResponseMessage(statusCode); List payloadProperties = [