using System;
using System.IO;
using System.Collections.Generic;
using System.Threading.Tasks;
using RestSharp;
using {{packageName}}.Client;
using {{packageName}}.Model;
{{#imports}}
{{/imports}}
namespace {{packageName}}.Api {
{{#operations}}
public interface I{{classname}} {
{{#operation}}
///
/// {{summary}} {{notes}}
///
{{#allParams}}/// {{description}}
{{/allParams}}{{#returnType}}/// {{{returnType}}}{{/returnType}}
{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
///
/// {{summary}} {{notes}}
///
{{#allParams}}/// {{description}}
{{/allParams}}{{#returnType}}/// {{{returnType}}}{{/returnType}}
{{#returnType}}Task<{{{returnType}}}>{{/returnType}}{{^returnType}}Task{{/returnType}} {{nickname}}Async ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
{{/operation}}
}
///
/// Represents a collection of functions to interact with the API endpoints
///
public class {{classname}} : I{{classname}} {
///
/// Initializes a new instance of the class.
///
/// an instance of ApiClient (optional)
///
public {{classname}}(ApiClient apiClient = null) {
if (apiClient == null) { // use the default one in Configuration
this.ApiClient = Configuration.DefaultApiClient;
} else {
this.ApiClient = apiClient;
}
}
///
/// Initializes a new instance of the class.
///
///
public {{classname}}(String basePath)
{
this.ApiClient = new ApiClient(basePath);
}
///
/// Sets the base path of the API client.
///
/// The base path
public void SetBasePath(String basePath) {
this.ApiClient.BasePath = basePath;
}
///
/// Gets the base path of the API client.
///
/// The base path
public String GetBasePath(String basePath) {
return this.ApiClient.BasePath;
}
///
/// Gets or sets the API client.
///
/// The API client
public ApiClient ApiClient {get; set;}
{{#operation}}
///
/// {{summary}} {{notes}}
///
{{#allParams}}/// {{description}}
{{/allParams}}{{#returnType}}/// {{{returnType}}}{{/returnType}}
public {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {
{{#allParams}}{{#required}}
// verify the required parameter '{{paramName}}' is set
if ({{paramName}} == null) throw new ApiException(400, "Missing required parameter '{{paramName}}' when calling {{nickname}}");
{{/required}}{{/allParams}}
var path = "{{path}}";
path = path.Replace("{format}", "json");
{{#pathParams}}path = path.Replace("{" + "{{baseName}}" + "}", ApiClient.ParameterToString({{{paramName}}}));
{{/pathParams}}
var queryParams = new Dictionary();
var headerParams = new Dictionary();
var formParams = new Dictionary();
var fileParams = new Dictionary();
String postBody = null;
{{#queryParams}} if ({{paramName}} != null) queryParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // query parameter
{{/queryParams}}
{{#headerParams}} if ({{paramName}} != null) headerParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // header parameter
{{/headerParams}}
{{#formParams}}if ({{paramName}} != null) {{#isFile}}fileParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}}));{{/isFile}}{{^isFile}}formParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // form parameter{{/isFile}}
{{/formParams}}
{{#bodyParam}}postBody = ApiClient.Serialize({{paramName}}); // http body (model) parameter
{{/bodyParam}}
// authentication setting, if any
String[] authSettings = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} };
// make the HTTP request
IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.{{httpMethod}}, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.Content, response.Content);
}
{{#returnType}} // if return type is "String" (not "string"), it implies a Filestream and should return the file path
String returnTypeString = "{{{returnType}}}";
Type returnType = returnTypeString == "String" ? typeof(FileStream) : typeof({{{returnType}}});
return ({{{returnType}}}) ApiClient.Deserialize(response.Content, returnType, response.Headers);{{/returnType}}{{^returnType}}return;{{/returnType}}
}
///
/// {{summary}} {{notes}}
///
{{#allParams}}/// {{description}}
{{/allParams}}{{#returnType}}/// {{{returnType}}}{{/returnType}}
public async {{#returnType}}Task<{{{returnType}}}>{{/returnType}}{{^returnType}}Task{{/returnType}} {{nickname}}Async ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {
{{#allParams}}{{#required}}
// verify the required parameter '{{paramName}}' is set
if ({{paramName}} == null) throw new ApiException(400, "Missing required parameter '{{paramName}}' when calling {{nickname}}");
{{/required}}{{/allParams}}
var path = "{{path}}";
path = path.Replace("{format}", "json");
{{#pathParams}}path = path.Replace("{" + "{{baseName}}" + "}", ApiClient.ParameterToString({{{paramName}}}));
{{/pathParams}}
var queryParams = new Dictionary();
var headerParams = new Dictionary();
var formParams = new Dictionary();
var fileParams = new Dictionary();
String postBody = null;
{{#queryParams}} if ({{paramName}} != null) queryParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // query parameter
{{/queryParams}}
{{#headerParams}} if ({{paramName}} != null) headerParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // header parameter
{{/headerParams}}
{{#formParams}}if ({{paramName}} != null) {{#isFile}}fileParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}}));{{/isFile}}{{^isFile}}formParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // form parameter{{/isFile}}
{{/formParams}}
{{#bodyParam}}postBody = ApiClient.Serialize({{paramName}}); // http body (model) parameter
{{/bodyParam}}
// authentication setting, if any
String[] authSettings = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} };
// make the HTTP request
IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.{{httpMethod}}, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.Content, response.Content);
}
{{#returnType}}return ({{{returnType}}}) ApiClient.Deserialize(response.Content, typeof({{{returnType}}}), response.Headers);{{/returnType}}{{^returnType}}
return;{{/returnType}}
}
{{/operation}}
}
{{/operations}}
}