diff --git a/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/httpclient/ApiClient.mustache b/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/httpclient/ApiClient.mustache index fe83457311c..e48722f8fa7 100644 --- a/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/httpclient/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/httpclient/ApiClient.mustache @@ -80,9 +80,9 @@ namespace {{packageName}}.Client } } - public T Deserialize(HttpResponseMessage response) + public async Task Deserialize(HttpResponseMessage response) { - var result = (T)Deserialize(response, typeof(T)); + var result = (T) await Deserialize(response, typeof(T)); return result; } @@ -92,19 +92,19 @@ namespace {{packageName}}.Client /// The HTTP response. /// Object type. /// Object representation of the JSON string. - internal object Deserialize(HttpResponseMessage response, Type type) + internal async Task Deserialize(HttpResponseMessage response, Type type) { IList headers = response.Headers.Select(x => x.Key + "=" + x.Value).ToList(); if (type == typeof(byte[])) // return byte array { - return response.Content.ReadAsByteArrayAsync().GetAwaiter().GetResult(); + return await response.Content.ReadAsByteArrayAsync(); } // TODO: ? if (type.IsAssignableFrom(typeof(Stream))) if (type == typeof(Stream)) { - var bytes = response.Content.ReadAsByteArrayAsync().GetAwaiter().GetResult(); + var bytes = await response.Content.ReadAsByteArrayAsync(); if (headers != null) { var filePath = String.IsNullOrEmpty(_configuration.TempFolderPath) @@ -128,18 +128,18 @@ namespace {{packageName}}.Client if (type.Name.StartsWith("System.Nullable`1[[System.DateTime")) // return a datetime object { - return DateTime.Parse(response.Content.ReadAsStringAsync().GetAwaiter().GetResult(), null, System.Globalization.DateTimeStyles.RoundtripKind); + return DateTime.Parse(await response.Content.ReadAsStringAsync(), null, System.Globalization.DateTimeStyles.RoundtripKind); } if (type == typeof(String) || type.Name.StartsWith("System.Nullable")) // return primitive type { - return Convert.ChangeType(response.Content.ReadAsStringAsync().GetAwaiter().GetResult(), type); + return Convert.ChangeType(await response.Content.ReadAsStringAsync(), type); } // at this point, it must be a model (json) try { - return JsonConvert.DeserializeObject(response.Content.ReadAsStringAsync().GetAwaiter().GetResult(), type, _serializerSettings); + return JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync(), type, _serializerSettings); } catch (Exception e) { @@ -510,7 +510,7 @@ namespace {{packageName}}.Client return await ToApiResponse(response, default(T), req.RequestUri); } - object responseData = deserializer.Deserialize(response); + object responseData = await deserializer.Deserialize(response); // if the response type is oneOf/anyOf, call FromJSON to deserialize the data if (typeof({{{packageName}}}.{{modelPackage}}.AbstractOpenAPISchema).IsAssignableFrom(typeof(T))) diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/ApiClient.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/ApiClient.cs index 69d9bb714e3..bc7d7d84785 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/ApiClient.cs +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/ApiClient.cs @@ -80,9 +80,9 @@ namespace Org.OpenAPITools.Client } } - public T Deserialize(HttpResponseMessage response) + public async Task Deserialize(HttpResponseMessage response) { - var result = (T)Deserialize(response, typeof(T)); + var result = (T) await Deserialize(response, typeof(T)); return result; } @@ -92,19 +92,19 @@ namespace Org.OpenAPITools.Client /// The HTTP response. /// Object type. /// Object representation of the JSON string. - internal object Deserialize(HttpResponseMessage response, Type type) + internal async Task Deserialize(HttpResponseMessage response, Type type) { IList headers = response.Headers.Select(x => x.Key + "=" + x.Value).ToList(); if (type == typeof(byte[])) // return byte array { - return response.Content.ReadAsByteArrayAsync().GetAwaiter().GetResult(); + return await response.Content.ReadAsByteArrayAsync(); } // TODO: ? if (type.IsAssignableFrom(typeof(Stream))) if (type == typeof(Stream)) { - var bytes = response.Content.ReadAsByteArrayAsync().GetAwaiter().GetResult(); + var bytes = await response.Content.ReadAsByteArrayAsync(); if (headers != null) { var filePath = String.IsNullOrEmpty(_configuration.TempFolderPath) @@ -128,18 +128,18 @@ namespace Org.OpenAPITools.Client if (type.Name.StartsWith("System.Nullable`1[[System.DateTime")) // return a datetime object { - return DateTime.Parse(response.Content.ReadAsStringAsync().GetAwaiter().GetResult(), null, System.Globalization.DateTimeStyles.RoundtripKind); + return DateTime.Parse(await response.Content.ReadAsStringAsync(), null, System.Globalization.DateTimeStyles.RoundtripKind); } if (type == typeof(String) || type.Name.StartsWith("System.Nullable")) // return primitive type { - return Convert.ChangeType(response.Content.ReadAsStringAsync().GetAwaiter().GetResult(), type); + return Convert.ChangeType(await response.Content.ReadAsStringAsync(), type); } // at this point, it must be a model (json) try { - return JsonConvert.DeserializeObject(response.Content.ReadAsStringAsync().GetAwaiter().GetResult(), type, _serializerSettings); + return JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync(), type, _serializerSettings); } catch (Exception e) { @@ -504,7 +504,7 @@ namespace Org.OpenAPITools.Client return await ToApiResponse(response, default(T), req.RequestUri); } - object responseData = deserializer.Deserialize(response); + object responseData = await deserializer.Deserialize(response); // if the response type is oneOf/anyOf, call FromJSON to deserialize the data if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))