From 6f0bef61baaff96f5247187a3aa5a959457e6310 Mon Sep 17 00:00:00 2001 From: Sai Giridhar P Date: Sun, 9 Aug 2020 21:40:57 +0530 Subject: [PATCH] feat(csharp-netcore): Adding response headers to the ApiException (#7169) --- .../resources/csharp-netcore/ApiException.mustache | 10 +++++++++- .../resources/csharp-netcore/Configuration.mustache | 2 +- .../src/Org.OpenAPITools/Client/ApiException.cs | 10 +++++++++- .../src/Org.OpenAPITools/Client/Configuration.cs | 2 +- .../src/Org.OpenAPITools/Client/ApiException.cs | 10 +++++++++- .../src/Org.OpenAPITools/Client/Configuration.cs | 2 +- 6 files changed, 30 insertions(+), 6 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/csharp-netcore/ApiException.mustache b/modules/openapi-generator/src/main/resources/csharp-netcore/ApiException.mustache index 32c59a1b3d58..1d252e2114c1 100644 --- a/modules/openapi-generator/src/main/resources/csharp-netcore/ApiException.mustache +++ b/modules/openapi-generator/src/main/resources/csharp-netcore/ApiException.mustache @@ -21,6 +21,12 @@ namespace {{packageName}}.Client /// The error content (Http response body). public object ErrorContent { get; private set; } + /// + /// Gets or sets the HTTP headers + /// + /// HTTP headers + public Multimap Headers { get; private set; } + /// /// Initializes a new instance of the class. /// @@ -42,10 +48,12 @@ namespace {{packageName}}.Client /// HTTP status code. /// Error message. /// Error content. - public ApiException(int errorCode, string message, object errorContent = null) : base(message) + /// HTTP Headers. + public ApiException(int errorCode, string message, object errorContent = null, Multimap headers = null) : base(message) { this.ErrorCode = errorCode; this.ErrorContent = errorContent; + this.Headers = headers; } } diff --git a/modules/openapi-generator/src/main/resources/csharp-netcore/Configuration.mustache b/modules/openapi-generator/src/main/resources/csharp-netcore/Configuration.mustache index ad5cfdef997a..820be40d2b9d 100644 --- a/modules/openapi-generator/src/main/resources/csharp-netcore/Configuration.mustache +++ b/modules/openapi-generator/src/main/resources/csharp-netcore/Configuration.mustache @@ -47,7 +47,7 @@ namespace {{packageName}}.Client { return new ApiException(status, string.Format("Error calling {0}: {1}", methodName, response.RawContent), - response.RawContent); + response.RawContent, response.Headers); } {{^netStandard}}if (status == 0) { diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Client/ApiException.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Client/ApiException.cs index 8f02a03a56ae..0dafc7e8ed39 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Client/ApiException.cs +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Client/ApiException.cs @@ -30,6 +30,12 @@ public class ApiException : Exception /// The error content (Http response body). public object ErrorContent { get; private set; } + /// + /// Gets or sets the HTTP headers + /// + /// HTTP headers + public Multimap Headers { get; private set; } + /// /// Initializes a new instance of the class. /// @@ -51,10 +57,12 @@ public ApiException(int errorCode, string message) : base(message) /// HTTP status code. /// Error message. /// Error content. - public ApiException(int errorCode, string message, object errorContent = null) : base(message) + /// HTTP Headers. + public ApiException(int errorCode, string message, object errorContent = null, Multimap headers = null) : base(message) { this.ErrorCode = errorCode; this.ErrorContent = errorContent; + this.Headers = headers; } } diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Client/Configuration.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Client/Configuration.cs index d81444d03e59..be6b48cb46e6 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Client/Configuration.cs +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Client/Configuration.cs @@ -54,7 +54,7 @@ public class Configuration : IReadableConfiguration { return new ApiException(status, string.Format("Error calling {0}: {1}", methodName, response.RawContent), - response.RawContent); + response.RawContent, response.Headers); } return null; diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Client/ApiException.cs b/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Client/ApiException.cs index 8f02a03a56ae..0dafc7e8ed39 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Client/ApiException.cs +++ b/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Client/ApiException.cs @@ -30,6 +30,12 @@ public class ApiException : Exception /// The error content (Http response body). public object ErrorContent { get; private set; } + /// + /// Gets or sets the HTTP headers + /// + /// HTTP headers + public Multimap Headers { get; private set; } + /// /// Initializes a new instance of the class. /// @@ -51,10 +57,12 @@ public ApiException(int errorCode, string message) : base(message) /// HTTP status code. /// Error message. /// Error content. - public ApiException(int errorCode, string message, object errorContent = null) : base(message) + /// HTTP Headers. + public ApiException(int errorCode, string message, object errorContent = null, Multimap headers = null) : base(message) { this.ErrorCode = errorCode; this.ErrorContent = errorContent; + this.Headers = headers; } } diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Client/Configuration.cs b/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Client/Configuration.cs index df843dad2c8d..04c4bb2b3edd 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Client/Configuration.cs +++ b/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Client/Configuration.cs @@ -54,7 +54,7 @@ public class Configuration : IReadableConfiguration { return new ApiException(status, string.Format("Error calling {0}: {1}", methodName, response.RawContent), - response.RawContent); + response.RawContent, response.Headers); } if (status == 0) {