diff --git a/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache index 1a0dc5bc3a7..5e18c854cba 100644 --- a/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache @@ -49,6 +49,9 @@ public class ApiClient { private Map authentications; + private int statusCode; + private Map> responseHeaders; + private DateFormat dateFormat; public ApiClient() { @@ -80,6 +83,20 @@ public class ApiClient { return this; } + /** + * Gets the status code of the previous request + */ + public int getStatusCode() { + return statusCode; + } + + /** + * Gets the response headers of the previous request + */ + public Map> getResponseHeaders() { + return responseHeaders; + } + /** * Get authentications (key: authentication name, value: authentication). */ @@ -494,6 +511,9 @@ public class ApiClient { ClientResponse response = getAPIResponse(path, method, queryParams, body, binaryBody, headerParams, formParams, accept, contentType, authNames); + statusCode = response.getStatusInfo().getStatusCode(); + responseHeaders = response.getHeaders(); + if(response.getStatusInfo() == ClientResponse.Status.NO_CONTENT) { return null; } else if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) { diff --git a/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache index c93537a740d..b74ab56ea10 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache @@ -49,6 +49,16 @@ namespace {{packageName}}.Client { get { return _defaultHeaderMap; } } + + /// + /// Gets the status code of the previous request + /// + public int StatusCode { get; private set; } + + /// + /// Gets the response headers of the previous request + /// + public Dictionary ResponseHeaders { get; private set; } // Creates and sets up a RestRequest prior to a call. private RestRequest PrepareRequest( @@ -110,7 +120,10 @@ namespace {{packageName}}.Client { var request = PrepareRequest( path, method, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings); - return (Object)RestClient.Execute(request); + var response = RestClient.Execute(request); + StatusCode = (int) response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); + return (Object) response; } /// @@ -133,7 +146,10 @@ namespace {{packageName}}.Client { var request = PrepareRequest( path, method, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings); - return (Object) await RestClient.ExecuteTaskAsync(request); + var response = await RestClient.ExecuteTaskAsync(request); + StatusCode = (int)response.StatusCode; + ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()); + return (Object)response; } ///