Add status code and response headers of the last request to java and csharp templates per #990

This commit is contained in:
ivanmartinvalle 2015-08-24 18:29:01 -05:00
parent 15e336b90a
commit 52dc7e210c
2 changed files with 38 additions and 2 deletions

View File

@ -49,6 +49,9 @@ public class ApiClient {
private Map<String, Authentication> authentications;
private int statusCode;
private Map<String, List<String>> 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<String, List<String>> 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) {

View File

@ -49,6 +49,16 @@ namespace {{packageName}}.Client
{
get { return _defaultHeaderMap; }
}
/// <summary>
/// Gets the status code of the previous request
/// </summary>
public int StatusCode { get; private set; }
/// <summary>
/// Gets the response headers of the previous request
/// </summary>
public Dictionary<String, String> 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;
}
/// <summary>
@ -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;
}
/// <summary>