forked from loafle/openapi-generator-original
Add status code and response headers of the last request to java and csharp templates per #990
This commit is contained in:
parent
15e336b90a
commit
52dc7e210c
@ -49,6 +49,9 @@ public class ApiClient {
|
|||||||
|
|
||||||
private Map<String, Authentication> authentications;
|
private Map<String, Authentication> authentications;
|
||||||
|
|
||||||
|
private int statusCode;
|
||||||
|
private Map<String, List<String>> responseHeaders;
|
||||||
|
|
||||||
private DateFormat dateFormat;
|
private DateFormat dateFormat;
|
||||||
|
|
||||||
public ApiClient() {
|
public ApiClient() {
|
||||||
@ -80,6 +83,20 @@ public class ApiClient {
|
|||||||
return this;
|
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).
|
* 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);
|
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) {
|
if(response.getStatusInfo() == ClientResponse.Status.NO_CONTENT) {
|
||||||
return null;
|
return null;
|
||||||
} else if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
|
} else if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
|
||||||
|
@ -50,6 +50,16 @@ namespace {{packageName}}.Client
|
|||||||
get { return _defaultHeaderMap; }
|
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.
|
// Creates and sets up a RestRequest prior to a call.
|
||||||
private RestRequest PrepareRequest(
|
private RestRequest PrepareRequest(
|
||||||
String path, RestSharp.Method method, Dictionary<String, String> queryParams, String postBody,
|
String path, RestSharp.Method method, Dictionary<String, String> queryParams, String postBody,
|
||||||
@ -110,7 +120,10 @@ namespace {{packageName}}.Client
|
|||||||
{
|
{
|
||||||
var request = PrepareRequest(
|
var request = PrepareRequest(
|
||||||
path, method, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings);
|
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>
|
/// <summary>
|
||||||
@ -133,7 +146,10 @@ namespace {{packageName}}.Client
|
|||||||
{
|
{
|
||||||
var request = PrepareRequest(
|
var request = PrepareRequest(
|
||||||
path, method, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings);
|
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>
|
/// <summary>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user