mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 03:18:53 +00:00
Merge pull request #1643 from wing328/csharp_refactor
[C#] refactor code to support multiple API keys in multi-threading environment
This commit is contained in:
commit
9367b7f6a6
@ -128,6 +128,8 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
sourceFolder + File.separator + clientPackage.replace(".", java.io.File.separator), "ApiClient.cs"));
|
||||
supportingFiles.add(new SupportingFile("ApiException.mustache",
|
||||
sourceFolder + File.separator + clientPackage.replace(".", java.io.File.separator), "ApiException.cs"));
|
||||
supportingFiles.add(new SupportingFile("ApiResponse.mustache",
|
||||
sourceFolder + File.separator + clientPackage.replace(".", java.io.File.separator), "ApiResponse.cs"));
|
||||
supportingFiles.add(new SupportingFile("Newtonsoft.Json.dll", "bin", "Newtonsoft.Json.dll"));
|
||||
supportingFiles.add(new SupportingFile("RestSharp.dll", "bin", "RestSharp.dll"));
|
||||
supportingFiles.add(new SupportingFile("compile.mustache", "", "compile.bat"));
|
||||
|
@ -18,23 +18,23 @@ namespace {{packageName}}.Client
|
||||
/// </summary>
|
||||
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}}")
|
||||
{
|
||||
BasePath = basePath;
|
||||
RestClient = new RestClient(BasePath);
|
||||
if (String.IsNullOrEmpty(basePath))
|
||||
throw new ArgumentException("basePath cannot be empty");
|
||||
|
||||
RestClient = new RestClient(basePath);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the base path.
|
||||
/// Gets or sets the default API client for making HTTP calls.
|
||||
/// </summary>
|
||||
/// <value>The base path</value>
|
||||
public string BasePath { get; set; }
|
||||
/// <value>The default API client.</value>
|
||||
public static ApiClient Default = new ApiClient();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the RestClient.
|
||||
@ -42,38 +42,14 @@ namespace {{packageName}}.Client
|
||||
/// <value>An instance of the RestClient</value>
|
||||
public RestClient RestClient { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default header.
|
||||
/// </summary>
|
||||
public Dictionary<String, String> DefaultHeader
|
||||
{
|
||||
get { return _defaultHeaderMap; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the status code of the previous request
|
||||
/// </summary>
|
||||
public int StatusCode { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the response headers of the previous request
|
||||
/// </summary>
|
||||
public Dictionary<String, String> ResponseHeaders { get; private set; }
|
||||
|
||||
// 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)
|
||||
Dictionary<String, FileParameter> fileParams, Dictionary<String, String> pathParams)
|
||||
{
|
||||
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 path parameter, if any
|
||||
foreach(var param in pathParams)
|
||||
request.AddParameter(param.Key, param.Value, ParameterType.UrlSegment);
|
||||
@ -111,18 +87,15 @@ namespace {{packageName}}.Client
|
||||
/// <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)
|
||||
Dictionary<String, FileParameter> fileParams, Dictionary<String, String> pathParams)
|
||||
{
|
||||
var request = PrepareRequest(
|
||||
path, method, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings);
|
||||
path, method, queryParams, postBody, headerParams, formParams, fileParams, pathParams);
|
||||
var response = RestClient.Execute(request);
|
||||
StatusCode = (int) response.StatusCode;
|
||||
ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString());
|
||||
return (Object) response;
|
||||
}
|
||||
|
||||
@ -137,32 +110,18 @@ namespace {{packageName}}.Client
|
||||
/// <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)
|
||||
Dictionary<String, FileParameter> fileParams, Dictionary<String, String> pathParams)
|
||||
{
|
||||
var request = PrepareRequest(
|
||||
path, method, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings);
|
||||
path, method, queryParams, postBody, headerParams, formParams, fileParams, pathParams);
|
||||
var response = await RestClient.ExecuteTaskAsync(request);
|
||||
StatusCode = (int)response.StatusCode;
|
||||
ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString());
|
||||
return (Object)response;
|
||||
}
|
||||
|
||||
/// <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>
|
||||
@ -286,68 +245,6 @@ namespace {{packageName}}.Client
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the API key with prefix.
|
||||
/// </summary>
|
||||
/// <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))
|
||||
return apiKeyPrefix + " " + apiKeyValue;
|
||||
else
|
||||
return apiKeyValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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)
|
||||
{
|
||||
if (authSettings == null || authSettings.Length == 0)
|
||||
return;
|
||||
|
||||
foreach (string auth in authSettings)
|
||||
{
|
||||
// determine which one to use
|
||||
switch(auth)
|
||||
{
|
||||
{{#authMethods}}
|
||||
case "{{name}}":
|
||||
{{#isApiKey}}{{#isKeyInHeader}}
|
||||
var apiKeyValue = GetApiKeyWithPrefix("{{keyParamName}}");
|
||||
if (!String.IsNullOrEmpty(apiKeyValue))
|
||||
{
|
||||
headerParams["{{keyParamName}}"] = apiKeyValue;
|
||||
}{{/isKeyInHeader}}{{#isKeyInQuery}}
|
||||
var apiKeyValue = GetApiKeyWithPrefix("{{keyParamName}}");
|
||||
if (!String.IsNullOrEmpty(apiKeyValue))
|
||||
{
|
||||
queryParams["{{keyParamName}}"] = apiKeyValue;
|
||||
}{{/isKeyInQuery}}{{/isApiKey}}{{#isBasic}}
|
||||
if (!String.IsNullOrEmpty(Configuration.Username) || !String.IsNullOrEmpty(Configuration.Password))
|
||||
{
|
||||
headerParams["Authorization"] = "Basic " + Base64Encode(Configuration.Username + ":" + Configuration.Password);
|
||||
}{{/isBasic}}{{#isOAuth}}
|
||||
if (!String.IsNullOrEmpty(Configuration.AccessToken))
|
||||
{
|
||||
headerParams["Authorization"] = "Bearer " + Configuration.AccessToken;
|
||||
}{{/isOAuth}}
|
||||
break;
|
||||
{{/authMethods}}
|
||||
default:
|
||||
//show warning about security definition not found
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Select the Accept header's value from the given accepts array:
|
||||
/// if JSON exists in the given array, use it;
|
||||
|
@ -1,47 +1,50 @@
|
||||
using System;
|
||||
|
||||
namespace {{packageName}}.Client {
|
||||
/// <summary>
|
||||
/// API Exception
|
||||
/// </summary>
|
||||
public class ApiException : Exception {
|
||||
/// <summary>
|
||||
/// Gets or sets the error code (HTTP status code)
|
||||
/// </summary>
|
||||
/// <value>The error code (HTTP status code).</value>
|
||||
public int ErrorCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the error content (body json object)
|
||||
/// </summary>
|
||||
/// <value>The error content (Http response body).</value>
|
||||
public dynamic ErrorContent { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiException"/> class.
|
||||
/// </summary>
|
||||
public ApiException() {}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="errorCode">HTTP status code.</param>
|
||||
/// <param name="message">Error message.</param>
|
||||
public ApiException(int errorCode, string message) : base(message) {
|
||||
this.ErrorCode = errorCode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="errorCode">HTTP status code.</param>
|
||||
/// <param name="message">Error message.</param>
|
||||
/// <param name="errorContent">Error content.</param>
|
||||
public ApiException(int errorCode, string message, dynamic errorContent = null) : base(message) {
|
||||
this.ErrorCode = errorCode;
|
||||
this.ErrorContent = errorContent;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace {{packageName}}.Client
|
||||
{
|
||||
/// <summary>
|
||||
/// API Exception
|
||||
/// </summary>
|
||||
public class ApiException : Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the error code (HTTP status code)
|
||||
/// </summary>
|
||||
/// <value>The error code (HTTP status code).</value>
|
||||
public int ErrorCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the error content (body json object)
|
||||
/// </summary>
|
||||
/// <value>The error content (Http response body).</value>
|
||||
public dynamic ErrorContent { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiException"/> class.
|
||||
/// </summary>
|
||||
public ApiException() {}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="errorCode">HTTP status code.</param>
|
||||
/// <param name="message">Error message.</param>
|
||||
public ApiException(int errorCode, string message) : base(message)
|
||||
{
|
||||
this.ErrorCode = errorCode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="errorCode">HTTP status code.</param>
|
||||
/// <param name="message">Error message.</param>
|
||||
/// <param name="errorContent">Error content.</param>
|
||||
public ApiException(int errorCode, string message, dynamic errorContent = null) : base(message)
|
||||
{
|
||||
this.ErrorCode = errorCode;
|
||||
this.ErrorContent = errorContent;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace {{packageName}}.Client
|
||||
{
|
||||
/// <summary>
|
||||
/// API Response
|
||||
/// </summary>
|
||||
public class ApiResponse<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the status code (HTTP status code)
|
||||
/// </summary>
|
||||
/// <value>The status code.</value>
|
||||
public int StatusCode { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the HTTP headers
|
||||
/// </summary>
|
||||
/// <value>HTTP headers</value>
|
||||
public IDictionary<string, string> Headers { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the data (parsed HTTP body)
|
||||
/// </summary>
|
||||
/// <value>The data.</value>
|
||||
public T Data { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiResponse"/> class.
|
||||
/// </summary>
|
||||
/// <param name="statusCode">HTTP status code.</param>
|
||||
/// <param name="message">Error message.</param>
|
||||
/// <param name="data">Data (parsed HTTP body)</param>
|
||||
public ApiResponse(int statusCode, IDictionary<string, string> headers, T data)
|
||||
{
|
||||
this.StatusCode= statusCode;
|
||||
this.Headers = headers;
|
||||
this.Data = data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -12,6 +12,17 @@ namespace {{packageName}}.Client
|
||||
/// </summary>
|
||||
public class Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the Configuration class.
|
||||
/// </summary>
|
||||
/// <param name="apiClient">Api client.</param>
|
||||
public Configuration(ApiClient apiClient=null)
|
||||
{
|
||||
if (apiClient == null)
|
||||
ApiClient = ApiClient.Default;
|
||||
else
|
||||
ApiClient = apiClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Version of the package.
|
||||
@ -19,41 +30,84 @@ namespace {{packageName}}.Client
|
||||
/// <value>Version of the package.</value>
|
||||
public const string Version = "{{packageVersion}}";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default Configuration.
|
||||
/// </summary>
|
||||
/// <value>Configuration.</value>
|
||||
public static Configuration Default = new Configuration();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default API client for making HTTP calls.
|
||||
/// </summary>
|
||||
/// <value>The API client.</value>
|
||||
public static ApiClient DefaultApiClient = new ApiClient();
|
||||
|
||||
public ApiClient ApiClient;
|
||||
|
||||
private readonly Dictionary<String, String> _defaultHeaderMap = new Dictionary<String, String>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default header.
|
||||
/// </summary>
|
||||
public Dictionary<String, String> DefaultHeader
|
||||
{
|
||||
get { return _defaultHeaderMap; }
|
||||
}
|
||||
|
||||
/// <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>
|
||||
/// Gets or sets the username (HTTP basic authentication).
|
||||
/// </summary>
|
||||
/// <value>The username.</value>
|
||||
public static String Username { get; set; }
|
||||
public String Username { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the password (HTTP basic authentication).
|
||||
/// </summary>
|
||||
/// <value>The password.</value>
|
||||
public static String Password { get; set; }
|
||||
public String Password { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the access token for OAuth2 authentication.
|
||||
/// </summary>
|
||||
/// <value>The access token.</value>
|
||||
public static String AccessToken { get; set; }
|
||||
public String AccessToken { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 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>();
|
||||
public 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.
|
||||
/// </summary>
|
||||
/// <value>The prefix of the API key.</value>
|
||||
public static Dictionary<String, String> ApiKeyPrefix = new Dictionary<String, String>();
|
||||
public Dictionary<String, String> ApiKeyPrefix = new Dictionary<String, String>();
|
||||
|
||||
/// <summary>
|
||||
/// Get the API key with prefix.
|
||||
/// </summary>
|
||||
/// <param name="apiKeyIdentifier">API key identifier (authentication scheme).</param>
|
||||
/// <returns>API key with prefix.</returns>
|
||||
public string GetApiKeyWithPrefix (string apiKeyIdentifier)
|
||||
{
|
||||
var apiKeyValue = "";
|
||||
ApiKey.TryGetValue (apiKeyIdentifier, out apiKeyValue);
|
||||
var apiKeyPrefix = "";
|
||||
if (ApiKeyPrefix.TryGetValue (apiKeyIdentifier, out apiKeyPrefix))
|
||||
return apiKeyPrefix + " " + apiKeyValue;
|
||||
else
|
||||
return apiKeyValue;
|
||||
}
|
||||
|
||||
private static string _tempFolderPath = Path.GetTempPath();
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using RestSharp;
|
||||
using {{packageName}}.Client;
|
||||
{{#hasImport}}using {{packageName}}.Model;
|
||||
@ -22,7 +23,7 @@ namespace {{packageName}}.Api
|
||||
/// {{notes}}
|
||||
/// </remarks>
|
||||
{{#allParams}}/// <param name="{{paramName}}">{{description}}</param>
|
||||
{{/allParams}}/// <returns>{{#returnType}}{{^returnContainer}}{{{returnType}}}{{/returnContainer}}{{/returnType}}</returns>
|
||||
{{/allParams}}/// <returns>{{#returnType}}{{returnType}}{{/returnType}}</returns>
|
||||
{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} {{operationId}} ({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = null{{/optionalMethodArgument}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
|
||||
|
||||
/// <summary>
|
||||
@ -32,8 +33,28 @@ namespace {{packageName}}.Api
|
||||
/// {{notes}}
|
||||
/// </remarks>
|
||||
{{#allParams}}/// <param name="{{paramName}}">{{description}}</param>
|
||||
{{/allParams}}/// <returns>{{#returnType}}{{^returnContainer}}{{{returnType}}}{{/returnContainer}}{{/returnType}}</returns>
|
||||
{{/allParams}}/// <returns>ApiResponse of {{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}Object(void){{/returnType}}</returns>
|
||||
ApiResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Object{{/returnType}}> {{operationId}}WithHttpInfo ({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = null{{/optionalMethodArgument}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
|
||||
|
||||
/// <summary>
|
||||
/// {{summary}}
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// {{notes}}
|
||||
/// </remarks>
|
||||
{{#allParams}}/// <param name="{{paramName}}">{{description}}</param>
|
||||
{{/allParams}}/// <returns>Task of {{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}void{{/returnType}}</returns>
|
||||
{{#returnType}}System.Threading.Tasks.Task<{{{returnType}}}>{{/returnType}}{{^returnType}}System.Threading.Tasks.Task{{/returnType}} {{operationId}}Async ({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = null{{/optionalMethodArgument}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
|
||||
|
||||
/// <summary>
|
||||
/// {{summary}}
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// {{notes}}
|
||||
/// </remarks>
|
||||
{{#allParams}}/// <param name="{{paramName}}">{{description}}</param>
|
||||
{{/allParams}}/// <returns>Task of ApiResponse{{#returnType}} ({{returnType}}){{/returnType}}</returns>
|
||||
System.Threading.Tasks.Task<ApiResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Object{{/returnType}}>> {{operationId}}AsyncWithHttpInfo ({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = null{{/optionalMethodArgument}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
|
||||
{{/operation}}
|
||||
}
|
||||
|
||||
@ -42,60 +63,94 @@ namespace {{packageName}}.Api
|
||||
/// </summary>
|
||||
public class {{classname}} : I{{classname}}
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="{{classname}}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiClient"> an instance of ApiClient (optional)</param>
|
||||
/// <returns></returns>
|
||||
public {{classname}}(ApiClient apiClient = null)
|
||||
{
|
||||
if (apiClient == null) // use the default one in Configuration
|
||||
this.ApiClient = Configuration.DefaultApiClient;
|
||||
else
|
||||
this.ApiClient = apiClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="{{classname}}"/> class.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public {{classname}}(String basePath)
|
||||
{
|
||||
this.ApiClient = new ApiClient(basePath);
|
||||
this.Configuration = new Configuration(new ApiClient(basePath));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the base path of the API client.
|
||||
/// Initializes a new instance of the <see cref="{{classname}}"/> class
|
||||
/// using Configuration object
|
||||
/// </summary>
|
||||
/// <param name="basePath">The base path</param>
|
||||
/// <value>The base path</value>
|
||||
public void SetBasePath(String basePath)
|
||||
/// <param name="configuration">An instance of Configuration</param>
|
||||
/// <returns></returns>
|
||||
public {{classname}}(Configuration configuration = null)
|
||||
{
|
||||
this.ApiClient.BasePath = basePath;
|
||||
if (configuration == null) // use the default one in Configuration
|
||||
this.Configuration = Configuration.Default;
|
||||
else
|
||||
this.Configuration = configuration;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the base path of the API client.
|
||||
/// </summary>
|
||||
/// <value>The base path</value>
|
||||
public String GetBasePath()
|
||||
{
|
||||
return this.ApiClient.BasePath;
|
||||
return this.Configuration.ApiClient.RestClient.BaseUrl.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the base path of the API client.
|
||||
/// </summary>
|
||||
/// <value>The base path</value>
|
||||
[Obsolete("SetBasePath is deprecated, please do 'Configuraiton.ApiClient = new ApiClient(\"http://new-path\")' instead.")]
|
||||
public void SetBasePath(String basePath)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the API client.
|
||||
/// Gets or sets the configuration object
|
||||
/// </summary>
|
||||
/// <value>An instance of the ApiClient</value>
|
||||
public ApiClient ApiClient {get; set;}
|
||||
|
||||
/// <value>An instance of the Configuration</value>
|
||||
public Configuration Configuration {get; set;}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default header.
|
||||
/// </summary>
|
||||
/// <returns>Dictionary of HTTP header</returns>
|
||||
[Obsolete("DefaultHeader is deprecated, please use Configuration.DefaultHeader instead.")]
|
||||
public Dictionary<String, String> DefaultHeader()
|
||||
{
|
||||
return this.Configuration.DefaultHeader;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add default header.
|
||||
/// </summary>
|
||||
/// <param name="key">Header field name.</param>
|
||||
/// <param name="value">Header field value.</param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("AddDefaultHeader is deprecated, please use Configuration.AddDefaultHeader instead.")]
|
||||
public void AddDefaultHeader(string key, string value)
|
||||
{
|
||||
this.Configuration.AddDefaultHeader(key, value);
|
||||
}
|
||||
|
||||
{{#operation}}
|
||||
/// <summary>
|
||||
/// {{summary}} {{notes}}
|
||||
/// </summary>
|
||||
{{#allParams}}/// <param name="{{paramName}}">{{description}}</param>
|
||||
{{/allParams}}/// <returns>{{#returnType}}{{^returnContainer}}{{{returnType}}}{{/returnContainer}}{{/returnType}}</returns>
|
||||
{{/allParams}}/// <returns>{{#returnType}}{{returnType}}{{/returnType}}</returns>
|
||||
public {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} {{operationId}} ({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = null{{/optionalMethodArgument}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
|
||||
{
|
||||
{{#returnType}}ApiResponse<{{{returnType}}}> response = {{operationId}}WithHttpInfo({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
|
||||
return response.Data;{{/returnType}}{{^returnType}}{{operationId}}WithHttpInfo({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{/returnType}}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// {{summary}} {{notes}}
|
||||
/// </summary>
|
||||
{{#allParams}}/// <param name="{{paramName}}">{{description}}</param>
|
||||
{{/allParams}}/// <returns>ApiResponse of {{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}Object(void){{/returnType}}</returns>
|
||||
public ApiResponse<{{#returnType}} {{{returnType}}} {{/returnType}}{{^returnType}}Object{{/returnType}}> {{operationId}}WithHttpInfo ({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = null{{/optionalMethodArgument}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
|
||||
{
|
||||
{{#allParams}}{{#required}}
|
||||
// verify the required parameter '{{paramName}}' is set
|
||||
@ -106,7 +161,7 @@ namespace {{packageName}}.Api
|
||||
|
||||
var pathParams = new Dictionary<String, String>();
|
||||
var queryParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>(Configuration.DefaultHeader);
|
||||
var formParams = new Dictionary<String, String>();
|
||||
var fileParams = new Dictionary<String, FileParameter>();
|
||||
String postBody = null;
|
||||
@ -115,44 +170,85 @@ namespace {{packageName}}.Api
|
||||
String[] http_header_accepts = new String[] {
|
||||
{{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}}
|
||||
};
|
||||
String http_header_accept = ApiClient.SelectHeaderAccept(http_header_accepts);
|
||||
String http_header_accept = Configuration.ApiClient.SelectHeaderAccept(http_header_accepts);
|
||||
if (http_header_accept != null)
|
||||
headerParams.Add("Accept", ApiClient.SelectHeaderAccept(http_header_accepts));
|
||||
headerParams.Add("Accept", Configuration.ApiClient.SelectHeaderAccept(http_header_accepts));
|
||||
|
||||
// set "format" to json by default
|
||||
// e.g. /pet/{petId}.{format} becomes /pet/{petId}.json
|
||||
pathParams.Add("format", "json");
|
||||
{{#pathParams}}if ({{paramName}} != null) pathParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // path parameter
|
||||
{{#pathParams}}if ({{paramName}} != null) pathParams.Add("{{baseName}}", Configuration.ApiClient.ParameterToString({{paramName}})); // path parameter
|
||||
{{/pathParams}}
|
||||
{{#queryParams}}if ({{paramName}} != null) queryParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // query parameter
|
||||
{{#queryParams}}if ({{paramName}} != null) queryParams.Add("{{baseName}}", Configuration.ApiClient.ParameterToString({{paramName}})); // query parameter
|
||||
{{/queryParams}}
|
||||
{{#headerParams}}if ({{paramName}} != null) headerParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // header parameter
|
||||
{{#headerParams}}if ({{paramName}} != null) headerParams.Add("{{baseName}}", Configuration.ApiClient.ParameterToString({{paramName}})); // header parameter
|
||||
{{/headerParams}}
|
||||
{{#formParams}}if ({{paramName}} != null) {{#isFile}}fileParams.Add("{{baseName}}", ApiClient.ParameterToFile("{{baseName}}", {{paramName}}));{{/isFile}}{{^isFile}}formParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // form parameter{{/isFile}}
|
||||
{{#formParams}}if ({{paramName}} != null) {{#isFile}}fileParams.Add("{{baseName}}", Configuration.ApiClient.ParameterToFile("{{baseName}}", {{paramName}}));{{/isFile}}{{^isFile}}formParams.Add("{{baseName}}", Configuration.ApiClient.ParameterToString({{paramName}})); // form parameter{{/isFile}}
|
||||
{{/formParams}}
|
||||
{{#bodyParam}}postBody = ApiClient.Serialize({{paramName}}); // http body (model) parameter
|
||||
{{#bodyParam}}postBody = Configuration.ApiClient.Serialize({{paramName}}); // http body (model) parameter
|
||||
{{/bodyParam}}
|
||||
|
||||
// authentication setting, if any
|
||||
String[] authSettings = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} };
|
||||
|
||||
{{#authMethods}}
|
||||
// authentication ({{name}}) required
|
||||
{{#isApiKey}}{{#isKeyInHeader}}
|
||||
var apiKeyValue = Configuration.GetApiKeyWithPrefix("{{keyParamName}}");
|
||||
if (!String.IsNullOrEmpty(apiKeyValue))
|
||||
{
|
||||
headerParams["{{keyParamName}}"] = apiKeyValue;
|
||||
}{{/isKeyInHeader}}{{#isKeyInQuery}}
|
||||
var apiKeyValue = Configuration.GetApiKeyWithPrefix("{{keyParamName}}");
|
||||
if (!String.IsNullOrEmpty(apiKeyValue))
|
||||
{
|
||||
queryParams["{{keyParamName}}"] = apiKeyValue;
|
||||
}{{/isKeyInQuery}}{{/isApiKey}}{{#isBasic}}
|
||||
// http basic authentication required
|
||||
if (!String.IsNullOrEmpty(Configuration.Username) || !String.IsNullOrEmpty(Configuration.Password))
|
||||
{
|
||||
headerParams["Authorization"] = "Basic " + Base64Encode(Configuration.Username + ":" + Configuration.Password);
|
||||
}{{/isBasic}}{{#isOAuth}}
|
||||
// oauth required
|
||||
if (!String.IsNullOrEmpty(Configuration.AccessToken))
|
||||
{
|
||||
headerParams["Authorization"] = "Bearer " + Configuration.AccessToken;
|
||||
}{{/isOAuth}}
|
||||
{{/authMethods}}
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = (IRestResponse) ApiClient.CallApi(path_, Method.{{httpMethod}}, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings);
|
||||
IRestResponse response = (IRestResponse) Configuration.ApiClient.CallApi(path_, Method.{{httpMethod}}, queryParams, postBody, headerParams, formParams, fileParams, pathParams);
|
||||
|
||||
int statusCode = (int) response.StatusCode;
|
||||
|
||||
if (((int)response.StatusCode) >= 400)
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling {{operationId}}: " + response.Content, response.Content);
|
||||
else if (((int)response.StatusCode) == 0)
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling {{operationId}}: " + response.ErrorMessage, response.ErrorMessage);
|
||||
if (statusCode >= 400)
|
||||
throw new ApiException (statusCode, "Error calling {{operationId}}: " + response.Content, response.Content);
|
||||
else if (statusCode == 0)
|
||||
throw new ApiException (statusCode, "Error calling {{operationId}}: " + response.ErrorMessage, response.ErrorMessage);
|
||||
|
||||
{{#returnType}}return ({{{returnType}}}) ApiClient.Deserialize(response, typeof({{{returnType}}}));{{/returnType}}{{^returnType}}return;{{/returnType}}
|
||||
{{#returnType}}return new ApiResponse<{{{returnType}}}>(statusCode,
|
||||
response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
|
||||
({{{returnType}}}) Configuration.ApiClient.Deserialize(response, typeof({{{returnType}}})));{{/returnType}}
|
||||
{{^returnType}}return new ApiResponse<Object>(statusCode,
|
||||
response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
|
||||
null);{{/returnType}}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// {{summary}} {{notes}}
|
||||
/// </summary>
|
||||
{{#allParams}}/// <param name="{{paramName}}">{{description}}</param>
|
||||
{{/allParams}}/// <returns>{{#returnType}}{{^returnContainer}}{{{returnType}}}{{/returnContainer}}{{/returnType}}</returns>
|
||||
{{/allParams}}/// <returns>Task of {{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}void{{/returnType}}</returns>
|
||||
{{#returnType}}public async System.Threading.Tasks.Task<{{{returnType}}}>{{/returnType}}{{^returnType}}public async System.Threading.Tasks.Task{{/returnType}} {{operationId}}Async ({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = null{{/optionalMethodArgument}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
|
||||
{
|
||||
{{#returnType}}ApiResponse<{{{returnType}}}> response = await {{operationId}}AsyncWithHttpInfo({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
|
||||
return response.Data;{{/returnType}}{{^returnType}}await {{operationId}}AsyncWithHttpInfo({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{/returnType}}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// {{summary}} {{notes}}
|
||||
/// </summary>
|
||||
{{#allParams}}/// <param name="{{paramName}}">{{description}}</param>
|
||||
{{/allParams}}/// <returns>Task of ApiResponse{{#returnType}} ({{returnType}}){{/returnType}}</returns>
|
||||
public async System.Threading.Tasks.Task<ApiResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Object{{/returnType}}>> {{operationId}}AsyncWithHttpInfo ({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = null{{/optionalMethodArgument}}{{/required}}{{#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 {{operationId}}");
|
||||
@ -171,34 +267,65 @@ namespace {{packageName}}.Api
|
||||
String[] http_header_accepts = new String[] {
|
||||
{{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}}
|
||||
};
|
||||
String http_header_accept = ApiClient.SelectHeaderAccept(http_header_accepts);
|
||||
String http_header_accept = Configuration.ApiClient.SelectHeaderAccept(http_header_accepts);
|
||||
if (http_header_accept != null)
|
||||
headerParams.Add("Accept", ApiClient.SelectHeaderAccept(http_header_accepts));
|
||||
headerParams.Add("Accept", Configuration.ApiClient.SelectHeaderAccept(http_header_accepts));
|
||||
|
||||
// set "format" to json by default
|
||||
// e.g. /pet/{petId}.{format} becomes /pet/{petId}.json
|
||||
pathParams.Add("format", "json");
|
||||
{{#pathParams}}if ({{paramName}} != null) pathParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // path parameter
|
||||
{{#pathParams}}if ({{paramName}} != null) pathParams.Add("{{baseName}}", Configuration.ApiClient.ParameterToString({{paramName}})); // path parameter
|
||||
{{/pathParams}}
|
||||
{{#queryParams}}if ({{paramName}} != null) queryParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // query parameter
|
||||
{{#queryParams}}if ({{paramName}} != null) queryParams.Add("{{baseName}}", Configuration.ApiClient.ParameterToString({{paramName}})); // query parameter
|
||||
{{/queryParams}}
|
||||
{{#headerParams}}if ({{paramName}} != null) headerParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // header parameter
|
||||
{{#headerParams}}if ({{paramName}} != null) headerParams.Add("{{baseName}}", Configuration.ApiClient.ParameterToString({{paramName}})); // header parameter
|
||||
{{/headerParams}}
|
||||
{{#formParams}}if ({{paramName}} != null) {{#isFile}}fileParams.Add("{{baseName}}", ApiClient.ParameterToFile("{{baseName}}", {{paramName}}));{{/isFile}}{{^isFile}}formParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // form parameter{{/isFile}}
|
||||
{{#formParams}}if ({{paramName}} != null) {{#isFile}}fileParams.Add("{{baseName}}", Configuration.ApiClient.ParameterToFile("{{baseName}}", {{paramName}}));{{/isFile}}{{^isFile}}formParams.Add("{{baseName}}", Configuration.ApiClient.ParameterToString({{paramName}})); // form parameter{{/isFile}}
|
||||
{{/formParams}}
|
||||
{{#bodyParam}}postBody = ApiClient.Serialize({{paramName}}); // http body (model) parameter
|
||||
{{#bodyParam}}postBody = Configuration.ApiClient.Serialize({{paramName}}); // http body (model) parameter
|
||||
{{/bodyParam}}
|
||||
|
||||
// authentication setting, if any
|
||||
String[] authSettings = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} };
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path_, Method.{{httpMethod}}, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings);
|
||||
if (((int)response.StatusCode) >= 400)
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling {{operationId}}: " + response.Content, response.Content);
|
||||
|
||||
{{#returnType}}return ({{{returnType}}}) ApiClient.Deserialize(response, typeof({{{returnType}}}));{{/returnType}}{{^returnType}}
|
||||
return;{{/returnType}}
|
||||
{{#authMethods}}
|
||||
// authentication ({{name}}) required
|
||||
{{#isApiKey}}{{#isKeyInHeader}}
|
||||
var apiKeyValue = Configuration.GetApiKeyWithPrefix("{{keyParamName}}");
|
||||
if (!String.IsNullOrEmpty(apiKeyValue))
|
||||
{
|
||||
headerParams["{{keyParamName}}"] = apiKeyValue;
|
||||
}{{/isKeyInHeader}}{{#isKeyInQuery}}
|
||||
var apiKeyValue = Configuration.GetApiKeyWithPrefix("{{keyParamName}}");
|
||||
if (!String.IsNullOrEmpty(apiKeyValue))
|
||||
{
|
||||
queryParams["{{keyParamName}}"] = apiKeyValue;
|
||||
}{{/isKeyInQuery}}{{/isApiKey}}{{#isBasic}}
|
||||
// http basic authentication required
|
||||
if (!String.IsNullOrEmpty(Configuration.Username) || !String.IsNullOrEmpty(Configuration.Password))
|
||||
{
|
||||
headerParams["Authorization"] = "Basic " + Base64Encode(Configuration.Username + ":" + Configuration.Password);
|
||||
}{{/isBasic}}{{#isOAuth}}
|
||||
// oauth required
|
||||
if (!String.IsNullOrEmpty(Configuration.AccessToken))
|
||||
{
|
||||
headerParams["Authorization"] = "Bearer " + Configuration.AccessToken;
|
||||
}{{/isOAuth}}
|
||||
{{/authMethods}}
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, Method.{{httpMethod}}, queryParams, postBody, headerParams, formParams, fileParams, pathParams);
|
||||
|
||||
int statusCode = (int) response.StatusCode;
|
||||
|
||||
if (statusCode >= 400)
|
||||
throw new ApiException (statusCode, "Error calling {{operationId}}: " + response.Content, response.Content);
|
||||
else if (statusCode == 0)
|
||||
throw new ApiException (statusCode, "Error calling {{operationId}}: " + response.ErrorMessage, response.ErrorMessage);
|
||||
|
||||
{{#returnType}}return new ApiResponse<{{{returnType}}}>(statusCode,
|
||||
response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
|
||||
({{{returnType}}}) Configuration.ApiClient.Deserialize(response, typeof({{{returnType}}})));{{/returnType}}
|
||||
{{^returnType}}return new ApiResponse<Object>(statusCode,
|
||||
response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
|
||||
null);{{/returnType}}
|
||||
}
|
||||
{{/operation}}
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ namespace {{packageName}}.Model
|
||||
this.{{name}} == other.{{name}} ||
|
||||
this.{{name}} != null &&
|
||||
this.{{name}}.SequenceEqual(other.{{name}})
|
||||
){{#hasMore}} && {{/hasMore}}{{/isNotContainer}}{{/vars}};
|
||||
){{#hasMore}} && {{/hasMore}}{{/isNotContainer}}{{/vars}}{{^vars}}false{{/vars}};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using RestSharp;
|
||||
using IO.Swagger.Client;
|
||||
using IO.Swagger.Model;
|
||||
@ -20,7 +21,7 @@ namespace IO.Swagger.Api
|
||||
/// <remarks>
|
||||
/// Returns a map of status codes to quantities
|
||||
/// </remarks>
|
||||
/// <returns></returns>
|
||||
/// <returns>Dictionary<string, int?></returns>
|
||||
Dictionary<string, int?> GetInventory ();
|
||||
|
||||
/// <summary>
|
||||
@ -29,8 +30,26 @@ namespace IO.Swagger.Api
|
||||
/// <remarks>
|
||||
/// Returns a map of status codes to quantities
|
||||
/// </remarks>
|
||||
/// <returns></returns>
|
||||
/// <returns>ApiResponse of Dictionary<string, int?></returns>
|
||||
ApiResponse<Dictionary<string, int?>> GetInventoryWithHttpInfo ();
|
||||
|
||||
/// <summary>
|
||||
/// Returns pet inventories by status
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Returns a map of status codes to quantities
|
||||
/// </remarks>
|
||||
/// <returns>Task of Dictionary<string, int?></returns>
|
||||
System.Threading.Tasks.Task<Dictionary<string, int?>> GetInventoryAsync ();
|
||||
|
||||
/// <summary>
|
||||
/// Returns pet inventories by status
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Returns a map of status codes to quantities
|
||||
/// </remarks>
|
||||
/// <returns>Task of ApiResponse (Dictionary<string, int?>)</returns>
|
||||
System.Threading.Tasks.Task<ApiResponse<Dictionary<string, int?>>> GetInventoryAsyncWithHttpInfo ();
|
||||
|
||||
/// <summary>
|
||||
/// Place an order for a pet
|
||||
@ -49,8 +68,28 @@ namespace IO.Swagger.Api
|
||||
///
|
||||
/// </remarks>
|
||||
/// <param name="body">order placed for purchasing the pet</param>
|
||||
/// <returns>Order</returns>
|
||||
/// <returns>ApiResponse of Order</returns>
|
||||
ApiResponse<Order> PlaceOrderWithHttpInfo (Order body = null);
|
||||
|
||||
/// <summary>
|
||||
/// Place an order for a pet
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
/// <param name="body">order placed for purchasing the pet</param>
|
||||
/// <returns>Task of Order</returns>
|
||||
System.Threading.Tasks.Task<Order> PlaceOrderAsync (Order body = null);
|
||||
|
||||
/// <summary>
|
||||
/// Place an order for a pet
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
/// <param name="body">order placed for purchasing the pet</param>
|
||||
/// <returns>Task of ApiResponse (Order)</returns>
|
||||
System.Threading.Tasks.Task<ApiResponse<Order>> PlaceOrderAsyncWithHttpInfo (Order body = null);
|
||||
|
||||
/// <summary>
|
||||
/// Find purchase order by ID
|
||||
@ -69,8 +108,28 @@ namespace IO.Swagger.Api
|
||||
/// For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
/// </remarks>
|
||||
/// <param name="orderId">ID of pet that needs to be fetched</param>
|
||||
/// <returns>Order</returns>
|
||||
/// <returns>ApiResponse of Order</returns>
|
||||
ApiResponse<Order> GetOrderByIdWithHttpInfo (string orderId);
|
||||
|
||||
/// <summary>
|
||||
/// Find purchase order by ID
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
/// </remarks>
|
||||
/// <param name="orderId">ID of pet that needs to be fetched</param>
|
||||
/// <returns>Task of Order</returns>
|
||||
System.Threading.Tasks.Task<Order> GetOrderByIdAsync (string orderId);
|
||||
|
||||
/// <summary>
|
||||
/// Find purchase order by ID
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
/// </remarks>
|
||||
/// <param name="orderId">ID of pet that needs to be fetched</param>
|
||||
/// <returns>Task of ApiResponse (Order)</returns>
|
||||
System.Threading.Tasks.Task<ApiResponse<Order>> GetOrderByIdAsyncWithHttpInfo (string orderId);
|
||||
|
||||
/// <summary>
|
||||
/// Delete purchase order by ID
|
||||
@ -89,8 +148,28 @@ namespace IO.Swagger.Api
|
||||
/// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
/// </remarks>
|
||||
/// <param name="orderId">ID of the order that needs to be deleted</param>
|
||||
/// <returns></returns>
|
||||
/// <returns>ApiResponse of Object(void)</returns>
|
||||
ApiResponse<Object> DeleteOrderWithHttpInfo (string orderId);
|
||||
|
||||
/// <summary>
|
||||
/// Delete purchase order by ID
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
/// </remarks>
|
||||
/// <param name="orderId">ID of the order that needs to be deleted</param>
|
||||
/// <returns>Task of void</returns>
|
||||
System.Threading.Tasks.Task DeleteOrderAsync (string orderId);
|
||||
|
||||
/// <summary>
|
||||
/// Delete purchase order by ID
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
/// </remarks>
|
||||
/// <param name="orderId">ID of the order that needs to be deleted</param>
|
||||
/// <returns>Task of ApiResponse</returns>
|
||||
System.Threading.Tasks.Task<ApiResponse<Object>> DeleteOrderAsyncWithHttpInfo (string orderId);
|
||||
|
||||
}
|
||||
|
||||
@ -99,59 +178,92 @@ namespace IO.Swagger.Api
|
||||
/// </summary>
|
||||
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
|
||||
this.ApiClient = Configuration.DefaultApiClient;
|
||||
else
|
||||
this.ApiClient = apiClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="StoreApi"/> class.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public StoreApi(String basePath)
|
||||
{
|
||||
this.ApiClient = new ApiClient(basePath);
|
||||
this.Configuration = new Configuration(new ApiClient(basePath));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the base path of the API client.
|
||||
/// Initializes a new instance of the <see cref="StoreApi"/> class
|
||||
/// using Configuration object
|
||||
/// </summary>
|
||||
/// <param name="basePath">The base path</param>
|
||||
/// <value>The base path</value>
|
||||
public void SetBasePath(String basePath)
|
||||
/// <param name="configuration">An instance of Configuration</param>
|
||||
/// <returns></returns>
|
||||
public StoreApi(Configuration configuration = null)
|
||||
{
|
||||
this.ApiClient.BasePath = basePath;
|
||||
if (configuration == null) // use the default one in Configuration
|
||||
this.Configuration = Configuration.Default;
|
||||
else
|
||||
this.Configuration = configuration;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the base path of the API client.
|
||||
/// </summary>
|
||||
/// <value>The base path</value>
|
||||
public String GetBasePath()
|
||||
{
|
||||
return this.ApiClient.BasePath;
|
||||
return this.Configuration.ApiClient.RestClient.BaseUrl.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the base path of the API client.
|
||||
/// </summary>
|
||||
/// <value>The base path</value>
|
||||
[Obsolete("SetBasePath is deprecated, please do 'Configuraiton.ApiClient = new ApiClient(\"http://new-path\")' instead.")]
|
||||
public void SetBasePath(String basePath)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the API client.
|
||||
/// Gets or sets the configuration object
|
||||
/// </summary>
|
||||
/// <value>An instance of the ApiClient</value>
|
||||
public ApiClient ApiClient {get; set;}
|
||||
|
||||
/// <value>An instance of the Configuration</value>
|
||||
public Configuration Configuration {get; set;}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default header.
|
||||
/// </summary>
|
||||
/// <returns>Dictionary of HTTP header</returns>
|
||||
[Obsolete("DefaultHeader is deprecated, please use Configuration.DefaultHeader instead.")]
|
||||
public Dictionary<String, String> DefaultHeader()
|
||||
{
|
||||
return this.Configuration.DefaultHeader;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add default header.
|
||||
/// </summary>
|
||||
/// <param name="key">Header field name.</param>
|
||||
/// <param name="value">Header field value.</param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("AddDefaultHeader is deprecated, please use Configuration.AddDefaultHeader instead.")]
|
||||
public void AddDefaultHeader(string key, string value)
|
||||
{
|
||||
this.Configuration.AddDefaultHeader(key, value);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns pet inventories by status Returns a map of status codes to quantities
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <returns>Dictionary<string, int?></returns>
|
||||
public Dictionary<string, int?> GetInventory ()
|
||||
{
|
||||
ApiResponse<Dictionary<string, int?>> response = GetInventoryWithHttpInfo();
|
||||
return response.Data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns pet inventories by status Returns a map of status codes to quantities
|
||||
/// </summary>
|
||||
/// <returns>ApiResponse of Dictionary<string, int?></returns>
|
||||
public ApiResponse< Dictionary<string, int?> > GetInventoryWithHttpInfo ()
|
||||
{
|
||||
|
||||
|
||||
@ -159,7 +271,7 @@ namespace IO.Swagger.Api
|
||||
|
||||
var pathParams = new Dictionary<String, String>();
|
||||
var queryParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>(Configuration.DefaultHeader);
|
||||
var formParams = new Dictionary<String, String>();
|
||||
var fileParams = new Dictionary<String, FileParameter>();
|
||||
String postBody = null;
|
||||
@ -168,9 +280,9 @@ namespace IO.Swagger.Api
|
||||
String[] http_header_accepts = new String[] {
|
||||
"application/json", "application/xml"
|
||||
};
|
||||
String http_header_accept = ApiClient.SelectHeaderAccept(http_header_accepts);
|
||||
String http_header_accept = Configuration.ApiClient.SelectHeaderAccept(http_header_accepts);
|
||||
if (http_header_accept != null)
|
||||
headerParams.Add("Accept", ApiClient.SelectHeaderAccept(http_header_accepts));
|
||||
headerParams.Add("Accept", Configuration.ApiClient.SelectHeaderAccept(http_header_accepts));
|
||||
|
||||
// set "format" to json by default
|
||||
// e.g. /pet/{petId}.{format} becomes /pet/{petId}.json
|
||||
@ -180,26 +292,49 @@ namespace IO.Swagger.Api
|
||||
|
||||
|
||||
|
||||
|
||||
// authentication setting, if any
|
||||
String[] authSettings = new String[] { "api_key" };
|
||||
|
||||
|
||||
// authentication (api_key) required
|
||||
|
||||
var apiKeyValue = Configuration.GetApiKeyWithPrefix("api_key");
|
||||
if (!String.IsNullOrEmpty(apiKeyValue))
|
||||
{
|
||||
headerParams["api_key"] = apiKeyValue;
|
||||
}
|
||||
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = (IRestResponse) ApiClient.CallApi(path_, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings);
|
||||
IRestResponse response = (IRestResponse) Configuration.ApiClient.CallApi(path_, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, pathParams);
|
||||
|
||||
int statusCode = (int) response.StatusCode;
|
||||
|
||||
if (((int)response.StatusCode) >= 400)
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling GetInventory: " + response.Content, response.Content);
|
||||
else if (((int)response.StatusCode) == 0)
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling GetInventory: " + response.ErrorMessage, response.ErrorMessage);
|
||||
if (statusCode >= 400)
|
||||
throw new ApiException (statusCode, "Error calling GetInventory: " + response.Content, response.Content);
|
||||
else if (statusCode == 0)
|
||||
throw new ApiException (statusCode, "Error calling GetInventory: " + response.ErrorMessage, response.ErrorMessage);
|
||||
|
||||
return (Dictionary<string, int?>) ApiClient.Deserialize(response, typeof(Dictionary<string, int?>));
|
||||
return new ApiResponse<Dictionary<string, int?>>(statusCode,
|
||||
response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
|
||||
(Dictionary<string, int?>) Configuration.ApiClient.Deserialize(response, typeof(Dictionary<string, int?>)));
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns pet inventories by status Returns a map of status codes to quantities
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <returns>Task of Dictionary<string, int?></returns>
|
||||
public async System.Threading.Tasks.Task<Dictionary<string, int?>> GetInventoryAsync ()
|
||||
{
|
||||
ApiResponse<Dictionary<string, int?>> response = await GetInventoryAsyncWithHttpInfo();
|
||||
return response.Data;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns pet inventories by status Returns a map of status codes to quantities
|
||||
/// </summary>
|
||||
/// <returns>Task of ApiResponse (Dictionary<string, int?>)</returns>
|
||||
public async System.Threading.Tasks.Task<ApiResponse<Dictionary<string, int?>>> GetInventoryAsyncWithHttpInfo ()
|
||||
{
|
||||
|
||||
|
||||
@ -216,9 +351,9 @@ namespace IO.Swagger.Api
|
||||
String[] http_header_accepts = new String[] {
|
||||
"application/json", "application/xml"
|
||||
};
|
||||
String http_header_accept = ApiClient.SelectHeaderAccept(http_header_accepts);
|
||||
String http_header_accept = Configuration.ApiClient.SelectHeaderAccept(http_header_accepts);
|
||||
if (http_header_accept != null)
|
||||
headerParams.Add("Accept", ApiClient.SelectHeaderAccept(http_header_accepts));
|
||||
headerParams.Add("Accept", Configuration.ApiClient.SelectHeaderAccept(http_header_accepts));
|
||||
|
||||
// set "format" to json by default
|
||||
// e.g. /pet/{petId}.{format} becomes /pet/{petId}.json
|
||||
@ -228,24 +363,50 @@ namespace IO.Swagger.Api
|
||||
|
||||
|
||||
|
||||
|
||||
// authentication setting, if any
|
||||
String[] authSettings = new String[] { "api_key" };
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path_, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings);
|
||||
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, typeof(Dictionary<string, int?>));
|
||||
|
||||
// authentication (api_key) required
|
||||
|
||||
var apiKeyValue = Configuration.GetApiKeyWithPrefix("api_key");
|
||||
if (!String.IsNullOrEmpty(apiKeyValue))
|
||||
{
|
||||
headerParams["api_key"] = apiKeyValue;
|
||||
}
|
||||
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, pathParams);
|
||||
|
||||
int statusCode = (int) response.StatusCode;
|
||||
|
||||
if (statusCode >= 400)
|
||||
throw new ApiException (statusCode, "Error calling GetInventory: " + response.Content, response.Content);
|
||||
else if (statusCode == 0)
|
||||
throw new ApiException (statusCode, "Error calling GetInventory: " + response.ErrorMessage, response.ErrorMessage);
|
||||
|
||||
return new ApiResponse<Dictionary<string, int?>>(statusCode,
|
||||
response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
|
||||
(Dictionary<string, int?>) Configuration.ApiClient.Deserialize(response, typeof(Dictionary<string, int?>)));
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Place an order for a pet
|
||||
/// </summary>
|
||||
/// <param name="body">order placed for purchasing the pet</param>
|
||||
/// <returns>Order</returns>
|
||||
/// <returns>Order</returns>
|
||||
public Order PlaceOrder (Order body = null)
|
||||
{
|
||||
ApiResponse<Order> response = PlaceOrderWithHttpInfo(body);
|
||||
return response.Data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Place an order for a pet
|
||||
/// </summary>
|
||||
/// <param name="body">order placed for purchasing the pet</param>
|
||||
/// <returns>ApiResponse of Order</returns>
|
||||
public ApiResponse< Order > PlaceOrderWithHttpInfo (Order body = null)
|
||||
{
|
||||
|
||||
|
||||
@ -253,7 +414,7 @@ namespace IO.Swagger.Api
|
||||
|
||||
var pathParams = new Dictionary<String, String>();
|
||||
var queryParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>(Configuration.DefaultHeader);
|
||||
var formParams = new Dictionary<String, String>();
|
||||
var fileParams = new Dictionary<String, FileParameter>();
|
||||
String postBody = null;
|
||||
@ -262,9 +423,9 @@ namespace IO.Swagger.Api
|
||||
String[] http_header_accepts = new String[] {
|
||||
"application/json", "application/xml"
|
||||
};
|
||||
String http_header_accept = ApiClient.SelectHeaderAccept(http_header_accepts);
|
||||
String http_header_accept = Configuration.ApiClient.SelectHeaderAccept(http_header_accepts);
|
||||
if (http_header_accept != null)
|
||||
headerParams.Add("Accept", ApiClient.SelectHeaderAccept(http_header_accepts));
|
||||
headerParams.Add("Accept", Configuration.ApiClient.SelectHeaderAccept(http_header_accepts));
|
||||
|
||||
// set "format" to json by default
|
||||
// e.g. /pet/{petId}.{format} becomes /pet/{petId}.json
|
||||
@ -273,29 +434,45 @@ namespace IO.Swagger.Api
|
||||
|
||||
|
||||
|
||||
postBody = ApiClient.Serialize(body); // http body (model) parameter
|
||||
postBody = Configuration.ApiClient.Serialize(body); // http body (model) parameter
|
||||
|
||||
|
||||
|
||||
|
||||
// authentication setting, if any
|
||||
String[] authSettings = new String[] { };
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = (IRestResponse) ApiClient.CallApi(path_, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings);
|
||||
IRestResponse response = (IRestResponse) Configuration.ApiClient.CallApi(path_, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, pathParams);
|
||||
|
||||
int statusCode = (int) response.StatusCode;
|
||||
|
||||
if (((int)response.StatusCode) >= 400)
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling PlaceOrder: " + response.Content, response.Content);
|
||||
else if (((int)response.StatusCode) == 0)
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling PlaceOrder: " + response.ErrorMessage, response.ErrorMessage);
|
||||
if (statusCode >= 400)
|
||||
throw new ApiException (statusCode, "Error calling PlaceOrder: " + response.Content, response.Content);
|
||||
else if (statusCode == 0)
|
||||
throw new ApiException (statusCode, "Error calling PlaceOrder: " + response.ErrorMessage, response.ErrorMessage);
|
||||
|
||||
return (Order) ApiClient.Deserialize(response, typeof(Order));
|
||||
return new ApiResponse<Order>(statusCode,
|
||||
response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
|
||||
(Order) Configuration.ApiClient.Deserialize(response, typeof(Order)));
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Place an order for a pet
|
||||
/// </summary>
|
||||
/// <param name="body">order placed for purchasing the pet</param>
|
||||
/// <returns>Order</returns>
|
||||
/// <returns>Task of Order</returns>
|
||||
public async System.Threading.Tasks.Task<Order> PlaceOrderAsync (Order body = null)
|
||||
{
|
||||
ApiResponse<Order> response = await PlaceOrderAsyncWithHttpInfo(body);
|
||||
return response.Data;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Place an order for a pet
|
||||
/// </summary>
|
||||
/// <param name="body">order placed for purchasing the pet</param>
|
||||
/// <returns>Task of ApiResponse (Order)</returns>
|
||||
public async System.Threading.Tasks.Task<ApiResponse<Order>> PlaceOrderAsyncWithHttpInfo (Order body = null)
|
||||
{
|
||||
|
||||
|
||||
@ -312,9 +489,9 @@ namespace IO.Swagger.Api
|
||||
String[] http_header_accepts = new String[] {
|
||||
"application/json", "application/xml"
|
||||
};
|
||||
String http_header_accept = ApiClient.SelectHeaderAccept(http_header_accepts);
|
||||
String http_header_accept = Configuration.ApiClient.SelectHeaderAccept(http_header_accepts);
|
||||
if (http_header_accept != null)
|
||||
headerParams.Add("Accept", ApiClient.SelectHeaderAccept(http_header_accepts));
|
||||
headerParams.Add("Accept", Configuration.ApiClient.SelectHeaderAccept(http_header_accepts));
|
||||
|
||||
// set "format" to json by default
|
||||
// e.g. /pet/{petId}.{format} becomes /pet/{petId}.json
|
||||
@ -323,26 +500,44 @@ namespace IO.Swagger.Api
|
||||
|
||||
|
||||
|
||||
postBody = ApiClient.Serialize(body); // http body (model) parameter
|
||||
postBody = Configuration.ApiClient.Serialize(body); // http body (model) parameter
|
||||
|
||||
|
||||
// authentication setting, if any
|
||||
String[] authSettings = new String[] { };
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path_, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings);
|
||||
if (((int)response.StatusCode) >= 400)
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling PlaceOrder: " + response.Content, response.Content);
|
||||
|
||||
return (Order) ApiClient.Deserialize(response, typeof(Order));
|
||||
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, pathParams);
|
||||
|
||||
int statusCode = (int) response.StatusCode;
|
||||
|
||||
if (statusCode >= 400)
|
||||
throw new ApiException (statusCode, "Error calling PlaceOrder: " + response.Content, response.Content);
|
||||
else if (statusCode == 0)
|
||||
throw new ApiException (statusCode, "Error calling PlaceOrder: " + response.ErrorMessage, response.ErrorMessage);
|
||||
|
||||
return new ApiResponse<Order>(statusCode,
|
||||
response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
|
||||
(Order) Configuration.ApiClient.Deserialize(response, typeof(Order)));
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find purchase order by ID For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
/// </summary>
|
||||
/// <param name="orderId">ID of pet that needs to be fetched</param>
|
||||
/// <returns>Order</returns>
|
||||
/// <returns>Order</returns>
|
||||
public Order GetOrderById (string orderId)
|
||||
{
|
||||
ApiResponse<Order> response = GetOrderByIdWithHttpInfo(orderId);
|
||||
return response.Data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find purchase order by ID For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
/// </summary>
|
||||
/// <param name="orderId">ID of pet that needs to be fetched</param>
|
||||
/// <returns>ApiResponse of Order</returns>
|
||||
public ApiResponse< Order > GetOrderByIdWithHttpInfo (string orderId)
|
||||
{
|
||||
|
||||
// verify the required parameter 'orderId' is set
|
||||
@ -353,7 +548,7 @@ namespace IO.Swagger.Api
|
||||
|
||||
var pathParams = new Dictionary<String, String>();
|
||||
var queryParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>(Configuration.DefaultHeader);
|
||||
var formParams = new Dictionary<String, String>();
|
||||
var fileParams = new Dictionary<String, FileParameter>();
|
||||
String postBody = null;
|
||||
@ -362,40 +557,56 @@ namespace IO.Swagger.Api
|
||||
String[] http_header_accepts = new String[] {
|
||||
"application/json", "application/xml"
|
||||
};
|
||||
String http_header_accept = ApiClient.SelectHeaderAccept(http_header_accepts);
|
||||
String http_header_accept = Configuration.ApiClient.SelectHeaderAccept(http_header_accepts);
|
||||
if (http_header_accept != null)
|
||||
headerParams.Add("Accept", ApiClient.SelectHeaderAccept(http_header_accepts));
|
||||
headerParams.Add("Accept", Configuration.ApiClient.SelectHeaderAccept(http_header_accepts));
|
||||
|
||||
// set "format" to json by default
|
||||
// e.g. /pet/{petId}.{format} becomes /pet/{petId}.json
|
||||
pathParams.Add("format", "json");
|
||||
if (orderId != null) pathParams.Add("orderId", ApiClient.ParameterToString(orderId)); // path parameter
|
||||
if (orderId != null) pathParams.Add("orderId", Configuration.ApiClient.ParameterToString(orderId)); // path parameter
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// authentication setting, if any
|
||||
String[] authSettings = new String[] { };
|
||||
|
||||
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = (IRestResponse) ApiClient.CallApi(path_, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings);
|
||||
IRestResponse response = (IRestResponse) Configuration.ApiClient.CallApi(path_, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, pathParams);
|
||||
|
||||
int statusCode = (int) response.StatusCode;
|
||||
|
||||
if (((int)response.StatusCode) >= 400)
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling GetOrderById: " + response.Content, response.Content);
|
||||
else if (((int)response.StatusCode) == 0)
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling GetOrderById: " + response.ErrorMessage, response.ErrorMessage);
|
||||
if (statusCode >= 400)
|
||||
throw new ApiException (statusCode, "Error calling GetOrderById: " + response.Content, response.Content);
|
||||
else if (statusCode == 0)
|
||||
throw new ApiException (statusCode, "Error calling GetOrderById: " + response.ErrorMessage, response.ErrorMessage);
|
||||
|
||||
return (Order) ApiClient.Deserialize(response, typeof(Order));
|
||||
return new ApiResponse<Order>(statusCode,
|
||||
response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
|
||||
(Order) Configuration.ApiClient.Deserialize(response, typeof(Order)));
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find purchase order by ID For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
/// </summary>
|
||||
/// <param name="orderId">ID of pet that needs to be fetched</param>
|
||||
/// <returns>Order</returns>
|
||||
/// <returns>Task of Order</returns>
|
||||
public async System.Threading.Tasks.Task<Order> GetOrderByIdAsync (string orderId)
|
||||
{
|
||||
ApiResponse<Order> response = await GetOrderByIdAsyncWithHttpInfo(orderId);
|
||||
return response.Data;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find purchase order by ID For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
/// </summary>
|
||||
/// <param name="orderId">ID of pet that needs to be fetched</param>
|
||||
/// <returns>Task of ApiResponse (Order)</returns>
|
||||
public async System.Threading.Tasks.Task<ApiResponse<Order>> GetOrderByIdAsyncWithHttpInfo (string orderId)
|
||||
{
|
||||
// verify the required parameter 'orderId' is set
|
||||
if (orderId == null) throw new ApiException(400, "Missing required parameter 'orderId' when calling GetOrderById");
|
||||
@ -414,37 +625,54 @@ namespace IO.Swagger.Api
|
||||
String[] http_header_accepts = new String[] {
|
||||
"application/json", "application/xml"
|
||||
};
|
||||
String http_header_accept = ApiClient.SelectHeaderAccept(http_header_accepts);
|
||||
String http_header_accept = Configuration.ApiClient.SelectHeaderAccept(http_header_accepts);
|
||||
if (http_header_accept != null)
|
||||
headerParams.Add("Accept", ApiClient.SelectHeaderAccept(http_header_accepts));
|
||||
headerParams.Add("Accept", Configuration.ApiClient.SelectHeaderAccept(http_header_accepts));
|
||||
|
||||
// set "format" to json by default
|
||||
// e.g. /pet/{petId}.{format} becomes /pet/{petId}.json
|
||||
pathParams.Add("format", "json");
|
||||
if (orderId != null) pathParams.Add("orderId", ApiClient.ParameterToString(orderId)); // path parameter
|
||||
if (orderId != null) pathParams.Add("orderId", Configuration.ApiClient.ParameterToString(orderId)); // path parameter
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// authentication setting, if any
|
||||
String[] authSettings = new String[] { };
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path_, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings);
|
||||
if (((int)response.StatusCode) >= 400)
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling GetOrderById: " + response.Content, response.Content);
|
||||
|
||||
return (Order) ApiClient.Deserialize(response, typeof(Order));
|
||||
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, pathParams);
|
||||
|
||||
int statusCode = (int) response.StatusCode;
|
||||
|
||||
if (statusCode >= 400)
|
||||
throw new ApiException (statusCode, "Error calling GetOrderById: " + response.Content, response.Content);
|
||||
else if (statusCode == 0)
|
||||
throw new ApiException (statusCode, "Error calling GetOrderById: " + response.ErrorMessage, response.ErrorMessage);
|
||||
|
||||
return new ApiResponse<Order>(statusCode,
|
||||
response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
|
||||
(Order) Configuration.ApiClient.Deserialize(response, typeof(Order)));
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete purchase order by ID For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
/// </summary>
|
||||
/// <param name="orderId">ID of the order that needs to be deleted</param>
|
||||
/// <returns></returns>
|
||||
/// <returns></returns>
|
||||
public void DeleteOrder (string orderId)
|
||||
{
|
||||
DeleteOrderWithHttpInfo(orderId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete purchase order by ID For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
/// </summary>
|
||||
/// <param name="orderId">ID of the order that needs to be deleted</param>
|
||||
/// <returns>ApiResponse of Object(void)</returns>
|
||||
public ApiResponse<Object> DeleteOrderWithHttpInfo (string orderId)
|
||||
{
|
||||
|
||||
// verify the required parameter 'orderId' is set
|
||||
@ -455,7 +683,7 @@ namespace IO.Swagger.Api
|
||||
|
||||
var pathParams = new Dictionary<String, String>();
|
||||
var queryParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>(Configuration.DefaultHeader);
|
||||
var formParams = new Dictionary<String, String>();
|
||||
var fileParams = new Dictionary<String, FileParameter>();
|
||||
String postBody = null;
|
||||
@ -464,40 +692,55 @@ namespace IO.Swagger.Api
|
||||
String[] http_header_accepts = new String[] {
|
||||
"application/json", "application/xml"
|
||||
};
|
||||
String http_header_accept = ApiClient.SelectHeaderAccept(http_header_accepts);
|
||||
String http_header_accept = Configuration.ApiClient.SelectHeaderAccept(http_header_accepts);
|
||||
if (http_header_accept != null)
|
||||
headerParams.Add("Accept", ApiClient.SelectHeaderAccept(http_header_accepts));
|
||||
headerParams.Add("Accept", Configuration.ApiClient.SelectHeaderAccept(http_header_accepts));
|
||||
|
||||
// set "format" to json by default
|
||||
// e.g. /pet/{petId}.{format} becomes /pet/{petId}.json
|
||||
pathParams.Add("format", "json");
|
||||
if (orderId != null) pathParams.Add("orderId", ApiClient.ParameterToString(orderId)); // path parameter
|
||||
if (orderId != null) pathParams.Add("orderId", Configuration.ApiClient.ParameterToString(orderId)); // path parameter
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// authentication setting, if any
|
||||
String[] authSettings = new String[] { };
|
||||
|
||||
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = (IRestResponse) ApiClient.CallApi(path_, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings);
|
||||
IRestResponse response = (IRestResponse) Configuration.ApiClient.CallApi(path_, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, pathParams);
|
||||
|
||||
int statusCode = (int) response.StatusCode;
|
||||
|
||||
if (((int)response.StatusCode) >= 400)
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling DeleteOrder: " + response.Content, response.Content);
|
||||
else if (((int)response.StatusCode) == 0)
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling DeleteOrder: " + response.ErrorMessage, response.ErrorMessage);
|
||||
if (statusCode >= 400)
|
||||
throw new ApiException (statusCode, "Error calling DeleteOrder: " + response.Content, response.Content);
|
||||
else if (statusCode == 0)
|
||||
throw new ApiException (statusCode, "Error calling DeleteOrder: " + response.ErrorMessage, response.ErrorMessage);
|
||||
|
||||
return;
|
||||
|
||||
return new ApiResponse<Object>(statusCode,
|
||||
response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
|
||||
null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete purchase order by ID For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
/// </summary>
|
||||
/// <param name="orderId">ID of the order that needs to be deleted</param>
|
||||
/// <returns></returns>
|
||||
/// <returns>Task of void</returns>
|
||||
public async System.Threading.Tasks.Task DeleteOrderAsync (string orderId)
|
||||
{
|
||||
await DeleteOrderAsyncWithHttpInfo(orderId);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete purchase order by ID For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
/// </summary>
|
||||
/// <param name="orderId">ID of the order that needs to be deleted</param>
|
||||
/// <returns>Task of ApiResponse</returns>
|
||||
public async System.Threading.Tasks.Task<ApiResponse<Object>> DeleteOrderAsyncWithHttpInfo (string orderId)
|
||||
{
|
||||
// verify the required parameter 'orderId' is set
|
||||
if (orderId == null) throw new ApiException(400, "Missing required parameter 'orderId' when calling DeleteOrder");
|
||||
@ -516,30 +759,36 @@ namespace IO.Swagger.Api
|
||||
String[] http_header_accepts = new String[] {
|
||||
"application/json", "application/xml"
|
||||
};
|
||||
String http_header_accept = ApiClient.SelectHeaderAccept(http_header_accepts);
|
||||
String http_header_accept = Configuration.ApiClient.SelectHeaderAccept(http_header_accepts);
|
||||
if (http_header_accept != null)
|
||||
headerParams.Add("Accept", ApiClient.SelectHeaderAccept(http_header_accepts));
|
||||
headerParams.Add("Accept", Configuration.ApiClient.SelectHeaderAccept(http_header_accepts));
|
||||
|
||||
// set "format" to json by default
|
||||
// e.g. /pet/{petId}.{format} becomes /pet/{petId}.json
|
||||
pathParams.Add("format", "json");
|
||||
if (orderId != null) pathParams.Add("orderId", ApiClient.ParameterToString(orderId)); // path parameter
|
||||
if (orderId != null) pathParams.Add("orderId", Configuration.ApiClient.ParameterToString(orderId)); // path parameter
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// authentication setting, if any
|
||||
String[] authSettings = new String[] { };
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path_, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings);
|
||||
if (((int)response.StatusCode) >= 400)
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling DeleteOrder: " + response.Content, response.Content);
|
||||
|
||||
|
||||
return;
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, pathParams);
|
||||
|
||||
int statusCode = (int) response.StatusCode;
|
||||
|
||||
if (statusCode >= 400)
|
||||
throw new ApiException (statusCode, "Error calling DeleteOrder: " + response.Content, response.Content);
|
||||
else if (statusCode == 0)
|
||||
throw new ApiException (statusCode, "Error calling DeleteOrder: " + response.ErrorMessage, response.ErrorMessage);
|
||||
|
||||
|
||||
return new ApiResponse<Object>(statusCode,
|
||||
response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
|
||||
null);
|
||||
}
|
||||
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -18,23 +18,23 @@ namespace IO.Swagger.Client
|
||||
/// </summary>
|
||||
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")
|
||||
{
|
||||
BasePath = basePath;
|
||||
RestClient = new RestClient(BasePath);
|
||||
if (String.IsNullOrEmpty(basePath))
|
||||
throw new ArgumentException("basePath cannot be empty");
|
||||
|
||||
RestClient = new RestClient(basePath);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the base path.
|
||||
/// Gets or sets the default API client for making HTTP calls.
|
||||
/// </summary>
|
||||
/// <value>The base path</value>
|
||||
public string BasePath { get; set; }
|
||||
/// <value>The default API client.</value>
|
||||
public static ApiClient Default = new ApiClient();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the RestClient.
|
||||
@ -42,38 +42,14 @@ namespace IO.Swagger.Client
|
||||
/// <value>An instance of the RestClient</value>
|
||||
public RestClient RestClient { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default header.
|
||||
/// </summary>
|
||||
public Dictionary<String, String> DefaultHeader
|
||||
{
|
||||
get { return _defaultHeaderMap; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the status code of the previous request
|
||||
/// </summary>
|
||||
public int StatusCode { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the response headers of the previous request
|
||||
/// </summary>
|
||||
public Dictionary<String, String> ResponseHeaders { get; private set; }
|
||||
|
||||
// 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)
|
||||
Dictionary<String, FileParameter> fileParams, Dictionary<String, String> pathParams)
|
||||
{
|
||||
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 path parameter, if any
|
||||
foreach(var param in pathParams)
|
||||
request.AddParameter(param.Key, param.Value, ParameterType.UrlSegment);
|
||||
@ -111,18 +87,15 @@ namespace IO.Swagger.Client
|
||||
/// <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)
|
||||
Dictionary<String, FileParameter> fileParams, Dictionary<String, String> pathParams)
|
||||
{
|
||||
var request = PrepareRequest(
|
||||
path, method, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings);
|
||||
path, method, queryParams, postBody, headerParams, formParams, fileParams, pathParams);
|
||||
var response = RestClient.Execute(request);
|
||||
StatusCode = (int) response.StatusCode;
|
||||
ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString());
|
||||
return (Object) response;
|
||||
}
|
||||
|
||||
@ -137,32 +110,18 @@ namespace IO.Swagger.Client
|
||||
/// <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)
|
||||
Dictionary<String, FileParameter> fileParams, Dictionary<String, String> pathParams)
|
||||
{
|
||||
var request = PrepareRequest(
|
||||
path, method, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings);
|
||||
path, method, queryParams, postBody, headerParams, formParams, fileParams, pathParams);
|
||||
var response = await RestClient.ExecuteTaskAsync(request);
|
||||
StatusCode = (int)response.StatusCode;
|
||||
ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString());
|
||||
return (Object)response;
|
||||
}
|
||||
|
||||
/// <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>
|
||||
@ -286,63 +245,6 @@ namespace IO.Swagger.Client
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the API key with prefix.
|
||||
/// </summary>
|
||||
/// <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))
|
||||
return apiKeyPrefix + " " + apiKeyValue;
|
||||
else
|
||||
return apiKeyValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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)
|
||||
{
|
||||
if (authSettings == null || authSettings.Length == 0)
|
||||
return;
|
||||
|
||||
foreach (string auth in authSettings)
|
||||
{
|
||||
// determine which one to use
|
||||
switch(auth)
|
||||
{
|
||||
|
||||
case "api_key":
|
||||
|
||||
var apiKeyValue = GetApiKeyWithPrefix("api_key");
|
||||
if (!String.IsNullOrEmpty(apiKeyValue))
|
||||
{
|
||||
headerParams["api_key"] = apiKeyValue;
|
||||
}
|
||||
break;
|
||||
|
||||
case "petstore_auth":
|
||||
|
||||
if (!String.IsNullOrEmpty(Configuration.AccessToken))
|
||||
{
|
||||
headerParams["Authorization"] = "Bearer " + Configuration.AccessToken;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
//show warning about security definition not found
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Select the Accept header's value from the given accepts array:
|
||||
/// if JSON exists in the given array, use it;
|
||||
|
@ -1,47 +1,50 @@
|
||||
using System;
|
||||
|
||||
namespace IO.Swagger.Client {
|
||||
/// <summary>
|
||||
/// API Exception
|
||||
/// </summary>
|
||||
public class ApiException : Exception {
|
||||
/// <summary>
|
||||
/// Gets or sets the error code (HTTP status code)
|
||||
/// </summary>
|
||||
/// <value>The error code (HTTP status code).</value>
|
||||
public int ErrorCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the error content (body json object)
|
||||
/// </summary>
|
||||
/// <value>The error content (Http response body).</value>
|
||||
public dynamic ErrorContent { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiException"/> class.
|
||||
/// </summary>
|
||||
public ApiException() {}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="errorCode">HTTP status code.</param>
|
||||
/// <param name="message">Error message.</param>
|
||||
public ApiException(int errorCode, string message) : base(message) {
|
||||
this.ErrorCode = errorCode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="errorCode">HTTP status code.</param>
|
||||
/// <param name="message">Error message.</param>
|
||||
/// <param name="errorContent">Error content.</param>
|
||||
public ApiException(int errorCode, string message, dynamic errorContent = null) : base(message) {
|
||||
this.ErrorCode = errorCode;
|
||||
this.ErrorContent = errorContent;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace IO.Swagger.Client
|
||||
{
|
||||
/// <summary>
|
||||
/// API Exception
|
||||
/// </summary>
|
||||
public class ApiException : Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the error code (HTTP status code)
|
||||
/// </summary>
|
||||
/// <value>The error code (HTTP status code).</value>
|
||||
public int ErrorCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the error content (body json object)
|
||||
/// </summary>
|
||||
/// <value>The error content (Http response body).</value>
|
||||
public dynamic ErrorContent { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiException"/> class.
|
||||
/// </summary>
|
||||
public ApiException() {}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="errorCode">HTTP status code.</param>
|
||||
/// <param name="message">Error message.</param>
|
||||
public ApiException(int errorCode, string message) : base(message)
|
||||
{
|
||||
this.ErrorCode = errorCode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="errorCode">HTTP status code.</param>
|
||||
/// <param name="message">Error message.</param>
|
||||
/// <param name="errorContent">Error content.</param>
|
||||
public ApiException(int errorCode, string message, dynamic errorContent = null) : base(message)
|
||||
{
|
||||
this.ErrorCode = errorCode;
|
||||
this.ErrorContent = errorContent;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace IO.Swagger.Client
|
||||
{
|
||||
/// <summary>
|
||||
/// API Response
|
||||
/// </summary>
|
||||
public class ApiResponse<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the status code (HTTP status code)
|
||||
/// </summary>
|
||||
/// <value>The status code.</value>
|
||||
public int StatusCode { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the HTTP headers
|
||||
/// </summary>
|
||||
/// <value>HTTP headers</value>
|
||||
public IDictionary<string, string> Headers { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the data (parsed HTTP body)
|
||||
/// </summary>
|
||||
/// <value>The data.</value>
|
||||
public T Data { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiResponse"/> class.
|
||||
/// </summary>
|
||||
/// <param name="statusCode">HTTP status code.</param>
|
||||
/// <param name="message">Error message.</param>
|
||||
/// <param name="data">Data (parsed HTTP body)</param>
|
||||
public ApiResponse(int statusCode, IDictionary<string, string> headers, T data)
|
||||
{
|
||||
this.StatusCode= statusCode;
|
||||
this.Headers = headers;
|
||||
this.Data = data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -12,6 +12,17 @@ namespace IO.Swagger.Client
|
||||
/// </summary>
|
||||
public class Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the Configuration class.
|
||||
/// </summary>
|
||||
/// <param name="apiClient">Api client.</param>
|
||||
public Configuration(ApiClient apiClient=null)
|
||||
{
|
||||
if (apiClient == null)
|
||||
ApiClient = ApiClient.Default;
|
||||
else
|
||||
ApiClient = apiClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Version of the package.
|
||||
@ -19,41 +30,84 @@ namespace IO.Swagger.Client
|
||||
/// <value>Version of the package.</value>
|
||||
public const string Version = "1.0.0";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default Configuration.
|
||||
/// </summary>
|
||||
/// <value>Configuration.</value>
|
||||
public static Configuration Default = new Configuration();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default API client for making HTTP calls.
|
||||
/// </summary>
|
||||
/// <value>The API client.</value>
|
||||
public static ApiClient DefaultApiClient = new ApiClient();
|
||||
|
||||
public ApiClient ApiClient;
|
||||
|
||||
private readonly Dictionary<String, String> _defaultHeaderMap = new Dictionary<String, String>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default header.
|
||||
/// </summary>
|
||||
public Dictionary<String, String> DefaultHeader
|
||||
{
|
||||
get { return _defaultHeaderMap; }
|
||||
}
|
||||
|
||||
/// <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>
|
||||
/// Gets or sets the username (HTTP basic authentication).
|
||||
/// </summary>
|
||||
/// <value>The username.</value>
|
||||
public static String Username { get; set; }
|
||||
public String Username { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the password (HTTP basic authentication).
|
||||
/// </summary>
|
||||
/// <value>The password.</value>
|
||||
public static String Password { get; set; }
|
||||
public String Password { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the access token for OAuth2 authentication.
|
||||
/// </summary>
|
||||
/// <value>The access token.</value>
|
||||
public static String AccessToken { get; set; }
|
||||
public String AccessToken { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 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>();
|
||||
public 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.
|
||||
/// </summary>
|
||||
/// <value>The prefix of the API key.</value>
|
||||
public static Dictionary<String, String> ApiKeyPrefix = new Dictionary<String, String>();
|
||||
public Dictionary<String, String> ApiKeyPrefix = new Dictionary<String, String>();
|
||||
|
||||
/// <summary>
|
||||
/// Get the API key with prefix.
|
||||
/// </summary>
|
||||
/// <param name="apiKeyIdentifier">API key identifier (authentication scheme).</param>
|
||||
/// <returns>API key with prefix.</returns>
|
||||
public string GetApiKeyWithPrefix (string apiKeyIdentifier)
|
||||
{
|
||||
var apiKeyValue = "";
|
||||
ApiKey.TryGetValue (apiKeyIdentifier, out apiKeyValue);
|
||||
var apiKeyPrefix = "";
|
||||
if (ApiKeyPrefix.TryGetValue (apiKeyIdentifier, out apiKeyPrefix))
|
||||
return apiKeyPrefix + " " + apiKeyValue;
|
||||
else
|
||||
return apiKeyValue;
|
||||
}
|
||||
|
||||
private static string _tempFolderPath = Path.GetTempPath();
|
||||
|
||||
|
@ -56,6 +56,8 @@
|
||||
<Compile Include="Lib\SwaggerClient\src\main\csharp\IO\Swagger\Model\User.cs" />
|
||||
<Compile Include="TestPet.cs" />
|
||||
<Compile Include="TestApiClient.cs" />
|
||||
<Compile Include="TestConfiguration.cs" />
|
||||
<Compile Include="Lib\SwaggerClient\src\main\csharp\IO\Swagger\Client\ApiResponse.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
|
@ -2,8 +2,29 @@
|
||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="TestPet.cs">
|
||||
<Files>
|
||||
<File FileName="TestPet.cs" Line="15" Column="3" />
|
||||
<File FileName="TestConfiguration.cs" Line="17" Column="33" />
|
||||
<File FileName="Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/PetApi.cs" Line="523" Column="49" />
|
||||
<File FileName="TestPet.cs" Line="87" Column="4" />
|
||||
<File FileName="Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/Configuration.cs" Line="1" Column="1" />
|
||||
<File FileName="TestApiClient.cs" Line="22" Column="4" />
|
||||
</Files>
|
||||
<Pads>
|
||||
<Pad Id="MonoDevelop.NUnit.TestPad">
|
||||
<State name="__root__">
|
||||
<Node name="SwaggerClientTest" expanded="True">
|
||||
<Node name="SwaggerClientTest" expanded="True">
|
||||
<Node name="SwaggerClient" expanded="True">
|
||||
<Node name="TestPet" expanded="True">
|
||||
<Node name="TestPet" expanded="True">
|
||||
<Node name="TestGetPetByIdAsyncWithHttpInfo" selected="True" />
|
||||
</Node>
|
||||
</Node>
|
||||
</Node>
|
||||
</Node>
|
||||
</Node>
|
||||
</State>
|
||||
</Pad>
|
||||
</Pads>
|
||||
</MonoDevelop.Ide.Workbench>
|
||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||
<BreakpointStore />
|
||||
|
@ -20,7 +20,6 @@ namespace SwaggerClient.TestApiClient
|
||||
List<int> numList = new List<int>(new int[] {1, 37});
|
||||
Assert.AreEqual("1,37", api.ParameterToString (numList));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,79 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using IO.Swagger.Client;
|
||||
using IO.Swagger.Api;
|
||||
using IO.Swagger.Model;
|
||||
|
||||
namespace SwaggerClient.TestConfiguration
|
||||
{
|
||||
public class TestConfiguration
|
||||
{
|
||||
[Test ()]
|
||||
public void TestAuthentication ()
|
||||
{
|
||||
Configuration c = new Configuration ();
|
||||
c.Username = "test_username";
|
||||
c.Password = "test_password";
|
||||
|
||||
c.ApiKey ["api_key_identifier"] = "1233456778889900";
|
||||
c.ApiKeyPrefix ["api_key_identifier"] = "PREFIX";
|
||||
Assert.AreEqual (c.GetApiKeyWithPrefix("api_key_identifier"), "PREFIX 1233456778889900");
|
||||
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void TestBasePath ()
|
||||
{
|
||||
PetApi p = new PetApi ("http://new-basepath.com");
|
||||
Assert.AreEqual (p.Configuration.ApiClient.RestClient.BaseUrl, "http://new-basepath.com");
|
||||
// Given that PetApi is initailized with a base path, a new configuration (with a new ApiClient)
|
||||
// is created by default
|
||||
Assert.AreNotSame (p.Configuration, Configuration.Default);
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void TestDefautlConfiguration ()
|
||||
{
|
||||
PetApi p1 = new PetApi ();
|
||||
PetApi p2 = new PetApi ();
|
||||
Assert.AreSame (p1.Configuration, p2.Configuration);
|
||||
// same as the default
|
||||
Assert.AreSame (p1.Configuration, Configuration.Default);
|
||||
|
||||
Configuration c = new Configuration ();
|
||||
Assert.AreNotSame (c, p1.Configuration);
|
||||
|
||||
PetApi p3 = new PetApi (c);
|
||||
// same as c
|
||||
Assert.AreSame (p3.Configuration, c);
|
||||
// not same as default
|
||||
Assert.AreNotSame (p3.Configuration, p1.Configuration);
|
||||
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void TestUsage ()
|
||||
{
|
||||
// basic use case using default base URL
|
||||
PetApi p1 = new PetApi ();
|
||||
Assert.AreSame (p1.Configuration, Configuration.Default, "PetApi should use default configuration");
|
||||
|
||||
// using a different base URL
|
||||
PetApi p2 = new PetApi ("http://new-base-url.com/");
|
||||
Assert.AreEqual (p2.Configuration.ApiClient.RestClient.BaseUrl.ToString(), "http://new-base-url.com/");
|
||||
|
||||
// using a different configuration
|
||||
Configuration c1 = new Configuration ();
|
||||
PetApi p3 = new PetApi (c1);
|
||||
Assert.AreSame (p3.Configuration, c1);
|
||||
|
||||
// using a different base URL via a new ApiClient
|
||||
ApiClient a1 = new ApiClient ("http://new-api-client.com");
|
||||
Configuration c2 = new Configuration (a1);
|
||||
PetApi p4 = new PetApi (c2);
|
||||
Assert.AreSame (p4.Configuration.ApiClient, a1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -76,6 +76,38 @@ namespace SwaggerClient.TestPet
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test GetPetByIdAsyncWithHttpInfo
|
||||
/// </summary>
|
||||
[Test ()]
|
||||
public void TestGetPetByIdAsyncWithHttpInfo ()
|
||||
{
|
||||
PetApi petApi = new PetApi ();
|
||||
var task = petApi.GetPetByIdAsyncWithHttpInfo (petId);
|
||||
|
||||
Assert.AreEqual (200, task.Result.StatusCode);
|
||||
Assert.IsTrue (task.Result.Headers.ContainsKey("Content-Type"));
|
||||
Assert.AreEqual (task.Result.Headers["Content-Type"], "application/json");
|
||||
|
||||
Pet response = task.Result.Data;
|
||||
Assert.IsInstanceOf<Pet> (response, "Response is a Pet");
|
||||
|
||||
Assert.AreEqual ("Csharp test", response.Name);
|
||||
Assert.AreEqual ("available", response.Status);
|
||||
|
||||
Assert.IsInstanceOf<List<Tag>> (response.Tags, "Response.Tags is a Array");
|
||||
Assert.AreEqual (petId, response.Tags [0].Id);
|
||||
Assert.AreEqual ("sample tag name1", response.Tags [0].Name);
|
||||
|
||||
Assert.IsInstanceOf<List<String>> (response.PhotoUrls, "Response.PhotoUrls is a Array");
|
||||
Assert.AreEqual ("sample photoUrls", response.PhotoUrls [0]);
|
||||
|
||||
Assert.IsInstanceOf<Category> (response.Category, "Response.Category is a Category");
|
||||
Assert.AreEqual (56, response.Category.Id);
|
||||
Assert.AreEqual ("sample category name2", response.Category.Name);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test GetPetById
|
||||
/// </summary>
|
||||
@ -229,6 +261,32 @@ namespace SwaggerClient.TestPet
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test status code
|
||||
/// </summary>
|
||||
[Test ()]
|
||||
public void TestStatusCodeAndHeader ()
|
||||
{
|
||||
PetApi petApi = new PetApi ();
|
||||
var response = petApi.GetPetByIdWithHttpInfo (petId);
|
||||
Assert.AreEqual (response.StatusCode, 200);
|
||||
Assert.IsTrue (response.Headers.ContainsKey("Content-Type"));
|
||||
Assert.AreEqual (response.Headers["Content-Type"], "application/json");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test default header (should be deprecated
|
||||
/// </summary>
|
||||
[Test ()]
|
||||
public void TestDefaultHeader ()
|
||||
{
|
||||
PetApi petApi = new PetApi ();
|
||||
// there should be a warning for using AddDefaultHeader (deprecated) below
|
||||
petApi.AddDefaultHeader ("header_key", "header_value");
|
||||
// the following should be used instead as suggested in the doc
|
||||
petApi.Configuration.AddDefaultHeader ("header_key2", "header_value2");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
@ -1,16 +1,8 @@
|
||||
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs
|
||||
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb
|
||||
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll
|
||||
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll
|
||||
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb
|
||||
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Newtonsoft.Json.dll
|
||||
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll
|
||||
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/RestSharp.dll
|
||||
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs
|
||||
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll
|
||||
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb
|
||||
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Newtonsoft.Json.dll
|
||||
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll
|
||||
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/RestSharp.dll
|
||||
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb
|
||||
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll
|
||||
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll
|
||||
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb
|
||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user