forked from loafle/openapi-generator-original
207 lines
10 KiB
Plaintext
207 lines
10 KiB
Plaintext
using System;
|
|
using System.IO;
|
|
using System.Collections.Generic;
|
|
using RestSharp;
|
|
using {{packageName}}.Client;
|
|
{{#hasImport}}using {{packageName}}.Model;
|
|
{{/hasImport}}
|
|
|
|
namespace {{packageName}}.Api
|
|
{
|
|
{{#operations}}
|
|
/// <summary>
|
|
/// Represents a collection of functions to interact with the API endpoints
|
|
/// </summary>
|
|
public interface I{{classname}}
|
|
{
|
|
{{#operation}}
|
|
/// <summary>
|
|
/// {{summary}}
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// {{notes}}
|
|
/// </remarks>
|
|
{{#allParams}}/// <param name="{{paramName}}">{{description}}</param>
|
|
{{/allParams}}/// <returns>{{#returnType}}{{^returnContainer}}{{{returnType}}}{{/returnContainer}}{{/returnType}}</returns>
|
|
{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
|
|
|
|
/// <summary>
|
|
/// {{summary}}
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// {{notes}}
|
|
/// </remarks>
|
|
{{#allParams}}/// <param name="{{paramName}}">{{description}}</param>
|
|
{{/allParams}}/// <returns>{{#returnType}}{{^returnContainer}}{{{returnType}}}{{/returnContainer}}{{/returnType}}</returns>
|
|
{{#returnType}}System.Threading.Tasks.Task<{{{returnType}}}>{{/returnType}}{{^returnType}}System.Threading.Tasks.Task{{/returnType}} {{nickname}}Async ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
|
|
{{/operation}}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Represents a collection of functions to interact with the API endpoints
|
|
/// </summary>
|
|
public class {{classname}} : I{{classname}}
|
|
{
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="{{classname}}"/> class.
|
|
/// </summary>
|
|
/// <param name="apiClient"> an instance of ApiClient (optional)</param>
|
|
/// <returns></returns>
|
|
public {{classname}}(ApiClient apiClient = null)
|
|
{
|
|
if (apiClient == null) // use the default one in Configuration
|
|
this.ApiClient = Configuration.DefaultApiClient;
|
|
else
|
|
this.ApiClient = apiClient;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="{{classname}}"/> class.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public {{classname}}(String basePath)
|
|
{
|
|
this.ApiClient = new ApiClient(basePath);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the base path of the API client.
|
|
/// </summary>
|
|
/// <param name="basePath">The base path</param>
|
|
/// <value>The base path</value>
|
|
public void SetBasePath(String basePath)
|
|
{
|
|
this.ApiClient.BasePath = basePath;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the base path of the API client.
|
|
/// </summary>
|
|
/// <value>The base path</value>
|
|
public String GetBasePath()
|
|
{
|
|
return this.ApiClient.BasePath;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets the API client.
|
|
/// </summary>
|
|
/// <value>An instance of the ApiClient</value>
|
|
public ApiClient ApiClient {get; set;}
|
|
|
|
{{#operation}}
|
|
/// <summary>
|
|
/// {{summary}} {{notes}}
|
|
/// </summary>
|
|
{{#allParams}}/// <param name="{{paramName}}">{{description}}</param>
|
|
{{/allParams}}/// <returns>{{#returnType}}{{^returnContainer}}{{{returnType}}}{{/returnContainer}}{{/returnType}}</returns>
|
|
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}}";
|
|
|
|
var pathParams = new Dictionary<String, String>();
|
|
var queryParams = new Dictionary<String, String>();
|
|
var headerParams = new Dictionary<String, String>();
|
|
var formParams = new Dictionary<String, String>();
|
|
var fileParams = new Dictionary<String, FileParameter>();
|
|
String postBody = null;
|
|
|
|
// to determine the Accept header
|
|
String[] http_header_accepts = new String[] {
|
|
{{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}}
|
|
};
|
|
String http_header_accept = ApiClient.SelectHeaderAccept(http_header_accepts);
|
|
if (http_header_accept != null)
|
|
headerParams.Add("Accept", ApiClient.SelectHeaderAccept(http_header_accepts));
|
|
|
|
// set "format" to json by default
|
|
// e.g. /pet/{petId}.{format} becomes /pet/{petId}.json
|
|
pathParams.Add("format", "json");
|
|
{{#pathParams}}if ({{paramName}} != null) pathParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // path parameter
|
|
{{/pathParams}}
|
|
{{#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.ParameterToFile("{{baseName}}", {{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, pathParams, authSettings);
|
|
|
|
if (((int)response.StatusCode) >= 400)
|
|
throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.Content, response.Content);
|
|
else if (((int)response.StatusCode) == 0)
|
|
throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.ErrorMessage, response.ErrorMessage);
|
|
|
|
{{#returnType}}return ({{{returnType}}}) ApiClient.Deserialize(response.Content, typeof({{{returnType}}}), response.Headers);{{/returnType}}{{^returnType}}return;{{/returnType}}
|
|
}
|
|
|
|
/// <summary>
|
|
/// {{summary}} {{notes}}
|
|
/// </summary>
|
|
{{#allParams}}/// <param name="{{paramName}}">{{description}}</param>
|
|
{{/allParams}}/// <returns>{{#returnType}}{{^returnContainer}}{{{returnType}}}{{/returnContainer}}{{/returnType}}</returns>
|
|
{{#returnType}}public async System.Threading.Tasks.Task<{{{returnType}}}>{{/returnType}}{{^returnType}}public async System.Threading.Tasks.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}}";
|
|
|
|
var pathParams = new Dictionary<String, String>();
|
|
var queryParams = new Dictionary<String, String>();
|
|
var headerParams = new Dictionary<String, String>();
|
|
var formParams = new Dictionary<String, String>();
|
|
var fileParams = new Dictionary<String, FileParameter>();
|
|
String postBody = null;
|
|
|
|
// to determine the Accept header
|
|
String[] http_header_accepts = new String[] {
|
|
{{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}}
|
|
};
|
|
String http_header_accept = ApiClient.SelectHeaderAccept(http_header_accepts);
|
|
if (http_header_accept != null)
|
|
headerParams.Add("Accept", ApiClient.SelectHeaderAccept(http_header_accepts));
|
|
|
|
// set "format" to json by default
|
|
// e.g. /pet/{petId}.{format} becomes /pet/{petId}.json
|
|
pathParams.Add("format", "json");
|
|
{{#pathParams}}if ({{paramName}} != null) pathParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // path parameter
|
|
{{/pathParams}}
|
|
{{#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.ParameterToFile("{{baseName}}", {{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, pathParams, 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}}
|
|
}
|