Skip to content

Commit b35a7b6

Browse files
committed
Merge pull request #1127 from ivanmartinvalle/master
Add status code and response headers of the last request to java and c#
2 parents 587028e + 52dc7e2 commit b35a7b6

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public class ApiClient {
4949
5050
private Map<String, Authentication> authentications;
5151
52+
private int statusCode;
53+
private Map<String, List<String>> responseHeaders;
54+
5255
private DateFormat dateFormat;
5356
5457
public ApiClient() {
@@ -80,6 +83,20 @@ public class ApiClient {
8083
return this;
8184
}
8285

86+
/**
87+
* Gets the status code of the previous request
88+
*/
89+
public int getStatusCode() {
90+
return statusCode;
91+
}
92+
93+
/**
94+
* Gets the response headers of the previous request
95+
*/
96+
public Map<String, List<String>> getResponseHeaders() {
97+
return responseHeaders;
98+
}
99+
83100
/**
84101
* Get authentications (key: authentication name, value: authentication).
85102
*/
@@ -494,6 +511,9 @@ public class ApiClient {
494511
495512
ClientResponse response = getAPIResponse(path, method, queryParams, body, binaryBody, headerParams, formParams, accept, contentType, authNames);
496513
514+
statusCode = response.getStatusInfo().getStatusCode();
515+
responseHeaders = response.getHeaders();
516+
497517
if(response.getStatusInfo() == ClientResponse.Status.NO_CONTENT) {
498518
return null;
499519
} else if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {

modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ namespace {{packageName}}.Client
4949
{
5050
get { return _defaultHeaderMap; }
5151
}
52+
53+
/// <summary>
54+
/// Gets the status code of the previous request
55+
/// </summary>
56+
public int StatusCode { get; private set; }
57+
58+
/// <summary>
59+
/// Gets the response headers of the previous request
60+
/// </summary>
61+
public Dictionary<String, String> ResponseHeaders { get; private set; }
5262

5363
// Creates and sets up a RestRequest prior to a call.
5464
private RestRequest PrepareRequest(
@@ -110,7 +120,10 @@ namespace {{packageName}}.Client
110120
{
111121
var request = PrepareRequest(
112122
path, method, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings);
113-
return (Object)RestClient.Execute(request);
123+
var response = RestClient.Execute(request);
124+
StatusCode = (int) response.StatusCode;
125+
ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString());
126+
return (Object) response;
114127
}
115128

116129
/// <summary>
@@ -133,7 +146,10 @@ namespace {{packageName}}.Client
133146
{
134147
var request = PrepareRequest(
135148
path, method, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings);
136-
return (Object) await RestClient.ExecuteTaskAsync(request);
149+
var response = await RestClient.ExecuteTaskAsync(request);
150+
StatusCode = (int)response.StatusCode;
151+
ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString());
152+
return (Object)response;
137153
}
138154

139155
/// <summary>

0 commit comments

Comments
 (0)