update c# style

This commit is contained in:
wing328 2015-07-06 23:06:28 +08:00
parent 94768d44b5
commit b1b0e28f59
14 changed files with 562 additions and 523 deletions

View File

@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text.RegularExpressions;
using System.IO;
using System.Web;
using System.Linq;
using System.Net;
using System.Text;
@ -10,222 +12,222 @@ using Newtonsoft.Json;
using RestSharp;
using RestSharp.Extensions;
namespace {{packageName}}.Client {
namespace {{packageName}}.Client
{
/// <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>
public class ApiClient {
public class ApiClient
{
private readonly Dictionary<String, String> _defaultHeaderMap = new Dictionary<String, String>();
/// <summary>
/// Initializes a new instance of the <see cref="ApiClient" /> class.
/// </summary>
/// <param name="basePath">The base path.</param>
public ApiClient(String basePath="{{basePath}}") {
this.BasePath = basePath;
this.RestClient = new RestClient(this.BasePath);
public ApiClient(String basePath="{{basePath}}")
{
BasePath = basePath;
RestClient = new RestClient(BasePath);
}
/// <summary>
/// Gets or sets the base path.
/// </summary>
/// <value>The base path.</value>
public string BasePath { get; set; }
/// <summary>
/// Gets or sets the RestClient
/// Gets or sets the RestClient.
/// </summary>
/// <value>The RestClient.</value>
public RestClient RestClient { get; set; }
private Dictionary<String, String> DefaultHeaderMap = new Dictionary<String, String>();
/// <summary>
/// Gets the default header.
/// </summary>
public Dictionary<String, String> DefaultHeader
{
get { return _defaultHeaderMap; }
}
/// <summary>
/// Make the HTTP request (Sync)
/// 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>
/// <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) {
Dictionary<String, FileParameter> fileParams, String[] authSettings)
{
var request = new RestRequest(path, method);
UpdateParamsForAuth(queryParams, headerParams, authSettings);
// add default header, if any
foreach(KeyValuePair<string, string> defaultHeader in this.DefaultHeaderMap)
foreach(var defaultHeader in _defaultHeaderMap)
request.AddHeader(defaultHeader.Key, defaultHeader.Value);
// add header parameter, if any
foreach(KeyValuePair<string, string> param in headerParams)
foreach(var param in headerParams)
request.AddHeader(param.Key, param.Value);
// add query parameter, if any
foreach(KeyValuePair<string, string> param in queryParams)
foreach(var param in queryParams)
request.AddQueryParameter(param.Key, param.Value);
// add form parameter, if any
foreach(KeyValuePair<string, string> param in formParams)
foreach(var param in formParams)
request.AddParameter(param.Key, param.Value);
// add file parameter, if any
foreach(KeyValuePair<string, FileParameter> param in fileParams)
foreach(var param in fileParams)
request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType);
if (postBody != null) {
request.AddParameter("application/json", postBody, ParameterType.RequestBody); // http body (model) parameter
}
if (postBody != null) // http body (model) parameter
request.AddParameter("application/json", postBody, ParameterType.RequestBody);
return (Object)RestClient.Execute(request);
}
/// <summary>
/// Make the HTTP request (Async)
/// 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>Task</returns>
/// <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 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) {
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(KeyValuePair<string, string> defaultHeader in this.DefaultHeaderMap)
foreach(var defaultHeader in _defaultHeaderMap)
request.AddHeader(defaultHeader.Key, defaultHeader.Value);
// add header parameter, if any
foreach(KeyValuePair<string, string> param in headerParams)
foreach(var param in headerParams)
request.AddHeader(param.Key, param.Value);
// add query parameter, if any
foreach(KeyValuePair<string, string> param in queryParams)
foreach(var param in queryParams)
request.AddQueryParameter(param.Key, param.Value);
// add form parameter, if any
foreach(KeyValuePair<string, string> param in formParams)
foreach(var param in formParams)
request.AddParameter(param.Key, param.Value);
// add file parameter, if any
foreach(KeyValuePair<string, FileParameter> param in fileParams)
foreach(var param in fileParams)
request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType);
if (postBody != null) {
request.AddParameter("application/json", postBody, ParameterType.RequestBody); // http body (model) parameter
}
if (postBody != null) // http body (model) parameter
request.AddParameter("application/json", postBody, ParameterType.RequestBody);
return (Object) await RestClient.ExecuteTaskAsync(request);
}
/// <summary>
/// Add default header
/// Add default header.
/// </summary>
/// <param name="key"> Header field name </param>
/// <param name="value"> Header field value </param>
/// <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);
public void AddDefaultHeader(string key, string value)
{
_defaultHeaderMap.Add(key, value);
}
/// <summary>
/// Get default header
/// Escape string (url-encoded).
/// </summary>
/// <returns>Dictionary of default header</returns>
public Dictionary<String, String> GetDefaultHeader() {
return DefaultHeaderMap;
/// <param name="str">String to be escaped.</param>
/// <returns>Escaped string.</returns>
public string EscapeString(string str)
{
return HttpUtility.UrlEncode(str);
}
/// <summary>
/// escape string (url-encoded)
/// Create FileParameter based on Stream.
/// </summary>
/// <param name="str">String to be escaped</param>
/// <returns>Escaped string</returns>
public string EscapeString(string str) {
return str;
}
/// <summary>
/// Create FileParameter based on Stream
/// </summary>
/// <param name="name">parameter name</param>
/// <param name="stream">Input stream</param>
/// <returns>FileParameter</returns>
/// <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) {
if (stream is FileStream)
return FileParameter.Create(name, stream.ReadAsBytes(), Path.GetFileName(((FileStream)stream).Name));
} else {
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
/// 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>
/// <param name="obj">The parameter (header, path, query, form).</param>
/// <returns>Formatted string.</returns>
public string ParameterToString(object obj)
{
if (obj is DateTime) {
if (obj is DateTime)
return ((DateTime)obj).ToString ("u");
} else if (obj is List<string>) {
else if (obj is List<string>)
return String.Join(",", obj as List<string>);
} else {
else
return Convert.ToString (obj);
}
}
/// <summary>
/// Deserialize the JSON string into a proper object
/// 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
/// <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 (Object)content;
} else if (type == typeof(Stream)) {
} else if (type == typeof(Stream))
{
String fileName, filePath;
if (String.IsNullOrEmpty (Configuration.TempFolderPath)) {
if (String.IsNullOrEmpty (Configuration.TempFolderPath))
filePath = System.IO.Path.GetTempPath ();
} else {
else
filePath = Configuration.TempFolderPath;
}
Regex regex = new Regex(@"Content-Disposition:.*filename=['""]?([^'""\s]+)['""]?$");
Match match = regex.Match(headers.ToString());
if (match.Success) {
// replace first and last " or ', if found
if (match.Success) // replace first and last " or ', if found
fileName = filePath + match.Value.Replace("\"", "").Replace("'","");
} else {
else
fileName = filePath + Guid.NewGuid().ToString();
}
File.WriteAllText (fileName, content);
return new FileStream(fileName, FileMode.Open);
} else if (type.Name.StartsWith("System.Nullable`1[[System.DateTime")) { // return a datetime object
} else if (type.Name.StartsWith("System.Nullable`1[[System.DateTime")) // return a datetime object
{
return DateTime.Parse(content, null, System.Globalization.DateTimeStyles.RoundtripKind);
} else if (type.Name == "String" || type.Name.StartsWith("System.Nullable")) { // return primitive
} else if (type.Name == "String" || type.Name.StartsWith("System.Nullable")) // return primitive type
{
return ConvertType(content, type);
}
@ -234,56 +236,61 @@ namespace {{packageName}}.Client {
{
return JsonConvert.DeserializeObject(content, type);
}
catch (IOException e) {
catch (IOException e)
{
throw new ApiException(500, e.Message);
}
}
/// <summary>
/// Serialize an object into JSON string
/// Serialize an object into JSON string.
/// </summary>
/// <param name="obj">Object</param>
/// <returns>JSON string</returns>
public string Serialize(object obj) {
/// <param name="obj">Object.</param>
/// <returns>JSON string.</returns>
public string Serialize(object obj)
{
try
{
return obj != null ? JsonConvert.SerializeObject(obj) : null;
}
catch (Exception e) {
catch (Exception e)
{
throw new ApiException(500, e.Message);
}
}
/// <summary>
/// Get the API key with prefix
/// Get the API key with prefix.
/// </summary>
/// <param name="obj">Object</param>
/// <returns>API key with prefix</returns>
/// <param name="apiKeyIdentifier">API key identifier (authentication scheme).</param>
/// <returns>API key with prefix.</returns>
public string GetApiKeyWithPrefix (string apiKeyIdentifier)
{
var apiKeyValue = "";
Configuration.ApiKey.TryGetValue (apiKeyIdentifier, out apiKeyValue);
var apiKeyPrefix = "";
if (Configuration.ApiKeyPrefix.TryGetValue (apiKeyIdentifier, out apiKeyPrefix)) {
if (Configuration.ApiKeyPrefix.TryGetValue (apiKeyIdentifier, out apiKeyPrefix))
return apiKeyPrefix + " " + apiKeyValue;
} else {
else
return apiKeyValue;
}
}
/// <summary>
/// Update parameters based on authentication
/// Update parameters based on authentication.
/// </summary>
/// <param name="QueryParams">Query parameters</param>
/// <param name="HeaderParams">Header parameters</param>
/// <param name="AuthSettings">Authentication settings</param>
public void UpdateParamsForAuth(Dictionary<String, String> queryParams, Dictionary<String, String> headerParams, string[] authSettings) {
/// <param name="queryParams">Query parameters.</param>
/// <param name="headerParams">Header parameters.</param>
/// <param name="authSettings">Authentication settings.</param>
public void UpdateParamsForAuth(Dictionary<String, String> queryParams, Dictionary<String, String> headerParams, string[] authSettings)
{
if (authSettings == null || authSettings.Length == 0)
return;
foreach (string auth in authSettings) {
foreach (string auth in authSettings)
{
// determine which one to use
switch(auth) {
switch(auth)
{
{{#authMethods}}
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}}
@ -295,24 +302,26 @@ namespace {{packageName}}.Client {
break;
}
}
}
/// <summary>
/// Encode string in base64 format
/// Encode string in base64 format.
/// </summary>
/// <param name="text">String to be encoded</param>
public static string Base64Encode(string text) {
/// <param name="text">String to be encoded.</param>
/// <returns>Encoded string.</returns>
public static string Base64Encode(string text)
{
var textByte = System.Text.Encoding.UTF8.GetBytes(text);
return System.Convert.ToBase64String(textByte);
}
/// <summary>
/// Dynamically cast the object into target type
/// Dynamically cast the object into target type.
/// Ref: http://stackoverflow.com/questions/4925718/c-dynamic-runtime-cast
/// </summary>
/// <param name="dynamic">Object to be casted</param>
/// <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);
}

View File

@ -3,18 +3,20 @@ using System.Reflection;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
namespace {{packageName}}.Client {
namespace {{packageName}}.Client
{
/// <summary>
/// Represents a set of configuration settings
/// </summary>
public class Configuration{
public class Configuration
{
/// <summary>
/// Version of the package
/// Version of the package.
/// </summary>
/// <value>Version of the package.</value>
public const string Version = "{{packageVersion}}";
/// <summary>
@ -24,25 +26,25 @@ namespace {{packageName}}.Client {
public static ApiClient DefaultApiClient = new ApiClient();
/// <summary>
/// Gets or sets the username (HTTP basic authentication)
/// Gets or sets the username (HTTP basic authentication).
/// </summary>
/// <value>The username.</value>
public static String Username { get; set; }
/// <summary>
/// Gets or sets the password (HTTP basic authentication)
/// Gets or sets the password (HTTP basic authentication).
/// </summary>
/// <value>The password.</value>
public static String Password { get; set; }
/// <summary>
/// Gets or sets the API key based on the authentication name
/// Gets or sets the API key based on the authentication name.
/// </summary>
/// <value>The API key.</value>
public static Dictionary<String, String> ApiKey = new Dictionary<String, String>();
/// <summary>
/// Gets or sets the prefix (e.g. Token) of the API key based on the authentication name
/// Gets or sets the prefix (e.g. Token) of the API key based on the authentication name.
/// </summary>
/// <value>The prefix of the API key.</value>
public static Dictionary<String, String> ApiKeyPrefix = new Dictionary<String, String>();
@ -50,46 +52,46 @@ namespace {{packageName}}.Client {
private static string _tempFolderPath = Path.GetTempPath();
/// <summary>
/// Gets or sets the temporary folder path to store the files downloaded from the server
/// Gets or sets the temporary folder path to store the files downloaded from the server.
/// </summary>
/// <value>Folder path</value>
public static String TempFolderPath {
get {
return _tempFolderPath;
}
/// <value>Folder path.</value>
public static String TempFolderPath
{
get { return _tempFolderPath; }
set {
if (String.IsNullOrEmpty(value)) {
set
{
if (String.IsNullOrEmpty(value))
{
_tempFolderPath = value;
return;
}
// create the directory if it does not exist
if (!Directory.Exists(value)) {
if (!Directory.Exists(value))
Directory.CreateDirectory(value);
}
// check if the path contains directory separator at the end
if (value[value.Length - 1] == Path.DirectorySeparatorChar) {
if (value[value.Length - 1] == Path.DirectorySeparatorChar)
_tempFolderPath = value;
} else {
else
_tempFolderPath = value + Path.DirectorySeparatorChar;
}
}
}
/// <summary>
/// Return a string contain essential information for debugging
/// Returns a string with essential information for debugging.
/// </summary>
/// <value>Folder path</value>
public static String ToDebugReport() {
/// <value>Debugging Report</value>
public static String ToDebugReport()
{
String report = "C# SDK ({{invokerPackage}}) Debug Report:\n";
report += " OS: " + Environment.OSVersion + "\n";
report += " .NET Framework Version: " + Assembly
.GetExecutingAssembly()
.GetReferencedAssemblies()
.Where(x => x.Name == "System.Core").First().Version.ToString() + "\n";
report += " Swagger Spec Version: {{version}}\n";
report += " Version of the API: {{version}}\n";
report += " SDK Package Version: {{packageVersion}}\n";
return report;

View File

@ -7,9 +7,11 @@ using {{packageName}}.Client;
{{#hasImport}}using {{packageName}}.Model;
{{/hasImport}}
namespace {{packageName}}.Api {
namespace {{packageName}}.Api
{
{{#operations}}
public interface I{{classname}} {
public interface I{{classname}}
{
{{#operation}}
/// <summary>
/// {{summary}} {{notes}}
@ -30,20 +32,20 @@ namespace {{packageName}}.Api {
/// <summary>
/// Represents a collection of functions to interact with the API endpoints
/// </summary>
public class {{classname}} : I{{classname}} {
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
public {{classname}}(ApiClient apiClient = null)
{
if (apiClient == null) // use the default one in Configuration
this.ApiClient = Configuration.DefaultApiClient;
} else {
else
this.ApiClient = apiClient;
}
}
/// <summary>
/// Initializes a new instance of the <see cref="{{classname}}"/> class.
@ -58,7 +60,8 @@ namespace {{packageName}}.Api {
/// Sets the base path of the API client.
/// </summary>
/// <value>The base path</value>
public void SetBasePath(String basePath) {
public void SetBasePath(String basePath)
{
this.ApiClient.BasePath = basePath;
}
@ -66,14 +69,15 @@ namespace {{packageName}}.Api {
/// Gets the base path of the API client.
/// </summary>
/// <value>The base path</value>
public String GetBasePath(String basePath) {
public String GetBasePath(String basePath)
{
return this.ApiClient.BasePath;
}
/// <summary>
/// Gets or sets the API client.
/// </summary>
/// <value>The API client</value>
/// <value>The API client.</value>
public ApiClient ApiClient {get; set;}
{{#operation}}
@ -82,8 +86,8 @@ namespace {{packageName}}.Api {
/// </summary>
{{#allParams}}/// <param name="{{paramName}}">{{description}}</param>
{{/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}}
// verify the required parameter '{{paramName}}' is set
if ({{paramName}} == null) throw new ApiException(400, "Missing required parameter '{{paramName}}' when calling {{nickname}}");
@ -115,11 +119,10 @@ namespace {{packageName}}.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.{{httpMethod}}, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.Content, response.Content);
} else if (((int)response.StatusCode) == 0) {
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}}
}
@ -129,7 +132,8 @@ namespace {{packageName}}.Api {
/// </summary>
{{#allParams}}/// <param name="{{paramName}}">{{description}}</param>
{{/allParams}}/// <returns>{{#returnType}}{{{returnType}}}{{/returnType}}</returns>
{{#returnType}}public async Task<{{{returnType}}}>{{/returnType}}{{^returnType}}public async Task{{/returnType}} {{nickname}}Async ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {
{{#returnType}}public async Task<{{{returnType}}}>{{/returnType}}{{^returnType}}public async 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}}
@ -159,9 +163,9 @@ namespace {{packageName}}.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.{{httpMethod}}, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
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}}
}

View File

@ -6,9 +6,11 @@ using RestSharp;
using IO.Swagger.Client;
using IO.Swagger.Model;
namespace IO.Swagger.Api {
namespace IO.Swagger.Api
{
public interface IPetApi {
public interface IPetApi
{
/// <summary>
/// Update an existing pet
@ -137,20 +139,20 @@ namespace IO.Swagger.Api {
/// <summary>
/// Represents a collection of functions to interact with the API endpoints
/// </summary>
public class PetApi : IPetApi {
public class PetApi : IPetApi
{
/// <summary>
/// Initializes a new instance of the <see cref="PetApi"/> class.
/// </summary>
/// <param name="apiClient"> an instance of ApiClient (optional)</param>
/// <returns></returns>
public PetApi(ApiClient apiClient = null) {
if (apiClient == null) { // use the default one in Configuration
public PetApi(ApiClient apiClient = null)
{
if (apiClient == null) // use the default one in Configuration
this.ApiClient = Configuration.DefaultApiClient;
} else {
else
this.ApiClient = apiClient;
}
}
/// <summary>
/// Initializes a new instance of the <see cref="PetApi"/> class.
@ -165,7 +167,8 @@ namespace IO.Swagger.Api {
/// Sets the base path of the API client.
/// </summary>
/// <value>The base path</value>
public void SetBasePath(String basePath) {
public void SetBasePath(String basePath)
{
this.ApiClient.BasePath = basePath;
}
@ -173,14 +176,15 @@ namespace IO.Swagger.Api {
/// Gets the base path of the API client.
/// </summary>
/// <value>The base path</value>
public String GetBasePath(String basePath) {
public String GetBasePath(String basePath)
{
return this.ApiClient.BasePath;
}
/// <summary>
/// Gets or sets the API client.
/// </summary>
/// <value>The API client</value>
/// <value>The API client.</value>
public ApiClient ApiClient {get; set;}
@ -189,8 +193,8 @@ namespace IO.Swagger.Api {
/// </summary>
/// <param name="body">Pet object that needs to be added to the store</param>
/// <returns></returns>
public void UpdatePet (Pet body) {
public void UpdatePet (Pet body)
{
var path = "/pet";
@ -215,11 +219,10 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling UpdatePet: " + response.Content, response.Content);
} else if (((int)response.StatusCode) == 0) {
else if (((int)response.StatusCode) == 0)
throw new ApiException ((int)response.StatusCode, "Error calling UpdatePet: " + response.ErrorMessage, response.ErrorMessage);
}
return;
}
@ -229,7 +232,8 @@ namespace IO.Swagger.Api {
/// </summary>
/// <param name="body">Pet object that needs to be added to the store</param>
/// <returns></returns>
public async Task UpdatePetAsync (Pet body) {
public async Task UpdatePetAsync (Pet body)
{
var path = "/pet";
@ -253,9 +257,9 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling UpdatePet: " + response.Content, response.Content);
}
return;
}
@ -265,8 +269,8 @@ namespace IO.Swagger.Api {
/// </summary>
/// <param name="body">Pet object that needs to be added to the store</param>
/// <returns></returns>
public void AddPet (Pet body) {
public void AddPet (Pet body)
{
var path = "/pet";
@ -291,11 +295,10 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling AddPet: " + response.Content, response.Content);
} else if (((int)response.StatusCode) == 0) {
else if (((int)response.StatusCode) == 0)
throw new ApiException ((int)response.StatusCode, "Error calling AddPet: " + response.ErrorMessage, response.ErrorMessage);
}
return;
}
@ -305,7 +308,8 @@ namespace IO.Swagger.Api {
/// </summary>
/// <param name="body">Pet object that needs to be added to the store</param>
/// <returns></returns>
public async Task AddPetAsync (Pet body) {
public async Task AddPetAsync (Pet body)
{
var path = "/pet";
@ -329,9 +333,9 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling AddPet: " + response.Content, response.Content);
}
return;
}
@ -341,8 +345,8 @@ namespace IO.Swagger.Api {
/// </summary>
/// <param name="status">Status values that need to be considered for filter</param>
/// <returns>List<Pet></returns>
public List<Pet> FindPetsByStatus (List<string> status) {
public List<Pet> FindPetsByStatus (List<string> status)
{
var path = "/pet/findByStatus";
@ -367,11 +371,10 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByStatus: " + response.Content, response.Content);
} else if (((int)response.StatusCode) == 0) {
else if (((int)response.StatusCode) == 0)
throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByStatus: " + response.ErrorMessage, response.ErrorMessage);
}
return (List<Pet>) ApiClient.Deserialize(response.Content, typeof(List<Pet>), response.Headers);
}
@ -381,7 +384,8 @@ namespace IO.Swagger.Api {
/// </summary>
/// <param name="status">Status values that need to be considered for filter</param>
/// <returns>List<Pet></returns>
public async Task<List<Pet>> FindPetsByStatusAsync (List<string> status) {
public async Task<List<Pet>> FindPetsByStatusAsync (List<string> status)
{
var path = "/pet/findByStatus";
@ -405,9 +409,9 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByStatus: " + response.Content, response.Content);
}
return (List<Pet>) ApiClient.Deserialize(response.Content, typeof(List<Pet>), response.Headers);
}
@ -416,8 +420,8 @@ namespace IO.Swagger.Api {
/// </summary>
/// <param name="tags">Tags to filter by</param>
/// <returns>List<Pet></returns>
public List<Pet> FindPetsByTags (List<string> tags) {
public List<Pet> FindPetsByTags (List<string> tags)
{
var path = "/pet/findByTags";
@ -442,11 +446,10 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByTags: " + response.Content, response.Content);
} else if (((int)response.StatusCode) == 0) {
else if (((int)response.StatusCode) == 0)
throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByTags: " + response.ErrorMessage, response.ErrorMessage);
}
return (List<Pet>) ApiClient.Deserialize(response.Content, typeof(List<Pet>), response.Headers);
}
@ -456,7 +459,8 @@ namespace IO.Swagger.Api {
/// </summary>
/// <param name="tags">Tags to filter by</param>
/// <returns>List<Pet></returns>
public async Task<List<Pet>> FindPetsByTagsAsync (List<string> tags) {
public async Task<List<Pet>> FindPetsByTagsAsync (List<string> tags)
{
var path = "/pet/findByTags";
@ -480,9 +484,9 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByTags: " + response.Content, response.Content);
}
return (List<Pet>) ApiClient.Deserialize(response.Content, typeof(List<Pet>), response.Headers);
}
@ -491,8 +495,8 @@ namespace IO.Swagger.Api {
/// </summary>
/// <param name="petId">ID of pet that needs to be fetched</param>
/// <returns>Pet</returns>
public Pet GetPetById (long? petId) {
public Pet GetPetById (long? petId)
{
// verify the required parameter 'petId' is set
if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling GetPetById");
@ -520,11 +524,10 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling GetPetById: " + response.Content, response.Content);
} else if (((int)response.StatusCode) == 0) {
else if (((int)response.StatusCode) == 0)
throw new ApiException ((int)response.StatusCode, "Error calling GetPetById: " + response.ErrorMessage, response.ErrorMessage);
}
return (Pet) ApiClient.Deserialize(response.Content, typeof(Pet), response.Headers);
}
@ -534,7 +537,8 @@ namespace IO.Swagger.Api {
/// </summary>
/// <param name="petId">ID of pet that needs to be fetched</param>
/// <returns>Pet</returns>
public async Task<Pet> GetPetByIdAsync (long? petId) {
public async Task<Pet> GetPetByIdAsync (long? petId)
{
// verify the required parameter 'petId' is set
if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling GetPetById");
@ -560,9 +564,9 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling GetPetById: " + response.Content, response.Content);
}
return (Pet) ApiClient.Deserialize(response.Content, typeof(Pet), response.Headers);
}
@ -573,8 +577,8 @@ namespace IO.Swagger.Api {
/// <param name="name">Updated name of the pet</param>
/// <param name="status">Updated status of the pet</param>
/// <returns></returns>
public void UpdatePetWithForm (string petId, string name, string status) {
public void UpdatePetWithForm (string petId, string name, string status)
{
// verify the required parameter 'petId' is set
if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling UpdatePetWithForm");
@ -604,11 +608,10 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling UpdatePetWithForm: " + response.Content, response.Content);
} else if (((int)response.StatusCode) == 0) {
else if (((int)response.StatusCode) == 0)
throw new ApiException ((int)response.StatusCode, "Error calling UpdatePetWithForm: " + response.ErrorMessage, response.ErrorMessage);
}
return;
}
@ -620,7 +623,8 @@ namespace IO.Swagger.Api {
/// <param name="name">Updated name of the pet</param>
/// <param name="status">Updated status of the pet</param>
/// <returns></returns>
public async Task UpdatePetWithFormAsync (string petId, string name, string status) {
public async Task UpdatePetWithFormAsync (string petId, string name, string status)
{
// verify the required parameter 'petId' is set
if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling UpdatePetWithForm");
@ -648,9 +652,9 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling UpdatePetWithForm: " + response.Content, response.Content);
}
return;
}
@ -661,8 +665,8 @@ namespace IO.Swagger.Api {
/// <param name="apiKey"></param>
/// <param name="petId">Pet id to delete</param>
/// <returns></returns>
public void DeletePet (string apiKey, long? petId) {
public void DeletePet (string apiKey, long? petId)
{
// verify the required parameter 'petId' is set
if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling DeletePet");
@ -691,11 +695,10 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling DeletePet: " + response.Content, response.Content);
} else if (((int)response.StatusCode) == 0) {
else if (((int)response.StatusCode) == 0)
throw new ApiException ((int)response.StatusCode, "Error calling DeletePet: " + response.ErrorMessage, response.ErrorMessage);
}
return;
}
@ -706,7 +709,8 @@ namespace IO.Swagger.Api {
/// <param name="apiKey"></param>
/// <param name="petId">Pet id to delete</param>
/// <returns></returns>
public async Task DeletePetAsync (string apiKey, long? petId) {
public async Task DeletePetAsync (string apiKey, long? petId)
{
// verify the required parameter 'petId' is set
if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling DeletePet");
@ -733,9 +737,9 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling DeletePet: " + response.Content, response.Content);
}
return;
}
@ -747,8 +751,8 @@ namespace IO.Swagger.Api {
/// <param name="additionalMetadata">Additional data to pass to server</param>
/// <param name="file">file to upload</param>
/// <returns></returns>
public void UploadFile (long? petId, string additionalMetadata, Stream file) {
public void UploadFile (long? petId, string additionalMetadata, Stream file)
{
// verify the required parameter 'petId' is set
if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling UploadFile");
@ -778,11 +782,10 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling UploadFile: " + response.Content, response.Content);
} else if (((int)response.StatusCode) == 0) {
else if (((int)response.StatusCode) == 0)
throw new ApiException ((int)response.StatusCode, "Error calling UploadFile: " + response.ErrorMessage, response.ErrorMessage);
}
return;
}
@ -794,7 +797,8 @@ namespace IO.Swagger.Api {
/// <param name="additionalMetadata">Additional data to pass to server</param>
/// <param name="file">file to upload</param>
/// <returns></returns>
public async Task UploadFileAsync (long? petId, string additionalMetadata, Stream file) {
public async Task UploadFileAsync (long? petId, string additionalMetadata, Stream file)
{
// verify the required parameter 'petId' is set
if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling UploadFile");
@ -822,9 +826,9 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling UploadFile: " + response.Content, response.Content);
}
return;
}

View File

@ -6,9 +6,11 @@ using RestSharp;
using IO.Swagger.Client;
using IO.Swagger.Model;
namespace IO.Swagger.Api {
namespace IO.Swagger.Api
{
public interface IStoreApi {
public interface IStoreApi
{
/// <summary>
/// Returns pet inventories by status Returns a map of status codes to quantities
@ -69,20 +71,20 @@ namespace IO.Swagger.Api {
/// <summary>
/// Represents a collection of functions to interact with the API endpoints
/// </summary>
public class StoreApi : IStoreApi {
public class StoreApi : IStoreApi
{
/// <summary>
/// Initializes a new instance of the <see cref="StoreApi"/> class.
/// </summary>
/// <param name="apiClient"> an instance of ApiClient (optional)</param>
/// <returns></returns>
public StoreApi(ApiClient apiClient = null) {
if (apiClient == null) { // use the default one in Configuration
public StoreApi(ApiClient apiClient = null)
{
if (apiClient == null) // use the default one in Configuration
this.ApiClient = Configuration.DefaultApiClient;
} else {
else
this.ApiClient = apiClient;
}
}
/// <summary>
/// Initializes a new instance of the <see cref="StoreApi"/> class.
@ -97,7 +99,8 @@ namespace IO.Swagger.Api {
/// Sets the base path of the API client.
/// </summary>
/// <value>The base path</value>
public void SetBasePath(String basePath) {
public void SetBasePath(String basePath)
{
this.ApiClient.BasePath = basePath;
}
@ -105,14 +108,15 @@ namespace IO.Swagger.Api {
/// Gets the base path of the API client.
/// </summary>
/// <value>The base path</value>
public String GetBasePath(String basePath) {
public String GetBasePath(String basePath)
{
return this.ApiClient.BasePath;
}
/// <summary>
/// Gets or sets the API client.
/// </summary>
/// <value>The API client</value>
/// <value>The API client.</value>
public ApiClient ApiClient {get; set;}
@ -120,8 +124,8 @@ namespace IO.Swagger.Api {
/// Returns pet inventories by status Returns a map of status codes to quantities
/// </summary>
/// <returns>Dictionary<String, int?></returns>
public Dictionary<String, int?> GetInventory () {
public Dictionary<String, int?> GetInventory ()
{
var path = "/store/inventory";
@ -145,11 +149,10 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling GetInventory: " + response.Content, response.Content);
} else if (((int)response.StatusCode) == 0) {
else if (((int)response.StatusCode) == 0)
throw new ApiException ((int)response.StatusCode, "Error calling GetInventory: " + response.ErrorMessage, response.ErrorMessage);
}
return (Dictionary<String, int?>) ApiClient.Deserialize(response.Content, typeof(Dictionary<String, int?>), response.Headers);
}
@ -158,7 +161,8 @@ namespace IO.Swagger.Api {
/// Returns pet inventories by status Returns a map of status codes to quantities
/// </summary>
/// <returns>Dictionary<String, int?></returns>
public async Task<Dictionary<String, int?>> GetInventoryAsync () {
public async Task<Dictionary<String, int?>> GetInventoryAsync ()
{
var path = "/store/inventory";
@ -181,9 +185,9 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling GetInventory: " + response.Content, response.Content);
}
return (Dictionary<String, int?>) ApiClient.Deserialize(response.Content, typeof(Dictionary<String, int?>), response.Headers);
}
@ -192,8 +196,8 @@ namespace IO.Swagger.Api {
/// </summary>
/// <param name="body">order placed for purchasing the pet</param>
/// <returns>Order</returns>
public Order PlaceOrder (Order body) {
public Order PlaceOrder (Order body)
{
var path = "/store/order";
@ -218,11 +222,10 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling PlaceOrder: " + response.Content, response.Content);
} else if (((int)response.StatusCode) == 0) {
else if (((int)response.StatusCode) == 0)
throw new ApiException ((int)response.StatusCode, "Error calling PlaceOrder: " + response.ErrorMessage, response.ErrorMessage);
}
return (Order) ApiClient.Deserialize(response.Content, typeof(Order), response.Headers);
}
@ -232,7 +235,8 @@ namespace IO.Swagger.Api {
/// </summary>
/// <param name="body">order placed for purchasing the pet</param>
/// <returns>Order</returns>
public async Task<Order> PlaceOrderAsync (Order body) {
public async Task<Order> PlaceOrderAsync (Order body)
{
var path = "/store/order";
@ -256,9 +260,9 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling PlaceOrder: " + response.Content, response.Content);
}
return (Order) ApiClient.Deserialize(response.Content, typeof(Order), response.Headers);
}
@ -267,8 +271,8 @@ namespace IO.Swagger.Api {
/// </summary>
/// <param name="orderId">ID of pet that needs to be fetched</param>
/// <returns>Order</returns>
public Order GetOrderById (string orderId) {
public Order GetOrderById (string orderId)
{
// verify the required parameter 'orderId' is set
if (orderId == null) throw new ApiException(400, "Missing required parameter 'orderId' when calling GetOrderById");
@ -296,11 +300,10 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling GetOrderById: " + response.Content, response.Content);
} else if (((int)response.StatusCode) == 0) {
else if (((int)response.StatusCode) == 0)
throw new ApiException ((int)response.StatusCode, "Error calling GetOrderById: " + response.ErrorMessage, response.ErrorMessage);
}
return (Order) ApiClient.Deserialize(response.Content, typeof(Order), response.Headers);
}
@ -310,7 +313,8 @@ namespace IO.Swagger.Api {
/// </summary>
/// <param name="orderId">ID of pet that needs to be fetched</param>
/// <returns>Order</returns>
public async Task<Order> GetOrderByIdAsync (string orderId) {
public async Task<Order> GetOrderByIdAsync (string orderId)
{
// verify the required parameter 'orderId' is set
if (orderId == null) throw new ApiException(400, "Missing required parameter 'orderId' when calling GetOrderById");
@ -336,9 +340,9 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling GetOrderById: " + response.Content, response.Content);
}
return (Order) ApiClient.Deserialize(response.Content, typeof(Order), response.Headers);
}
@ -347,8 +351,8 @@ namespace IO.Swagger.Api {
/// </summary>
/// <param name="orderId">ID of the order that needs to be deleted</param>
/// <returns></returns>
public void DeleteOrder (string orderId) {
public void DeleteOrder (string orderId)
{
// verify the required parameter 'orderId' is set
if (orderId == null) throw new ApiException(400, "Missing required parameter 'orderId' when calling DeleteOrder");
@ -376,11 +380,10 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling DeleteOrder: " + response.Content, response.Content);
} else if (((int)response.StatusCode) == 0) {
else if (((int)response.StatusCode) == 0)
throw new ApiException ((int)response.StatusCode, "Error calling DeleteOrder: " + response.ErrorMessage, response.ErrorMessage);
}
return;
}
@ -390,7 +393,8 @@ namespace IO.Swagger.Api {
/// </summary>
/// <param name="orderId">ID of the order that needs to be deleted</param>
/// <returns></returns>
public async Task DeleteOrderAsync (string orderId) {
public async Task DeleteOrderAsync (string orderId)
{
// verify the required parameter 'orderId' is set
if (orderId == null) throw new ApiException(400, "Missing required parameter 'orderId' when calling DeleteOrder");
@ -416,9 +420,9 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling DeleteOrder: " + response.Content, response.Content);
}
return;
}

View File

@ -6,9 +6,11 @@ using RestSharp;
using IO.Swagger.Client;
using IO.Swagger.Model;
namespace IO.Swagger.Api {
namespace IO.Swagger.Api
{
public interface IUserApi {
public interface IUserApi
{
/// <summary>
/// Create user This can only be done by the logged in user.
@ -129,20 +131,20 @@ namespace IO.Swagger.Api {
/// <summary>
/// Represents a collection of functions to interact with the API endpoints
/// </summary>
public class UserApi : IUserApi {
public class UserApi : IUserApi
{
/// <summary>
/// Initializes a new instance of the <see cref="UserApi"/> class.
/// </summary>
/// <param name="apiClient"> an instance of ApiClient (optional)</param>
/// <returns></returns>
public UserApi(ApiClient apiClient = null) {
if (apiClient == null) { // use the default one in Configuration
public UserApi(ApiClient apiClient = null)
{
if (apiClient == null) // use the default one in Configuration
this.ApiClient = Configuration.DefaultApiClient;
} else {
else
this.ApiClient = apiClient;
}
}
/// <summary>
/// Initializes a new instance of the <see cref="UserApi"/> class.
@ -157,7 +159,8 @@ namespace IO.Swagger.Api {
/// Sets the base path of the API client.
/// </summary>
/// <value>The base path</value>
public void SetBasePath(String basePath) {
public void SetBasePath(String basePath)
{
this.ApiClient.BasePath = basePath;
}
@ -165,14 +168,15 @@ namespace IO.Swagger.Api {
/// Gets the base path of the API client.
/// </summary>
/// <value>The base path</value>
public String GetBasePath(String basePath) {
public String GetBasePath(String basePath)
{
return this.ApiClient.BasePath;
}
/// <summary>
/// Gets or sets the API client.
/// </summary>
/// <value>The API client</value>
/// <value>The API client.</value>
public ApiClient ApiClient {get; set;}
@ -181,8 +185,8 @@ namespace IO.Swagger.Api {
/// </summary>
/// <param name="body">Created user object</param>
/// <returns></returns>
public void CreateUser (User body) {
public void CreateUser (User body)
{
var path = "/user";
@ -207,11 +211,10 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling CreateUser: " + response.Content, response.Content);
} else if (((int)response.StatusCode) == 0) {
else if (((int)response.StatusCode) == 0)
throw new ApiException ((int)response.StatusCode, "Error calling CreateUser: " + response.ErrorMessage, response.ErrorMessage);
}
return;
}
@ -221,7 +224,8 @@ namespace IO.Swagger.Api {
/// </summary>
/// <param name="body">Created user object</param>
/// <returns></returns>
public async Task CreateUserAsync (User body) {
public async Task CreateUserAsync (User body)
{
var path = "/user";
@ -245,9 +249,9 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling CreateUser: " + response.Content, response.Content);
}
return;
}
@ -257,8 +261,8 @@ namespace IO.Swagger.Api {
/// </summary>
/// <param name="body">List of user object</param>
/// <returns></returns>
public void CreateUsersWithArrayInput (List<User> body) {
public void CreateUsersWithArrayInput (List<User> body)
{
var path = "/user/createWithArray";
@ -283,11 +287,10 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithArrayInput: " + response.Content, response.Content);
} else if (((int)response.StatusCode) == 0) {
else if (((int)response.StatusCode) == 0)
throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithArrayInput: " + response.ErrorMessage, response.ErrorMessage);
}
return;
}
@ -297,7 +300,8 @@ namespace IO.Swagger.Api {
/// </summary>
/// <param name="body">List of user object</param>
/// <returns></returns>
public async Task CreateUsersWithArrayInputAsync (List<User> body) {
public async Task CreateUsersWithArrayInputAsync (List<User> body)
{
var path = "/user/createWithArray";
@ -321,9 +325,9 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithArrayInput: " + response.Content, response.Content);
}
return;
}
@ -333,8 +337,8 @@ namespace IO.Swagger.Api {
/// </summary>
/// <param name="body">List of user object</param>
/// <returns></returns>
public void CreateUsersWithListInput (List<User> body) {
public void CreateUsersWithListInput (List<User> body)
{
var path = "/user/createWithList";
@ -359,11 +363,10 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithListInput: " + response.Content, response.Content);
} else if (((int)response.StatusCode) == 0) {
else if (((int)response.StatusCode) == 0)
throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithListInput: " + response.ErrorMessage, response.ErrorMessage);
}
return;
}
@ -373,7 +376,8 @@ namespace IO.Swagger.Api {
/// </summary>
/// <param name="body">List of user object</param>
/// <returns></returns>
public async Task CreateUsersWithListInputAsync (List<User> body) {
public async Task CreateUsersWithListInputAsync (List<User> body)
{
var path = "/user/createWithList";
@ -397,9 +401,9 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithListInput: " + response.Content, response.Content);
}
return;
}
@ -410,8 +414,8 @@ namespace IO.Swagger.Api {
/// <param name="username">The user name for login</param>
/// <param name="password">The password for login in clear text</param>
/// <returns>string</returns>
public string LoginUser (string username, string password) {
public string LoginUser (string username, string password)
{
var path = "/user/login";
@ -437,11 +441,10 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling LoginUser: " + response.Content, response.Content);
} else if (((int)response.StatusCode) == 0) {
else if (((int)response.StatusCode) == 0)
throw new ApiException ((int)response.StatusCode, "Error calling LoginUser: " + response.ErrorMessage, response.ErrorMessage);
}
return (string) ApiClient.Deserialize(response.Content, typeof(string), response.Headers);
}
@ -452,7 +455,8 @@ namespace IO.Swagger.Api {
/// <param name="username">The user name for login</param>
/// <param name="password">The password for login in clear text</param>
/// <returns>string</returns>
public async Task<string> LoginUserAsync (string username, string password) {
public async Task<string> LoginUserAsync (string username, string password)
{
var path = "/user/login";
@ -477,9 +481,9 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling LoginUser: " + response.Content, response.Content);
}
return (string) ApiClient.Deserialize(response.Content, typeof(string), response.Headers);
}
@ -487,8 +491,8 @@ namespace IO.Swagger.Api {
/// Logs out current logged in user session
/// </summary>
/// <returns></returns>
public void LogoutUser () {
public void LogoutUser ()
{
var path = "/user/logout";
@ -512,11 +516,10 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling LogoutUser: " + response.Content, response.Content);
} else if (((int)response.StatusCode) == 0) {
else if (((int)response.StatusCode) == 0)
throw new ApiException ((int)response.StatusCode, "Error calling LogoutUser: " + response.ErrorMessage, response.ErrorMessage);
}
return;
}
@ -525,7 +528,8 @@ namespace IO.Swagger.Api {
/// Logs out current logged in user session
/// </summary>
/// <returns></returns>
public async Task LogoutUserAsync () {
public async Task LogoutUserAsync ()
{
var path = "/user/logout";
@ -548,9 +552,9 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling LogoutUser: " + response.Content, response.Content);
}
return;
}
@ -560,8 +564,8 @@ namespace IO.Swagger.Api {
/// </summary>
/// <param name="username">The name that needs to be fetched. Use user1 for testing. </param>
/// <returns>User</returns>
public User GetUserByName (string username) {
public User GetUserByName (string username)
{
// verify the required parameter 'username' is set
if (username == null) throw new ApiException(400, "Missing required parameter 'username' when calling GetUserByName");
@ -589,11 +593,10 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling GetUserByName: " + response.Content, response.Content);
} else if (((int)response.StatusCode) == 0) {
else if (((int)response.StatusCode) == 0)
throw new ApiException ((int)response.StatusCode, "Error calling GetUserByName: " + response.ErrorMessage, response.ErrorMessage);
}
return (User) ApiClient.Deserialize(response.Content, typeof(User), response.Headers);
}
@ -603,7 +606,8 @@ namespace IO.Swagger.Api {
/// </summary>
/// <param name="username">The name that needs to be fetched. Use user1 for testing. </param>
/// <returns>User</returns>
public async Task<User> GetUserByNameAsync (string username) {
public async Task<User> GetUserByNameAsync (string username)
{
// verify the required parameter 'username' is set
if (username == null) throw new ApiException(400, "Missing required parameter 'username' when calling GetUserByName");
@ -629,9 +633,9 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling GetUserByName: " + response.Content, response.Content);
}
return (User) ApiClient.Deserialize(response.Content, typeof(User), response.Headers);
}
@ -641,8 +645,8 @@ namespace IO.Swagger.Api {
/// <param name="username">name that need to be deleted</param>
/// <param name="body">Updated user object</param>
/// <returns></returns>
public void UpdateUser (string username, User body) {
public void UpdateUser (string username, User body)
{
// verify the required parameter 'username' is set
if (username == null) throw new ApiException(400, "Missing required parameter 'username' when calling UpdateUser");
@ -671,11 +675,10 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling UpdateUser: " + response.Content, response.Content);
} else if (((int)response.StatusCode) == 0) {
else if (((int)response.StatusCode) == 0)
throw new ApiException ((int)response.StatusCode, "Error calling UpdateUser: " + response.ErrorMessage, response.ErrorMessage);
}
return;
}
@ -686,7 +689,8 @@ namespace IO.Swagger.Api {
/// <param name="username">name that need to be deleted</param>
/// <param name="body">Updated user object</param>
/// <returns></returns>
public async Task UpdateUserAsync (string username, User body) {
public async Task UpdateUserAsync (string username, User body)
{
// verify the required parameter 'username' is set
if (username == null) throw new ApiException(400, "Missing required parameter 'username' when calling UpdateUser");
@ -713,9 +717,9 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling UpdateUser: " + response.Content, response.Content);
}
return;
}
@ -725,8 +729,8 @@ namespace IO.Swagger.Api {
/// </summary>
/// <param name="username">The name that needs to be deleted</param>
/// <returns></returns>
public void DeleteUser (string username) {
public void DeleteUser (string username)
{
// verify the required parameter 'username' is set
if (username == null) throw new ApiException(400, "Missing required parameter 'username' when calling DeleteUser");
@ -754,11 +758,10 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling DeleteUser: " + response.Content, response.Content);
} else if (((int)response.StatusCode) == 0) {
else if (((int)response.StatusCode) == 0)
throw new ApiException ((int)response.StatusCode, "Error calling DeleteUser: " + response.ErrorMessage, response.ErrorMessage);
}
return;
}
@ -768,7 +771,8 @@ namespace IO.Swagger.Api {
/// </summary>
/// <param name="username">The name that needs to be deleted</param>
/// <returns></returns>
public async Task DeleteUserAsync (string username) {
public async Task DeleteUserAsync (string username)
{
// verify the required parameter 'username' is set
if (username == null) throw new ApiException(400, "Missing required parameter 'username' when calling DeleteUser");
@ -794,9 +798,9 @@ namespace IO.Swagger.Api {
// make the HTTP request
IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
if (((int)response.StatusCode) >= 400) {
if (((int)response.StatusCode) >= 400)
throw new ApiException ((int)response.StatusCode, "Error calling DeleteUser: " + response.Content, response.Content);
}
return;
}

View File

@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text.RegularExpressions;
using System.IO;
using System.Web;
using System.Linq;
using System.Net;
using System.Text;
@ -10,222 +12,222 @@ using Newtonsoft.Json;
using RestSharp;
using RestSharp.Extensions;
namespace IO.Swagger.Client {
namespace IO.Swagger.Client
{
/// <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>
public class ApiClient {
public class ApiClient
{
private readonly Dictionary<String, String> _defaultHeaderMap = new Dictionary<String, String>();
/// <summary>
/// Initializes a new instance of the <see cref="ApiClient" /> class.
/// </summary>
/// <param name="basePath">The base path.</param>
public ApiClient(String basePath="http://petstore.swagger.io/v2") {
this.BasePath = basePath;
this.RestClient = new RestClient(this.BasePath);
public ApiClient(String basePath="http://petstore.swagger.io/v2")
{
BasePath = basePath;
RestClient = new RestClient(BasePath);
}
/// <summary>
/// Gets or sets the base path.
/// </summary>
/// <value>The base path.</value>
public string BasePath { get; set; }
/// <summary>
/// Gets or sets the RestClient
/// Gets or sets the RestClient.
/// </summary>
/// <value>The RestClient.</value>
public RestClient RestClient { get; set; }
private Dictionary<String, String> DefaultHeaderMap = new Dictionary<String, String>();
/// <summary>
/// Gets the default header.
/// </summary>
public Dictionary<String, String> DefaultHeader
{
get { return _defaultHeaderMap; }
}
/// <summary>
/// Make the HTTP request (Sync)
/// 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>
/// <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) {
Dictionary<String, FileParameter> fileParams, String[] authSettings)
{
var request = new RestRequest(path, method);
UpdateParamsForAuth(queryParams, headerParams, authSettings);
// add default header, if any
foreach(KeyValuePair<string, string> defaultHeader in this.DefaultHeaderMap)
foreach(var defaultHeader in _defaultHeaderMap)
request.AddHeader(defaultHeader.Key, defaultHeader.Value);
// add header parameter, if any
foreach(KeyValuePair<string, string> param in headerParams)
foreach(var param in headerParams)
request.AddHeader(param.Key, param.Value);
// add query parameter, if any
foreach(KeyValuePair<string, string> param in queryParams)
foreach(var param in queryParams)
request.AddQueryParameter(param.Key, param.Value);
// add form parameter, if any
foreach(KeyValuePair<string, string> param in formParams)
foreach(var param in formParams)
request.AddParameter(param.Key, param.Value);
// add file parameter, if any
foreach(KeyValuePair<string, FileParameter> param in fileParams)
foreach(var param in fileParams)
request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType);
if (postBody != null) {
request.AddParameter("application/json", postBody, ParameterType.RequestBody); // http body (model) parameter
}
if (postBody != null) // http body (model) parameter
request.AddParameter("application/json", postBody, ParameterType.RequestBody);
return (Object)RestClient.Execute(request);
}
/// <summary>
/// Make the HTTP request (Async)
/// 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>Task</returns>
/// <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 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) {
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(KeyValuePair<string, string> defaultHeader in this.DefaultHeaderMap)
foreach(var defaultHeader in _defaultHeaderMap)
request.AddHeader(defaultHeader.Key, defaultHeader.Value);
// add header parameter, if any
foreach(KeyValuePair<string, string> param in headerParams)
foreach(var param in headerParams)
request.AddHeader(param.Key, param.Value);
// add query parameter, if any
foreach(KeyValuePair<string, string> param in queryParams)
foreach(var param in queryParams)
request.AddQueryParameter(param.Key, param.Value);
// add form parameter, if any
foreach(KeyValuePair<string, string> param in formParams)
foreach(var param in formParams)
request.AddParameter(param.Key, param.Value);
// add file parameter, if any
foreach(KeyValuePair<string, FileParameter> param in fileParams)
foreach(var param in fileParams)
request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType);
if (postBody != null) {
request.AddParameter("application/json", postBody, ParameterType.RequestBody); // http body (model) parameter
}
if (postBody != null) // http body (model) parameter
request.AddParameter("application/json", postBody, ParameterType.RequestBody);
return (Object) await RestClient.ExecuteTaskAsync(request);
}
/// <summary>
/// Add default header
/// Add default header.
/// </summary>
/// <param name="key"> Header field name </param>
/// <param name="value"> Header field value </param>
/// <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);
public void AddDefaultHeader(string key, string value)
{
_defaultHeaderMap.Add(key, value);
}
/// <summary>
/// Get default header
/// Escape string (url-encoded).
/// </summary>
/// <returns>Dictionary of default header</returns>
public Dictionary<String, String> GetDefaultHeader() {
return DefaultHeaderMap;
/// <param name="str">String to be escaped.</param>
/// <returns>Escaped string.</returns>
public string EscapeString(string str)
{
return HttpUtility.UrlEncode(str);
}
/// <summary>
/// escape string (url-encoded)
/// Create FileParameter based on Stream.
/// </summary>
/// <param name="str">String to be escaped</param>
/// <returns>Escaped string</returns>
public string EscapeString(string str) {
return str;
}
/// <summary>
/// Create FileParameter based on Stream
/// </summary>
/// <param name="name">parameter name</param>
/// <param name="stream">Input stream</param>
/// <returns>FileParameter</returns>
/// <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) {
if (stream is FileStream)
return FileParameter.Create(name, stream.ReadAsBytes(), Path.GetFileName(((FileStream)stream).Name));
} else {
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
/// 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>
/// <param name="obj">The parameter (header, path, query, form).</param>
/// <returns>Formatted string.</returns>
public string ParameterToString(object obj)
{
if (obj is DateTime) {
if (obj is DateTime)
return ((DateTime)obj).ToString ("u");
} else if (obj is List<string>) {
else if (obj is List<string>)
return String.Join(",", obj as List<string>);
} else {
else
return Convert.ToString (obj);
}
}
/// <summary>
/// Deserialize the JSON string into a proper object
/// 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
/// <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 (Object)content;
} else if (type == typeof(Stream)) {
} else if (type == typeof(Stream))
{
String fileName, filePath;
if (String.IsNullOrEmpty (Configuration.TempFolderPath)) {
if (String.IsNullOrEmpty (Configuration.TempFolderPath))
filePath = System.IO.Path.GetTempPath ();
} else {
else
filePath = Configuration.TempFolderPath;
}
Regex regex = new Regex(@"Content-Disposition:.*filename=['""]?([^'""\s]+)['""]?$");
Match match = regex.Match(headers.ToString());
if (match.Success) {
// replace first and last " or ', if found
if (match.Success) // replace first and last " or ', if found
fileName = filePath + match.Value.Replace("\"", "").Replace("'","");
} else {
else
fileName = filePath + Guid.NewGuid().ToString();
}
File.WriteAllText (fileName, content);
return new FileStream(fileName, FileMode.Open);
} else if (type.Name.StartsWith("System.Nullable`1[[System.DateTime")) { // return a datetime object
} else if (type.Name.StartsWith("System.Nullable`1[[System.DateTime")) // return a datetime object
{
return DateTime.Parse(content, null, System.Globalization.DateTimeStyles.RoundtripKind);
} else if (type.Name == "String" || type.Name.StartsWith("System.Nullable")) { // return primitive
} else if (type.Name == "String" || type.Name.StartsWith("System.Nullable")) // return primitive type
{
return ConvertType(content, type);
}
@ -234,56 +236,61 @@ namespace IO.Swagger.Client {
{
return JsonConvert.DeserializeObject(content, type);
}
catch (IOException e) {
catch (IOException e)
{
throw new ApiException(500, e.Message);
}
}
/// <summary>
/// Serialize an object into JSON string
/// Serialize an object into JSON string.
/// </summary>
/// <param name="obj">Object</param>
/// <returns>JSON string</returns>
public string Serialize(object obj) {
/// <param name="obj">Object.</param>
/// <returns>JSON string.</returns>
public string Serialize(object obj)
{
try
{
return obj != null ? JsonConvert.SerializeObject(obj) : null;
}
catch (Exception e) {
catch (Exception e)
{
throw new ApiException(500, e.Message);
}
}
/// <summary>
/// Get the API key with prefix
/// Get the API key with prefix.
/// </summary>
/// <param name="obj">Object</param>
/// <returns>API key with prefix</returns>
/// <param name="apiKeyIdentifier">API key identifier (authentication scheme).</param>
/// <returns>API key with prefix.</returns>
public string GetApiKeyWithPrefix (string apiKeyIdentifier)
{
var apiKeyValue = "";
Configuration.ApiKey.TryGetValue (apiKeyIdentifier, out apiKeyValue);
var apiKeyPrefix = "";
if (Configuration.ApiKeyPrefix.TryGetValue (apiKeyIdentifier, out apiKeyPrefix)) {
if (Configuration.ApiKeyPrefix.TryGetValue (apiKeyIdentifier, out apiKeyPrefix))
return apiKeyPrefix + " " + apiKeyValue;
} else {
else
return apiKeyValue;
}
}
/// <summary>
/// Update parameters based on authentication
/// Update parameters based on authentication.
/// </summary>
/// <param name="QueryParams">Query parameters</param>
/// <param name="HeaderParams">Header parameters</param>
/// <param name="AuthSettings">Authentication settings</param>
public void UpdateParamsForAuth(Dictionary<String, String> queryParams, Dictionary<String, String> headerParams, string[] authSettings) {
/// <param name="queryParams">Query parameters.</param>
/// <param name="headerParams">Header parameters.</param>
/// <param name="authSettings">Authentication settings.</param>
public void UpdateParamsForAuth(Dictionary<String, String> queryParams, Dictionary<String, String> headerParams, string[] authSettings)
{
if (authSettings == null || authSettings.Length == 0)
return;
foreach (string auth in authSettings) {
foreach (string auth in authSettings)
{
// determine which one to use
switch(auth) {
switch(auth)
{
case "api_key":
headerParams["api_key"] = GetApiKeyWithPrefix("api_key");
@ -300,24 +307,26 @@ namespace IO.Swagger.Client {
break;
}
}
}
/// <summary>
/// Encode string in base64 format
/// Encode string in base64 format.
/// </summary>
/// <param name="text">String to be encoded</param>
public static string Base64Encode(string text) {
/// <param name="text">String to be encoded.</param>
/// <returns>Encoded string.</returns>
public static string Base64Encode(string text)
{
var textByte = System.Text.Encoding.UTF8.GetBytes(text);
return System.Convert.ToBase64String(textByte);
}
/// <summary>
/// Dynamically cast the object into target type
/// Dynamically cast the object into target type.
/// Ref: http://stackoverflow.com/questions/4925718/c-dynamic-runtime-cast
/// </summary>
/// <param name="dynamic">Object to be casted</param>
/// <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);
}

View File

@ -3,18 +3,20 @@ using System.Reflection;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
namespace IO.Swagger.Client {
namespace IO.Swagger.Client
{
/// <summary>
/// Represents a set of configuration settings
/// </summary>
public class Configuration{
public class Configuration
{
/// <summary>
/// Version of the package
/// Version of the package.
/// </summary>
/// <value>Version of the package.</value>
public const string Version = "1.0.0";
/// <summary>
@ -24,25 +26,25 @@ namespace IO.Swagger.Client {
public static ApiClient DefaultApiClient = new ApiClient();
/// <summary>
/// Gets or sets the username (HTTP basic authentication)
/// Gets or sets the username (HTTP basic authentication).
/// </summary>
/// <value>The username.</value>
public static String Username { get; set; }
/// <summary>
/// Gets or sets the password (HTTP basic authentication)
/// Gets or sets the password (HTTP basic authentication).
/// </summary>
/// <value>The password.</value>
public static String Password { get; set; }
/// <summary>
/// Gets or sets the API key based on the authentication name
/// Gets or sets the API key based on the authentication name.
/// </summary>
/// <value>The API key.</value>
public static Dictionary<String, String> ApiKey = new Dictionary<String, String>();
/// <summary>
/// Gets or sets the prefix (e.g. Token) of the API key based on the authentication name
/// Gets or sets the prefix (e.g. Token) of the API key based on the authentication name.
/// </summary>
/// <value>The prefix of the API key.</value>
public static Dictionary<String, String> ApiKeyPrefix = new Dictionary<String, String>();
@ -50,46 +52,46 @@ namespace IO.Swagger.Client {
private static string _tempFolderPath = Path.GetTempPath();
/// <summary>
/// Gets or sets the temporary folder path to store the files downloaded from the server
/// Gets or sets the temporary folder path to store the files downloaded from the server.
/// </summary>
/// <value>Folder path</value>
public static String TempFolderPath {
get {
return _tempFolderPath;
}
/// <value>Folder path.</value>
public static String TempFolderPath
{
get { return _tempFolderPath; }
set {
if (String.IsNullOrEmpty(value)) {
set
{
if (String.IsNullOrEmpty(value))
{
_tempFolderPath = value;
return;
}
// create the directory if it does not exist
if (!Directory.Exists(value)) {
if (!Directory.Exists(value))
Directory.CreateDirectory(value);
}
// check if the path contains directory separator at the end
if (value[value.Length - 1] == Path.DirectorySeparatorChar) {
if (value[value.Length - 1] == Path.DirectorySeparatorChar)
_tempFolderPath = value;
} else {
else
_tempFolderPath = value + Path.DirectorySeparatorChar;
}
}
}
/// <summary>
/// Return a string contain essential information for debugging
/// Returns a string with essential information for debugging.
/// </summary>
/// <value>Folder path</value>
public static String ToDebugReport() {
/// <value>Debugging Report</value>
public static String ToDebugReport()
{
String report = "C# SDK () Debug Report:\n";
report += " OS: " + Environment.OSVersion + "\n";
report += " .NET Framework Version: " + Assembly
.GetExecutingAssembly()
.GetReferencedAssemblies()
.Where(x => x.Name == "System.Core").First().Version.ToString() + "\n";
report += " Swagger Spec Version: 1.0.0\n";
report += " Version of the API: 1.0.0\n";
report += " SDK Package Version: 1.0.0\n";
return report;

View File

@ -40,6 +40,7 @@
<Reference Include="nunit.framework">
<HintPath>packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System.Web" />
</ItemGroup>
<ItemGroup>
<Compile Include="Lib\SwaggerClient\src\main\csharp\IO\Swagger\Api\PetApi.cs" />

View File

@ -2,7 +2,7 @@
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
<MonoDevelop.Ide.Workbench ActiveDocument="TestPet.cs">
<Files>
<File FileName="TestPet.cs" Line="57" Column="19" />
<File FileName="TestPet.cs" Line="31" Column="19" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints>