forked from loafle/openapi-generator-original
WIP pre-adding new sources for ApiClient and api
This commit is contained in:
parent
4b896c759c
commit
4bc4a8aed1
@ -1,202 +1,466 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Web;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using RestSharp;
|
using RestSharp;
|
||||||
|
using RestSharp.Extensions;
|
||||||
|
|
||||||
namespace {{packageName}}.Client {
|
namespace {{packageName}}.Client
|
||||||
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// API client is mainly responible for making the HTTP call to the API backend
|
/// API client is mainly responible for making the HTTP call to the API backend.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ApiClient {
|
public class ApiClient
|
||||||
|
{
|
||||||
|
private readonly Dictionary<String, String> _defaultHeaderMap = new Dictionary<String, String>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ApiClient" /> class.
|
/// Initializes a new instance of the <see cref="ApiClient" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="basePath">The base path.</param>
|
/// <param name="basePath">The base path.</param>
|
||||||
public ApiClient(String basePath="{{basePath}}") {
|
public ApiClient(String basePath="{{basePath}}")
|
||||||
this.basePath = basePath;
|
{
|
||||||
this.restClient = new RestClient(this.basePath);
|
BasePath = basePath;
|
||||||
|
RestClient = new RestClient(BasePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the base path.
|
/// Gets or sets the base path.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The base path.</value>
|
/// <value>The base path</value>
|
||||||
public string basePath { get; set; }
|
public string BasePath { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the RestClient
|
/// Gets or sets the RestClient.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The RestClient.</value>
|
/// <value>An instance of the RestClient</value>
|
||||||
public RestClient restClient { get; set; }
|
public RestClient RestClient { get; set; }
|
||||||
|
|
||||||
private Dictionary<String, String> defaultHeaderMap = new Dictionary<String, String>();
|
/// <summary>
|
||||||
|
/// Gets the default header.
|
||||||
public Object CallApi(String Path, RestSharp.Method Method, Dictionary<String, String> QueryParams, String PostBody,
|
/// </summary>
|
||||||
Dictionary<String, String> HeaderParams, Dictionary<String, String> FormParams, Dictionary<String, String> FileParams, Dictionary<String, String> PathParams, String[] AuthSettings) {
|
public Dictionary<String, String> DefaultHeader
|
||||||
var response = Task.Run(async () => {
|
{
|
||||||
var resp = await CallApiAsync(Path, Method, QueryParams, PostBody, HeaderParams, FormParams, FileParams, PathParams, AuthSettings);
|
get { return _defaultHeaderMap; }
|
||||||
return resp;
|
|
||||||
});
|
|
||||||
return response.Result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Object> CallApiAsync(String Path, RestSharp.Method Method, Dictionary<String, String> QueryParams, String PostBody,
|
<<<<<<< HEAD
|
||||||
Dictionary<String, String> HeaderParams, Dictionary<String, String> FormParams, Dictionary<String, String> FileParams, Dictionary<String, String> PathParams, String[] AuthSettings) {
|
// Creates and sets up a RestRequest prior to a call.
|
||||||
|
private RestRequest PrepareRequest(
|
||||||
|
String path, RestSharp.Method method, Dictionary<String, String> queryParams, String postBody,
|
||||||
|
Dictionary<String, String> headerParams, Dictionary<String, String> formParams,
|
||||||
|
Dictionary<String, FileParameter> fileParams, Dictionary<String, String> pathParams, String[] authSettings)
|
||||||
|
{
|
||||||
|
var request = new RestRequest(path, method);
|
||||||
|
|
||||||
var request = new RestRequest(Path, Method);
|
UpdateParamsForAuth(queryParams, headerParams, authSettings);
|
||||||
|
|
||||||
UpdateParamsForAuth(QueryParams, HeaderParams, AuthSettings);
|
|
||||||
|
|
||||||
// add default header, if any
|
// add default header, if any
|
||||||
foreach(KeyValuePair<string, string> defaultHeader in this.defaultHeaderMap)
|
foreach(var defaultHeader in _defaultHeaderMap)
|
||||||
request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
||||||
|
|
||||||
// add path parameter, if any
|
// add path parameter, if any
|
||||||
foreach(KeyValuePair<string, string> param in PathParams)
|
foreach(var param in pathParams)
|
||||||
request.AddParameter(param.Key, param.Value, ParameterType.UrlSegment);
|
request.AddParameter(param.Key, param.Value, ParameterType.UrlSegment);
|
||||||
|
|
||||||
// add header parameter, if any
|
// add header parameter, if any
|
||||||
foreach(KeyValuePair<string, string> param in HeaderParams)
|
foreach(var param in headerParams)
|
||||||
request.AddHeader(param.Key, param.Value);
|
request.AddHeader(param.Key, param.Value);
|
||||||
|
|
||||||
// add query parameter, if any
|
// add query parameter, if any
|
||||||
foreach(KeyValuePair<string, string> param in QueryParams)
|
foreach(var param in queryParams)
|
||||||
request.AddQueryParameter(param.Key, param.Value);
|
request.AddQueryParameter(param.Key, param.Value);
|
||||||
|
|
||||||
// add form parameter, if any
|
// add form parameter, if any
|
||||||
foreach(KeyValuePair<string, string> param in FormParams)
|
foreach(var param in formParams)
|
||||||
request.AddParameter(param.Key, param.Value);
|
request.AddParameter(param.Key, param.Value);
|
||||||
|
|
||||||
// add file parameter, if any
|
// add file parameter, if any
|
||||||
foreach(KeyValuePair<string, string> param in FileParams)
|
foreach(var param in fileParams)
|
||||||
request.AddFile(param.Key, param.Value);
|
request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType);
|
||||||
|
|
||||||
if (PostBody != null) {
|
if (postBody != null) // http body (model) parameter
|
||||||
request.AddParameter("application/json", PostBody, ParameterType.RequestBody); // http body (model) parameter
|
request.AddParameter("application/json", postBody, ParameterType.RequestBody);
|
||||||
}
|
|
||||||
|
|
||||||
return (Object) await restClient.ExecuteTaskAsync(request);
|
|
||||||
|
|
||||||
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add default header
|
/// Makes the HTTP request (Sync).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="key"> Header field name
|
/// <param name="path">URL path.</param>
|
||||||
/// <param name="value"> Header field value
|
/// <param name="method">HTTP method.</param>
|
||||||
|
/// <param name="queryParams">Query parameters.</param>
|
||||||
|
/// <param name="postBody">HTTP body (POST request).</param>
|
||||||
|
/// <param name="headerParams">Header parameters.</param>
|
||||||
|
/// <param name="formParams">Form parameters.</param>
|
||||||
|
/// <param name="fileParams">File parameters.</param>
|
||||||
|
/// <param name="pathParams">Path parameters.</param>
|
||||||
|
/// <param name="authSettings">Authentication settings.</param>
|
||||||
|
/// <returns>Object</returns>
|
||||||
|
public Object CallApi(
|
||||||
|
String path, RestSharp.Method method, Dictionary<String, String> queryParams, String postBody,
|
||||||
|
Dictionary<String, String> headerParams, Dictionary<String, String> formParams,
|
||||||
|
Dictionary<String, FileParameter> fileParams, Dictionary<String, String> pathParams, String[] authSettings)
|
||||||
|
{
|
||||||
|
var request = PrepareRequest(
|
||||||
|
path, method, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings);
|
||||||
|
return (Object)RestClient.Execute(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Makes the asynchronous HTTP request.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">URL path.</param>
|
||||||
|
/// <param name="method">HTTP method.</param>
|
||||||
|
/// <param name="queryParams">Query parameters.</param>
|
||||||
|
/// <param name="postBody">HTTP body (POST request).</param>
|
||||||
|
/// <param name="headerParams">Header parameters.</param>
|
||||||
|
/// <param name="formParams">Form parameters.</param>
|
||||||
|
/// <param name="fileParams">File parameters.</param>
|
||||||
|
/// <param name="pathParams">Path parameters.</param>
|
||||||
|
/// <param name="authSettings">Authentication settings.</param>
|
||||||
|
/// <returns>The Task instance.</returns>
|
||||||
|
public async System.Threading.Tasks.Task<Object> CallApiAsync(
|
||||||
|
String path, RestSharp.Method method, Dictionary<String, String> queryParams, String postBody,
|
||||||
|
Dictionary<String, String> headerParams, Dictionary<String, String> formParams,
|
||||||
|
Dictionary<String, FileParameter> fileParams, Dictionary<String, String> pathParams, String[] authSettings)
|
||||||
|
{
|
||||||
|
var request = PrepareRequest(
|
||||||
|
path, method, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings);
|
||||||
|
return (Object) await RestClient.ExecuteTaskAsync(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add default header.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key">Header field name.</param>
|
||||||
|
/// <param name="value">Header field value.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public void AddDefaultHeader(string key, string value) {
|
public void AddDefaultHeader(string key, string value)
|
||||||
defaultHeaderMap.Add(key, value);
|
{
|
||||||
|
_defaultHeaderMap.Add(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get default header
|
/// Escape string (url-encoded).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Dictionary of default header</returns>
|
/// <param name="str">String to be escaped.</param>
|
||||||
public Dictionary<String, String> GetDefaultHeader() {
|
/// <returns>Escaped string.</returns>
|
||||||
return defaultHeaderMap;
|
public string EscapeString(string str)
|
||||||
|
{
|
||||||
|
return HttpUtility.UrlEncode(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// escape string (url-encoded)
|
/// Create FileParameter based on Stream.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="str"> String to be escaped
|
/// <param name="name">Parameter name.</param>
|
||||||
/// <returns>Escaped string</returns>
|
/// <param name="stream">Input stream.</param>
|
||||||
public string EscapeString(string str) {
|
/// <returns>FileParameter.</returns>
|
||||||
return str;
|
public FileParameter ParameterToFile(string name, Stream stream)
|
||||||
|
{
|
||||||
|
if (stream is FileStream)
|
||||||
|
return FileParameter.Create(name, stream.ReadAsBytes(), Path.GetFileName(((FileStream)stream).Name));
|
||||||
|
else
|
||||||
|
return FileParameter.Create(name, stream.ReadAsBytes(), "no_file_name_provided");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// if parameter is DateTime, output in ISO8601 format
|
/// If parameter is DateTime, output in ISO8601 format.
|
||||||
/// if parameter is a list of string, join the list with ","
|
/// If parameter is a list of string, join the list with ",".
|
||||||
/// otherwise just return the string
|
/// Otherwise just return the string.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="obj"> The parameter (header, path, query, form)
|
/// <param name="obj">The parameter (header, path, query, form).</param>
|
||||||
/// <returns>Formatted string</returns>
|
/// <returns>Formatted string.</returns>
|
||||||
public string ParameterToString(object obj)
|
public string ParameterToString(object obj)
|
||||||
{
|
{
|
||||||
if (obj is DateTime) {
|
if (obj is DateTime)
|
||||||
return ((DateTime)obj).ToString ("u");
|
return ((DateTime)obj).ToString ("u");
|
||||||
} else if (obj is List<string>) {
|
else if (obj is List<string>)
|
||||||
return String.Join(",", obj as List<string>);
|
return String.Join(",", obj as List<string>);
|
||||||
} else {
|
else
|
||||||
return Convert.ToString (obj);
|
return Convert.ToString (obj);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deserialize the JSON string into a proper object
|
/// Deserialize the JSON string into a proper object.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="json"> JSON string
|
/// <param name="content">HTTP body (e.g. string, JSON).</param>
|
||||||
/// <param name="type"> Object type
|
/// <param name="type">Object type.</param>
|
||||||
/// <returns>Object representation of the JSON string</returns>
|
/// <returns>Object representation of the JSON string.</returns>
|
||||||
public object Deserialize(string content, Type type) {
|
public object Deserialize(string content, Type type, IList<Parameter> headers=null)
|
||||||
if (type.GetType() == typeof(Object))
|
{
|
||||||
return (Object)content;
|
if (type == typeof(Object)) // return an object
|
||||||
|
{
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == typeof(Stream))
|
||||||
|
{
|
||||||
|
var filePath = String.IsNullOrEmpty(Configuration.TempFolderPath)
|
||||||
|
? Path.GetTempPath()
|
||||||
|
: Configuration.TempFolderPath;
|
||||||
|
|
||||||
|
=======
|
||||||
|
/// <summary>
|
||||||
|
/// Makes the HTTP request (Sync).
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">URL path.</param>
|
||||||
|
/// <param name="method">HTTP method.</param>
|
||||||
|
/// <param name="queryParams">Query parameters.</param>
|
||||||
|
/// <param name="postBody">HTTP body (POST request).</param>
|
||||||
|
/// <param name="headerParams">Header parameters.</param>
|
||||||
|
/// <param name="formParams">Form parameters.</param>
|
||||||
|
/// <param name="fileParams">File parameters.</param>
|
||||||
|
/// <param name="authSettings">Authentication settings.</param>
|
||||||
|
/// <returns>Object</returns>
|
||||||
|
public Object CallApi(String path, RestSharp.Method method, Dictionary<String, String> queryParams, String postBody,
|
||||||
|
Dictionary<String, String> headerParams, Dictionary<String, String> formParams,
|
||||||
|
Dictionary<String, FileParameter> fileParams, String[] authSettings)
|
||||||
|
{
|
||||||
|
|
||||||
|
var request = new RestRequest(path, method);
|
||||||
|
|
||||||
|
UpdateParamsForAuth(queryParams, headerParams, authSettings);
|
||||||
|
|
||||||
|
// add default header, if any
|
||||||
|
foreach(var defaultHeader in _defaultHeaderMap)
|
||||||
|
request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
||||||
|
|
||||||
|
// add header parameter, if any
|
||||||
|
foreach(var param in headerParams)
|
||||||
|
request.AddHeader(param.Key, param.Value);
|
||||||
|
|
||||||
|
// add query parameter, if any
|
||||||
|
foreach(var param in queryParams)
|
||||||
|
request.AddQueryParameter(param.Key, param.Value);
|
||||||
|
|
||||||
|
// add form parameter, if any
|
||||||
|
foreach(var param in formParams)
|
||||||
|
request.AddParameter(param.Key, param.Value);
|
||||||
|
|
||||||
|
// add file parameter, if any
|
||||||
|
foreach(var param in fileParams)
|
||||||
|
request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType);
|
||||||
|
|
||||||
|
if (postBody != null) // http body (model) parameter
|
||||||
|
request.AddParameter("application/json", postBody, ParameterType.RequestBody);
|
||||||
|
|
||||||
|
return (Object)RestClient.Execute(request);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Makes the asynchronous HTTP request.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">URL path.</param>
|
||||||
|
/// <param name="method">HTTP method.</param>
|
||||||
|
/// <param name="queryParams">Query parameters.</param>
|
||||||
|
/// <param name="postBody">HTTP body (POST request).</param>
|
||||||
|
/// <param name="headerParams">Header parameters.</param>
|
||||||
|
/// <param name="formParams">Form parameters.</param>
|
||||||
|
/// <param name="fileParams">File parameters.</param>
|
||||||
|
/// <param name="authSettings">Authentication settings.</param>
|
||||||
|
/// <returns>The Task instance.</returns>
|
||||||
|
public async System.Threading.Tasks.Task<Object> CallApiAsync(String path, RestSharp.Method method, Dictionary<String, String> queryParams, String postBody,
|
||||||
|
Dictionary<String, String> headerParams, Dictionary<String, String> formParams, Dictionary<String, FileParameter> fileParams, String[] authSettings)
|
||||||
|
{
|
||||||
|
|
||||||
|
var request = new RestRequest(path, method);
|
||||||
|
|
||||||
|
UpdateParamsForAuth(queryParams, headerParams, authSettings);
|
||||||
|
|
||||||
|
// add default header, if any
|
||||||
|
foreach(var defaultHeader in _defaultHeaderMap)
|
||||||
|
request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
||||||
|
|
||||||
|
// add header parameter, if any
|
||||||
|
foreach(var param in headerParams)
|
||||||
|
request.AddHeader(param.Key, param.Value);
|
||||||
|
|
||||||
|
// add query parameter, if any
|
||||||
|
foreach(var param in queryParams)
|
||||||
|
request.AddQueryParameter(param.Key, param.Value);
|
||||||
|
|
||||||
|
// add form parameter, if any
|
||||||
|
foreach(var param in formParams)
|
||||||
|
request.AddParameter(param.Key, param.Value);
|
||||||
|
|
||||||
|
// add file parameter, if any
|
||||||
|
foreach(var param in fileParams)
|
||||||
|
request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType);
|
||||||
|
|
||||||
|
if (postBody != null) // http body (model) parameter
|
||||||
|
request.AddParameter("application/json", postBody, ParameterType.RequestBody);
|
||||||
|
|
||||||
|
return (Object) await RestClient.ExecuteTaskAsync(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add default header.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key">Header field name.</param>
|
||||||
|
/// <param name="value">Header field value.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public void AddDefaultHeader(string key, string value)
|
||||||
|
{
|
||||||
|
_defaultHeaderMap.Add(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Escape string (url-encoded).
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="str">String to be escaped.</param>
|
||||||
|
/// <returns>Escaped string.</returns>
|
||||||
|
public string EscapeString(string str)
|
||||||
|
{
|
||||||
|
return HttpUtility.UrlEncode(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create FileParameter based on Stream.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Parameter name.</param>
|
||||||
|
/// <param name="stream">Input stream.</param>
|
||||||
|
/// <returns>FileParameter.</returns>
|
||||||
|
public FileParameter ParameterToFile(string name, Stream stream)
|
||||||
|
{
|
||||||
|
if (stream is FileStream)
|
||||||
|
return FileParameter.Create(name, stream.ReadAsBytes(), Path.GetFileName(((FileStream)stream).Name));
|
||||||
|
else
|
||||||
|
return FileParameter.Create(name, stream.ReadAsBytes(), "no_file_name_provided");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// If parameter is DateTime, output in ISO8601 format.
|
||||||
|
/// If parameter is a list of string, join the list with ",".
|
||||||
|
/// Otherwise just return the string.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">The parameter (header, path, query, form).</param>
|
||||||
|
/// <returns>Formatted string.</returns>
|
||||||
|
public string ParameterToString(object obj)
|
||||||
|
{
|
||||||
|
if (obj is DateTime)
|
||||||
|
return ((DateTime)obj).ToString ("u");
|
||||||
|
else if (obj is List<string>)
|
||||||
|
return String.Join(",", obj as List<string>);
|
||||||
|
else
|
||||||
|
return Convert.ToString (obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deserialize the JSON string into a proper object.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="content">HTTP body (e.g. string, JSON).</param>
|
||||||
|
/// <param name="type">Object type.</param>
|
||||||
|
/// <returns>Object representation of the JSON string.</returns>
|
||||||
|
public object Deserialize(string content, Type type, IList<Parameter> headers=null)
|
||||||
|
{
|
||||||
|
if (type == typeof(Object)) // return an object
|
||||||
|
{
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == typeof(Stream))
|
||||||
|
{
|
||||||
|
var filePath = String.IsNullOrEmpty(Configuration.TempFolderPath)
|
||||||
|
? Path.GetTempPath()
|
||||||
|
: Configuration.TempFolderPath;
|
||||||
|
|
||||||
|
>>>>>>> e879268043b53fe30ea0238807b9519687c1e5f2
|
||||||
|
var fileName = filePath + Guid.NewGuid();
|
||||||
|
if (headers != null)
|
||||||
|
{
|
||||||
|
var regex = new Regex(@"Content-Disposition:.*filename=['""]?([^'""\s]+)['""]?$");
|
||||||
|
var match = regex.Match(headers.ToString());
|
||||||
|
if (match.Success)
|
||||||
|
fileName = filePath + match.Value.Replace("\"", "").Replace("'", "");
|
||||||
|
}
|
||||||
|
File.WriteAllText(fileName, content);
|
||||||
|
return new FileStream(fileName, FileMode.Open);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type.Name.StartsWith("System.Nullable`1[[System.DateTime")) // return a datetime object
|
||||||
|
{
|
||||||
|
return DateTime.Parse(content, null, System.Globalization.DateTimeStyles.RoundtripKind);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == typeof(String) || type.Name.StartsWith("System.Nullable")) // return primitive type
|
||||||
|
{
|
||||||
|
return ConvertType(content, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
// at this point, it must be a model (json)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return JsonConvert.DeserializeObject(content, type);
|
return JsonConvert.DeserializeObject(content, type);
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e)
|
||||||
|
{
|
||||||
throw new ApiException(500, e.Message);
|
throw new ApiException(500, e.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Serialize an object into JSON string
|
/// Serialize an object into JSON string.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="obj"> Object
|
/// <param name="obj">Object.</param>
|
||||||
/// <returns>JSON string</returns>
|
/// <returns>JSON string.</returns>
|
||||||
public string Serialize(object obj) {
|
public string Serialize(object obj)
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return obj != null ? JsonConvert.SerializeObject(obj) : null;
|
return obj != null ? JsonConvert.SerializeObject(obj) : null;
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e)
|
||||||
|
{
|
||||||
throw new ApiException(500, e.Message);
|
throw new ApiException(500, e.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the API key with prefix
|
/// Get the API key with prefix.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="obj"> Object
|
/// <param name="apiKeyIdentifier">API key identifier (authentication scheme).</param>
|
||||||
/// <returns>API key with prefix</returns>
|
/// <returns>API key with prefix.</returns>
|
||||||
public string GetApiKeyWithPrefix (string apiKey)
|
public string GetApiKeyWithPrefix (string apiKeyIdentifier)
|
||||||
{
|
{
|
||||||
var apiKeyValue = "";
|
var apiKeyValue = "";
|
||||||
Configuration.apiKey.TryGetValue (apiKey, out apiKeyValue);
|
Configuration.ApiKey.TryGetValue (apiKeyIdentifier, out apiKeyValue);
|
||||||
var apiKeyPrefix = "";
|
var apiKeyPrefix = "";
|
||||||
if (Configuration.apiKeyPrefix.TryGetValue (apiKey, out apiKeyPrefix)) {
|
if (Configuration.ApiKeyPrefix.TryGetValue (apiKeyIdentifier, out apiKeyPrefix))
|
||||||
return apiKeyPrefix + " " + apiKeyValue;
|
return apiKeyPrefix + " " + apiKeyValue;
|
||||||
} else {
|
else
|
||||||
return apiKeyValue;
|
return apiKeyValue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Update parameters based on authentication
|
/// Update parameters based on authentication.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="QueryParams">Query parameters</param>
|
/// <param name="queryParams">Query parameters.</param>
|
||||||
/// <param name="HeaderParams">Header parameters</param>
|
/// <param name="headerParams">Header parameters.</param>
|
||||||
/// <param name="AuthSettings">Authentication settings</param>
|
/// <param name="authSettings">Authentication settings.</param>
|
||||||
public void UpdateParamsForAuth(Dictionary<String, String> QueryParams, Dictionary<String, String> HeaderParams, string[] AuthSettings) {
|
public void UpdateParamsForAuth(Dictionary<String, String> queryParams, Dictionary<String, String> headerParams, string[] authSettings)
|
||||||
if (AuthSettings == null || AuthSettings.Length == 0)
|
{
|
||||||
|
if (authSettings == null || authSettings.Length == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (string auth in AuthSettings) {
|
foreach (string auth in authSettings)
|
||||||
|
{
|
||||||
// determine which one to use
|
// determine which one to use
|
||||||
switch(auth) {
|
switch(auth)
|
||||||
|
{
|
||||||
{{#authMethods}}
|
{{#authMethods}}
|
||||||
case "{{name}}":
|
case "{{name}}":
|
||||||
{{#isApiKey}}{{#isKeyInHeader}}HeaderParams["{{keyParamName}}"] = GetApiKeyWithPrefix("{{keyParamName}}");{{/isKeyInHeader}}{{#isKeyInQuery}}QueryParams["{{keyParamName}}"] = GetApiKeyWithPrefix("{{keyParamName}}");{{/isKeyInQuery}}{{/isApiKey}}{{#isBasic}}HeaderParams["Authorization"] = "Basic " + Base64Encode(Configuration.username + ":" + Configuration.password);{{/isBasic}}
|
{{#isApiKey}}{{#isKeyInHeader}}headerParams["{{keyParamName}}"] = GetApiKeyWithPrefix("{{keyParamName}}");{{/isKeyInHeader}}{{#isKeyInQuery}}queryParams["{{keyParamName}}"] = GetApiKeyWithPrefix("{{keyParamName}}");{{/isKeyInQuery}}{{/isApiKey}}{{#isBasic}}headerParams["Authorization"] = "Basic " + Base64Encode(Configuration.Username + ":" + Configuration.Password);{{/isBasic}}
|
||||||
{{#isOAuth}}//TODO support oauth{{/isOAuth}}
|
{{#isOAuth}}//TODO support oauth{{/isOAuth}}
|
||||||
break;
|
break;
|
||||||
{{/authMethods}}
|
{{/authMethods}}
|
||||||
@ -205,17 +469,29 @@ namespace {{packageName}}.Client {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Encode string in base64 format
|
/// Encode string in base64 format.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="text">String to be encoded</param>
|
/// <param name="text">String to be encoded.</param>
|
||||||
public static string Base64Encode(string text) {
|
/// <returns>Encoded string.</returns>
|
||||||
|
public static string Base64Encode(string text)
|
||||||
|
{
|
||||||
var textByte = System.Text.Encoding.UTF8.GetBytes(text);
|
var textByte = System.Text.Encoding.UTF8.GetBytes(text);
|
||||||
return System.Convert.ToBase64String(textByte);
|
return System.Convert.ToBase64String(textByte);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Dynamically cast the object into target type.
|
||||||
|
/// Ref: http://stackoverflow.com/questions/4925718/c-dynamic-runtime-cast
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source">Object to be casted</param>
|
||||||
|
/// <param name="dest">Target type</param>
|
||||||
|
/// <returns>Casted object</returns>
|
||||||
|
public static dynamic ConvertType(dynamic source, Type dest) {
|
||||||
|
return Convert.ChangeType(source, dest);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,49 +1,49 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using RestSharp;
|
using RestSharp;
|
||||||
using {{packageName}}.Client;
|
using {{packageName}}.Client;
|
||||||
using {{packageName}}.Model;
|
{{#hasImport}}using {{packageName}}.Model;
|
||||||
{{#imports}}
|
{{/hasImport}}
|
||||||
{{/imports}}
|
|
||||||
|
|
||||||
namespace {{packageName}}.Api {
|
namespace {{packageName}}.Api
|
||||||
|
{
|
||||||
{{#operations}}
|
{{#operations}}
|
||||||
|
public interface I{{classname}}
|
||||||
public interface I{{classname}} {
|
{
|
||||||
{{#operation}}
|
{{#operation}}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// {{summary}} {{notes}}
|
/// {{summary}} {{notes}}
|
||||||
/// </summary>
|
/// </summary>
|
||||||
{{#allParams}}/// <param name="{{paramName}}">{{description}}</param>{{/allParams}}
|
{{#allParams}}/// <param name="{{paramName}}">{{description}}</param>
|
||||||
/// <returns>{{#returnType}}{{{returnType}}}{{/returnType}}</returns>
|
{{/allParams}}/// <returns>{{#returnType}}{{{returnType}}}{{/returnType}}</returns>
|
||||||
{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
|
{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// {{summary}} {{notes}}
|
/// {{summary}} {{notes}}
|
||||||
/// </summary>
|
/// </summary>
|
||||||
{{#allParams}}/// <param name="{{paramName}}">{{description}}</param>{{/allParams}}
|
{{#allParams}}/// <param name="{{paramName}}">{{description}}</param>
|
||||||
/// <returns>{{#returnType}}{{{returnType}}}{{/returnType}}</returns>
|
{{/allParams}}/// <returns>{{#returnType}}{{{returnType}}}{{/returnType}}</returns>
|
||||||
{{#returnType}}Task<{{{returnType}}}>{{/returnType}}{{^returnType}}Task{{/returnType}} {{nickname}}Async ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
|
{{#returnType}}System.Threading.Tasks.Task<{{{returnType}}}>{{/returnType}}{{^returnType}}System.Threading.Tasks.Task{{/returnType}} {{nickname}}Async ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
|
||||||
{{/operation}}
|
{{/operation}}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a collection of functions to interact with the API endpoints
|
/// Represents a collection of functions to interact with the API endpoints
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class {{classname}} : I{{classname}} {
|
public class {{classname}} : I{{classname}}
|
||||||
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="{{classname}}"/> class.
|
/// Initializes a new instance of the <see cref="{{classname}}"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="apiClient"> an instance of ApiClient (optional)
|
/// <param name="apiClient"> an instance of ApiClient (optional)</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public {{classname}}(ApiClient apiClient = null) {
|
public {{classname}}(ApiClient apiClient = null)
|
||||||
if (apiClient == null) { // use the default one in Configuration
|
{
|
||||||
this.apiClient = Configuration.apiClient;
|
if (apiClient == null) // use the default one in Configuration
|
||||||
} else {
|
this.ApiClient = Configuration.DefaultApiClient;
|
||||||
this.apiClient = apiClient;
|
else
|
||||||
}
|
this.ApiClient = apiClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -52,123 +52,156 @@ namespace {{packageName}}.Api {
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public {{classname}}(String basePath)
|
public {{classname}}(String basePath)
|
||||||
{
|
{
|
||||||
this.apiClient = new ApiClient(basePath);
|
this.ApiClient = new ApiClient(basePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the base path of the API client.
|
/// Sets the base path of the API client.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="basePath">The base path</param>
|
||||||
/// <value>The base path</value>
|
/// <value>The base path</value>
|
||||||
public void SetBasePath(String basePath) {
|
public void SetBasePath(String basePath)
|
||||||
this.apiClient.basePath = basePath;
|
{
|
||||||
|
this.ApiClient.BasePath = basePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the base path of the API client.
|
/// Gets the base path of the API client.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="basePath">The base path</param>
|
||||||
/// <value>The base path</value>
|
/// <value>The base path</value>
|
||||||
public String GetBasePath(String basePath) {
|
public String GetBasePath(String basePath)
|
||||||
return this.apiClient.basePath;
|
{
|
||||||
|
return this.ApiClient.BasePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the API client.
|
/// Gets or sets the API client.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The API client</value>
|
/// <value>An instance of the ApiClient</param>
|
||||||
public ApiClient apiClient {get; set;}
|
public ApiClient ApiClient {get; set;}
|
||||||
|
|
||||||
|
|
||||||
{{#operation}}
|
{{#operation}}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// {{summary}} {{notes}}
|
/// {{summary}} {{notes}}
|
||||||
/// </summary>
|
/// </summary>
|
||||||
{{#allParams}}/// <param name="{{paramName}}">{{description}}</param>{{/allParams}}
|
{{#allParams}}/// <param name="{{paramName}}">{{description}}</param>
|
||||||
/// <returns>{{#returnType}}{{{returnType}}}{{/returnType}}</returns>
|
{{/allParams}}/// <returns>{{#returnType}}{{{returnType}}}{{/returnType}}</returns>
|
||||||
public {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {
|
public {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
|
||||||
|
{
|
||||||
{{#allParams}}{{#required}}
|
{{#allParams}}{{#required}}
|
||||||
// verify the required parameter '{{paramName}}' is set
|
// verify the required parameter '{{paramName}}' is set
|
||||||
if ({{paramName}} == null) throw new ApiException(400, "Missing required parameter '{{paramName}}' when calling {{nickname}}");
|
if ({{paramName}} == null) throw new ApiException(400, "Missing required parameter '{{paramName}}' when calling {{nickname}}");
|
||||||
{{/required}}{{/allParams}}
|
{{/required}}{{/allParams}}
|
||||||
|
|
||||||
var path = "{{path}}";
|
var path = "{{path}}";
|
||||||
|
<<<<<<< HEAD
|
||||||
|
|
||||||
var pathParams = new Dictionary<String, String>();
|
var pathParams = new Dictionary<String, String>();
|
||||||
|
=======
|
||||||
|
path = path.Replace("{format}", "json");
|
||||||
|
{{#pathParams}}path = path.Replace("{" + "{{baseName}}" + "}", ApiClient.ParameterToString({{{paramName}}}));
|
||||||
|
{{/pathParams}}
|
||||||
|
|
||||||
|
>>>>>>> e879268043b53fe30ea0238807b9519687c1e5f2
|
||||||
var queryParams = new Dictionary<String, String>();
|
var queryParams = new Dictionary<String, String>();
|
||||||
var headerParams = new Dictionary<String, String>();
|
var headerParams = new Dictionary<String, String>();
|
||||||
var formParams = new Dictionary<String, String>();
|
var formParams = new Dictionary<String, String>();
|
||||||
var fileParams = new Dictionary<String, String>();
|
var fileParams = new Dictionary<String, FileParameter>();
|
||||||
String postBody = null;
|
String postBody = null;
|
||||||
|
<<<<<<< HEAD
|
||||||
|
|
||||||
pathParams.Add("format", "json");
|
pathParams.Add("format", "json");
|
||||||
{{#pathParams}} if ({{paramName}} != null) pathParams.Add("{{baseName}}", apiClient.ParameterToString({{paramName}})); // path parameter
|
{{#pathParams}} if ({{paramName}} != null) pathParams.Add("{{baseName}}", apiClient.ParameterToString({{paramName}})); // path parameter
|
||||||
{{/pathParams}}
|
{{/pathParams}}
|
||||||
|
=======
|
||||||
|
>>>>>>> e879268043b53fe30ea0238807b9519687c1e5f2
|
||||||
|
|
||||||
{{#queryParams}} if ({{paramName}} != null) queryParams.Add("{{baseName}}", apiClient.ParameterToString({{paramName}})); // query parameter
|
{{#queryParams}} if ({{paramName}} != null) queryParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // query parameter
|
||||||
{{/queryParams}}
|
{{/queryParams}}
|
||||||
{{#headerParams}} if ({{paramName}} != null) headerParams.Add("{{baseName}}", apiClient.ParameterToString({{paramName}})); // header parameter
|
{{#headerParams}} if ({{paramName}} != null) headerParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // header parameter
|
||||||
{{/headerParams}}
|
{{/headerParams}}
|
||||||
{{#formParams}}if ({{paramName}} != null) {{#isFile}}fileParams.Add("{{baseName}}", {{paramName}});{{/isFile}}{{^isFile}}formParams.Add("{{baseName}}", apiClient.ParameterToString({{paramName}})); // form parameter{{/isFile}}
|
{{#formParams}}if ({{paramName}} != null) {{#isFile}}fileParams.Add("{{baseName}}", ApiClient.ParameterToFile("{{baseName}}", {{paramName}}));{{/isFile}}{{^isFile}}formParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // form parameter{{/isFile}}
|
||||||
{{/formParams}}
|
{{/formParams}}
|
||||||
{{#bodyParam}}postBody = apiClient.Serialize({{paramName}}); // http body (model) parameter
|
{{#bodyParam}}postBody = ApiClient.Serialize({{paramName}}); // http body (model) parameter
|
||||||
{{/bodyParam}}
|
{{/bodyParam}}
|
||||||
|
|
||||||
// authentication setting, if any
|
// authentication setting, if any
|
||||||
String[] authSettings = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} };
|
String[] authSettings = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} };
|
||||||
|
|
||||||
// make the HTTP request
|
// make the HTTP request
|
||||||
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.{{httpMethod}}, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings);
|
<<<<<<< HEAD
|
||||||
|
IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.{{httpMethod}}, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings);
|
||||||
|
=======
|
||||||
|
IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.{{httpMethod}}, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
|
||||||
|
>>>>>>> e879268043b53fe30ea0238807b9519687c1e5f2
|
||||||
|
|
||||||
if (((int)response.StatusCode) >= 400) {
|
if (((int)response.StatusCode) >= 400)
|
||||||
throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.Content, response.Content);
|
throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.Content, response.Content);
|
||||||
}
|
else if (((int)response.StatusCode) == 0)
|
||||||
{{#returnType}}return ({{{returnType}}}) apiClient.Deserialize(response.Content, typeof({{{returnType}}}));{{/returnType}}{{^returnType}}
|
throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.ErrorMessage, response.ErrorMessage);
|
||||||
return;{{/returnType}}
|
|
||||||
|
{{#returnType}}return ({{{returnType}}}) ApiClient.Deserialize(response.Content, typeof({{{returnType}}}), response.Headers);{{/returnType}}{{^returnType}}return;{{/returnType}}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// {{summary}} {{notes}}
|
/// {{summary}} {{notes}}
|
||||||
/// </summary>
|
/// </summary>
|
||||||
{{#allParams}}/// <param name="{{paramName}}">{{description}}</param>{{/allParams}}
|
{{#allParams}}/// <param name="{{paramName}}">{{description}}</param>
|
||||||
/// <returns>{{#returnType}}{{{returnType}}}{{/returnType}}</returns>
|
{{/allParams}}/// <returns>{{#returnType}}{{{returnType}}}{{/returnType}}</returns>
|
||||||
public async {{#returnType}}Task<{{{returnType}}}>{{/returnType}}{{^returnType}}Task{{/returnType}} {{nickname}}Async ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {
|
{{#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}}
|
{{#allParams}}{{#required}}// verify the required parameter '{{paramName}}' is set
|
||||||
// verify the required parameter '{{paramName}}' is set
|
|
||||||
if ({{paramName}} == null) throw new ApiException(400, "Missing required parameter '{{paramName}}' when calling {{nickname}}");
|
if ({{paramName}} == null) throw new ApiException(400, "Missing required parameter '{{paramName}}' when calling {{nickname}}");
|
||||||
{{/required}}{{/allParams}}
|
{{/required}}{{/allParams}}
|
||||||
|
|
||||||
var path = "{{path}}";
|
var path = "{{path}}";
|
||||||
|
<<<<<<< HEAD
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var pathParams = new Dictionary<String, String>();
|
var pathParams = new Dictionary<String, String>();
|
||||||
|
=======
|
||||||
|
path = path.Replace("{format}", "json");
|
||||||
|
{{#pathParams}}path = path.Replace("{" + "{{baseName}}" + "}", ApiClient.ParameterToString({{{paramName}}}));
|
||||||
|
{{/pathParams}}
|
||||||
|
|
||||||
|
>>>>>>> e879268043b53fe30ea0238807b9519687c1e5f2
|
||||||
var queryParams = new Dictionary<String, String>();
|
var queryParams = new Dictionary<String, String>();
|
||||||
var headerParams = new Dictionary<String, String>();
|
var headerParams = new Dictionary<String, String>();
|
||||||
var formParams = new Dictionary<String, String>();
|
var formParams = new Dictionary<String, String>();
|
||||||
var fileParams = new Dictionary<String, String>();
|
var fileParams = new Dictionary<String, FileParameter>();
|
||||||
String postBody = null;
|
String postBody = null;
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
pathParams.Add("format", "json");
|
pathParams.Add("format", "json");
|
||||||
{{#pathParams}} if ({{paramName}} != null) pathParams.Add("{{baseName}}", apiClient.ParameterToString({{paramName}})); // path parameter
|
{{#pathParams}} if ({{paramName}} != null) pathParams.Add("{{baseName}}", apiClient.ParameterToString({{paramName}})); // path parameter
|
||||||
{{/pathParams}}
|
{{/pathParams}}
|
||||||
|
|
||||||
{{#queryParams}} if ({{paramName}} != null) queryParams.Add("{{baseName}}", apiClient.ParameterToString({{paramName}})); // query parameter
|
=======
|
||||||
|
>>>>>>> e879268043b53fe30ea0238807b9519687c1e5f2
|
||||||
|
{{#queryParams}} if ({{paramName}} != null) queryParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // query parameter
|
||||||
{{/queryParams}}
|
{{/queryParams}}
|
||||||
{{#headerParams}} if ({{paramName}} != null) headerParams.Add("{{baseName}}", apiClient.ParameterToString({{paramName}})); // header parameter
|
{{#headerParams}} if ({{paramName}} != null) headerParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // header parameter
|
||||||
{{/headerParams}}
|
{{/headerParams}}
|
||||||
{{#formParams}}if ({{paramName}} != null) {{#isFile}}fileParams.Add("{{baseName}}", {{paramName}});{{/isFile}}{{^isFile}}formParams.Add("{{baseName}}", apiClient.ParameterToString({{paramName}})); // form parameter{{/isFile}}
|
{{#formParams}}if ({{paramName}} != null) {{#isFile}}fileParams.Add("{{baseName}}", ApiClient.ParameterToFile("{{baseName}}", {{paramName}}));{{/isFile}}{{^isFile}}formParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // form parameter{{/isFile}}
|
||||||
{{/formParams}}
|
{{/formParams}}
|
||||||
{{#bodyParam}}postBody = apiClient.Serialize({{paramName}}); // http body (model) parameter
|
{{#bodyParam}}postBody = ApiClient.Serialize({{paramName}}); // http body (model) parameter
|
||||||
{{/bodyParam}}
|
{{/bodyParam}}
|
||||||
|
|
||||||
// authentication setting, if any
|
// authentication setting, if any
|
||||||
String[] authSettings = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} };
|
String[] authSettings = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} };
|
||||||
|
|
||||||
// make the HTTP request
|
// make the HTTP request
|
||||||
IRestResponse response = (IRestResponse) await apiClient.CallApiAsync(path, Method.{{httpMethod}}, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings);
|
<<<<<<< HEAD
|
||||||
if (((int)response.StatusCode) >= 400) {
|
IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.{{httpMethod}}, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings);
|
||||||
|
=======
|
||||||
|
IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.{{httpMethod}}, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
|
||||||
|
>>>>>>> e879268043b53fe30ea0238807b9519687c1e5f2
|
||||||
|
if (((int)response.StatusCode) >= 400)
|
||||||
throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.Content, response.Content);
|
throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.Content, response.Content);
|
||||||
}
|
|
||||||
{{#returnType}}return ({{{returnType}}}) apiClient.Deserialize(response.Content, typeof({{{returnType}}}));{{/returnType}}{{^returnType}}
|
{{#returnType}}return ({{{returnType}}}) ApiClient.Deserialize(response.Content, typeof({{{returnType}}}), response.Headers);{{/returnType}}{{^returnType}}
|
||||||
return;{{/returnType}}
|
return;{{/returnType}}
|
||||||
}
|
}
|
||||||
{{/operation}}
|
{{/operation}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user