From a577db895ca42d2f819c679eb91950eae3e9a8c8 Mon Sep 17 00:00:00 2001 From: Xiangxuan Qu Date: Sat, 18 Nov 2023 15:41:17 +0900 Subject: [PATCH] fix[csharp]: The Deserialize should use the ClientUtils to handle the headers. (#16604) --- .../csharp/libraries/httpclient/ApiClient.mustache | 13 ++++++++++++- .../src/Org.OpenAPITools/Client/ApiClient.cs | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/csharp/libraries/httpclient/ApiClient.mustache b/modules/openapi-generator/src/main/resources/csharp/libraries/httpclient/ApiClient.mustache index 021fcb79a38..22993e54336 100644 --- a/modules/openapi-generator/src/main/resources/csharp/libraries/httpclient/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/csharp/libraries/httpclient/ApiClient.mustache @@ -91,7 +91,18 @@ namespace {{packageName}}.Client /// Object representation of the JSON string. internal async Task Deserialize(HttpResponseMessage response, Type type) { - IList headers = response.Headers.Select(x => x.Key + "=" + x.Value).ToList(); + IList headers = new List(); + // process response headers, e.g. Access-Control-Allow-Methods + foreach (var responseHeader in response.Headers) + { + headers.Add(responseHeader.Key + "=" + ClientUtils.ParameterToString(responseHeader.Value)); + } + + // process response content headers, e.g. Content-Type + foreach (var responseHeader in response.Content.Headers) + { + headers.Add(responseHeader.Key + "=" + ClientUtils.ParameterToString(responseHeader.Value)); + } if (type == typeof(byte[])) // return byte array { diff --git a/samples/client/petstore/csharp/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/ApiClient.cs b/samples/client/petstore/csharp/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/ApiClient.cs index f6e3372563a..b814e218a61 100644 --- a/samples/client/petstore/csharp/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/ApiClient.cs +++ b/samples/client/petstore/csharp/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/ApiClient.cs @@ -94,7 +94,18 @@ namespace Org.OpenAPITools.Client /// Object representation of the JSON string. internal async Task Deserialize(HttpResponseMessage response, Type type) { - IList headers = response.Headers.Select(x => x.Key + "=" + x.Value).ToList(); + IList headers = new List(); + // process response headers, e.g. Access-Control-Allow-Methods + foreach (var responseHeader in response.Headers) + { + headers.Add(responseHeader.Key + "=" + ClientUtils.ParameterToString(responseHeader.Value)); + } + + // process response content headers, e.g. Content-Type + foreach (var responseHeader in response.Content.Headers) + { + headers.Add(responseHeader.Key + "=" + ClientUtils.ParameterToString(responseHeader.Value)); + } if (type == typeof(byte[])) // return byte array {