Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/main/resources/csharp/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,23 @@
namespace {{package}} {
{{#operations}}
public class {{classname}} {
string basePath = "{{basePath}}";
string basePath;
private readonly ApiInvoker apiInvoker = ApiInvoker.GetInstance();

public {{classname}}(String basePath = "{{basePath}}")
{
this.basePath = basePath;
}

public ApiInvoker getInvoker() {
return apiInvoker;
}

// Sets the endpoint base url for the services being accessed
public void setBasePath(string basePath) {
this.basePath = basePath;
}

// Gets the endpoint base url for the services being accessed
public String getBasePath() {
return basePath;
Expand Down
15 changes: 10 additions & 5 deletions src/main/resources/csharp/apiInvoker.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public static ApiInvoker GetInstance() {
return _instance;
}

public void addDefaultHeader(string key, string value) {
defaultHeaderMap.Add(key, value);
}
Expand Down Expand Up @@ -46,7 +46,7 @@

public string invokeAPI(string host, string path, string method, Dictionary<String, String> queryParams, object body, Dictionary<String, String> headerParams) {
var b = new StringBuilder();

foreach (var queryParamItem in queryParams)
{
var value = queryParamItem.Value;
Expand All @@ -71,7 +71,7 @@
{
client.Headers.Add(defaultHeaderMapItem.Key, defaultHeaderMapItem.Value);
}

switch (method)
{
case "GET":
Expand All @@ -84,13 +84,17 @@
swRequestWriter.Close();
break;
default:
throw new ApiException(500, "unknown method type " + method);
throw new ApiException(500, "unknown method type " + method);
}

try
{
var webResponse = (HttpWebResponse)client.GetResponse();
if (webResponse.StatusCode != HttpStatusCode.OK) throw new ApiException((int)webResponse.StatusCode, webResponse.StatusDescription);
if (webResponse.StatusCode != HttpStatusCode.OK)
{
webResponse.Close();
throw new ApiException((int)webResponse.StatusCode, webResponse.StatusDescription);
}

var responseReader = new StreamReader(webResponse.GetResponseStream());
var responseData = responseReader.ReadToEnd();
Expand All @@ -104,6 +108,7 @@
if (response != null)
{
statusCode = (int)response.StatusCode;
response.Close();
}
throw new ApiException(statusCode, ex.Message);
}
Expand Down