forked from loafle/openapi-generator-original
add authentication support
This commit is contained in:
parent
165efdbdbb
commit
5f36ad3b75
@ -8,26 +8,41 @@ using Newtonsoft.Json;
|
|||||||
using RestSharp;
|
using RestSharp;
|
||||||
|
|
||||||
namespace {{invokerPackage}} {
|
namespace {{invokerPackage}} {
|
||||||
|
/// <summary>
|
||||||
|
/// API client is mainly responible for making the HTTP call to the API backend
|
||||||
|
/// </summary>
|
||||||
public class ApiClient {
|
public class ApiClient {
|
||||||
public ApiClient() {
|
|
||||||
this.basePath = "{{basePath}}";
|
|
||||||
this.restClient = new RestClient(this.basePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ApiClient(String basePath) {
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="ApiClient"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="basePath">The base path.</param>
|
||||||
|
public ApiClient(String basePath="{{basePath}}") {
|
||||||
this.basePath = basePath;
|
this.basePath = basePath;
|
||||||
this.restClient = new RestClient(this.basePath);
|
this.restClient = new RestClient(this.basePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the base path.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The base path.</value>
|
||||||
public string basePath { get; set; }
|
public string basePath { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the RestClient
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The RestClient.</value>
|
||||||
public RestClient restClient { get; set; }
|
public RestClient restClient { get; set; }
|
||||||
|
|
||||||
private Dictionary<String, String> defaultHeaderMap = new Dictionary<String, String>();
|
private Dictionary<String, String> defaultHeaderMap = new Dictionary<String, String>();
|
||||||
|
|
||||||
public Object CallApi(String Path, RestSharp.Method Method, Dictionary<String, String> QueryParams, String PostBody,
|
public Object CallApi(String Path, RestSharp.Method Method, Dictionary<String, String> QueryParams, String PostBody,
|
||||||
Dictionary<String, String> HeaderParams, Dictionary<String, String> FormParams, Dictionary<String, String> FileParams) {
|
Dictionary<String, String> HeaderParams, Dictionary<String, String> FormParams, Dictionary<String, String> FileParams, String[] AuthSettings) {
|
||||||
|
|
||||||
var request = new RestRequest(Path, Method);
|
var request = new RestRequest(Path, Method);
|
||||||
|
|
||||||
|
UpdateParamsForAuth(QueryParams, HeaderParams, AuthSettings);
|
||||||
|
|
||||||
// add default header, if any
|
// add default header, if any
|
||||||
foreach(KeyValuePair<string, string> defaultHeader in this.defaultHeaderMap)
|
foreach(KeyValuePair<string, string> defaultHeader in this.defaultHeaderMap)
|
||||||
request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
||||||
@ -126,5 +141,59 @@ namespace {{invokerPackage}} {
|
|||||||
throw new ApiException(500, e.Message);
|
throw new ApiException(500, e.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the API key with prefix
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj"> Object
|
||||||
|
/// <returns>API key with prefix</returns>
|
||||||
|
public string GetApiKeyWithPrefix (string apiKey)
|
||||||
|
{
|
||||||
|
var apiKeyValue = "";
|
||||||
|
Configuration.apiKey.TryGetValue (apiKey, out apiKeyValue);
|
||||||
|
var apiKeyPrefix = "";
|
||||||
|
if (Configuration.apiKeyPrefix.TryGetValue (apiKey, 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}}HeaderParams["{{keyParamName}}"] = GetApiKeyWithPrefix("{{keyParamName}}");{{/isKeyInHeader}}{{#isKeyInQuery}}QueryParams["{{keyParamName}}"] = GetApiKeyWithPrefix("{{keyParamName}}");{{/isKeyInQuery}}{{/isApiKey}}{{#isBasic}}HeaderParams["Authorization"] = "Basic " + Base64Encode(Configuration.username + ":" + Configuration.password);{{/isBasic}}
|
||||||
|
{{#isOAuth}}//TODO support oauth{{/isOAuth}}
|
||||||
|
break;
|
||||||
|
{{/authMethods}}
|
||||||
|
default:
|
||||||
|
//TODO show warning about security definition not found
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Encode string in base64 format
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text">String to be encoded</param>
|
||||||
|
public static string Base64Encode(string text) {
|
||||||
|
var textByte = System.Text.Encoding.UTF8.GetBytes(text);
|
||||||
|
return System.Convert.ToBase64String(textByte);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,41 @@ using System.Text;
|
|||||||
using {{invokerPackage}};
|
using {{invokerPackage}};
|
||||||
|
|
||||||
namespace {{invokerPackage}} {
|
namespace {{invokerPackage}} {
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a set of configuration settings
|
||||||
|
/// </summary>
|
||||||
public class Configuration{
|
public class Configuration{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the API client. This is the default API client for making HTTP calls.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The API client.</value>
|
||||||
public static ApiClient apiClient = new ApiClient();
|
public static ApiClient apiClient = new ApiClient();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the username (HTTP basic authentication)
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The username.</value>
|
||||||
|
public static String username { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the password (HTTP basic authentication)
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The password.</value>
|
||||||
|
public static String password { 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>();
|
||||||
|
|
||||||
|
/// <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>();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,20 +8,14 @@ using {{modelPackage}};
|
|||||||
|
|
||||||
namespace {{package}} {
|
namespace {{package}} {
|
||||||
{{#operations}}
|
{{#operations}}
|
||||||
public class {{classname}} {
|
|
||||||
string basePath;
|
|
||||||
public ApiClient apiClient {get; set;}
|
|
||||||
|
|
||||||
public {{classname}}(String basePath = "{{basePath}}")
|
|
||||||
{
|
|
||||||
this.basePath = basePath;
|
|
||||||
this.apiClient = new ApiClient(basePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new object
|
/// Represents a collection of functions to interact with the API endpoints
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="apiClient"> an instance of ApiClient
|
public class {{classname}} {
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="{{classname}}"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="apiClient"> an instance of ApiClient (optional)
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public {{classname}}(ApiClient apiClient = null) {
|
public {{classname}}(ApiClient apiClient = null) {
|
||||||
if (apiClient == null) { // use the default one in Configuration
|
if (apiClient == null) { // use the default one in Configuration
|
||||||
@ -32,22 +26,37 @@ namespace {{package}} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the endpoint base url for the services being accessed
|
/// Initializes a new instance of the <see cref="{{classname}}"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="basePath"> Base URL
|
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public void SetBasePath(string basePath) {
|
public {{classname}}(String basePath)
|
||||||
this.basePath = basePath;
|
{
|
||||||
|
this.apiClient = new ApiClient(basePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the endpoint base url for the services being accessed
|
/// Sets the base path of the API client.
|
||||||
/// <returns>Base URL</returns>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public String GetBasePath() {
|
/// <value>The base path</value>
|
||||||
return this.basePath;
|
public void SetBasePath(String basePath) {
|
||||||
|
this.apiClient.basePath = basePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the base path of the API client.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The base path</value>
|
||||||
|
public String GetBasePath(String basePath) {
|
||||||
|
return this.apiClient.basePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the API client.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The API client</value>
|
||||||
|
public ApiClient apiClient {get; set;}
|
||||||
|
|
||||||
|
|
||||||
{{#operation}}
|
{{#operation}}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// {{summary}} {{notes}}
|
/// {{summary}} {{notes}}
|
||||||
@ -82,8 +91,11 @@ namespace {{package}} {
|
|||||||
{{#bodyParam}}postBody = apiClient.Serialize({{paramName}}); // http body (model) parameter
|
{{#bodyParam}}postBody = apiClient.Serialize({{paramName}}); // http body (model) parameter
|
||||||
{{/bodyParam}}
|
{{/bodyParam}}
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
String[] authSettings = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} };
|
||||||
|
|
||||||
// make the HTTP request
|
// make the HTTP request
|
||||||
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.{{httpMethod}}, queryParams, postBody, headerParams, formParams, fileParams);
|
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.{{httpMethod}}, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
|
||||||
|
|
||||||
if (((int)response.StatusCode) >= 400) {
|
if (((int)response.StatusCode) >= 400) {
|
||||||
throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.Content);
|
throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.Content);
|
||||||
|
@ -1,13 +1,27 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace {{invokerPackage}} {
|
namespace {{invokerPackage}} {
|
||||||
|
/// <summary>
|
||||||
|
/// API Exception
|
||||||
|
/// </summary>
|
||||||
public class ApiException : Exception {
|
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; }
|
public int ErrorCode { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="ApiException"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="basePath">The base path.</param>
|
||||||
public ApiException() {}
|
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) {
|
public ApiException(int errorCode, string message) : base(message) {
|
||||||
this.ErrorCode = errorCode;
|
this.ErrorCode = errorCode;
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,15 @@ using System.Text;
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
{{#models}}
|
{{#models}}
|
||||||
{{#model}}
|
{{#model}}
|
||||||
namespace {{package}} {
|
namespace {{package}} {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// {{description}}
|
||||||
|
/// </summary>
|
||||||
[DataContract]
|
[DataContract]
|
||||||
public class {{classname}} {
|
public class {{classname}} {
|
||||||
{{#vars}}
|
{{#vars}}
|
||||||
@ -15,6 +20,11 @@ namespace {{package}} {
|
|||||||
public {{{datatype}}} {{name}} { get; set; }
|
public {{{datatype}}} {{name}} { get; set; }
|
||||||
|
|
||||||
{{/vars}}
|
{{/vars}}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the string presentation of the object
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>String presentation of the object</returns>
|
||||||
public override string ToString() {
|
public override string ToString() {
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.Append("class {{classname}} {\n");
|
sb.Append("class {{classname}} {\n");
|
||||||
@ -24,7 +34,16 @@ namespace {{package}} {
|
|||||||
sb.Append("}\n");
|
sb.Append("}\n");
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the JSON string presentation of the object
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>JSON string presentation of the object</returns>
|
||||||
|
public string ToJson() {
|
||||||
|
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
{{/model}}
|
{{/model}}
|
||||||
{{/models}}
|
{{/models}}
|
||||||
}
|
}
|
||||||
|
@ -6,20 +6,14 @@ using IO.Swagger.Model;
|
|||||||
|
|
||||||
namespace IO.Swagger.Api {
|
namespace IO.Swagger.Api {
|
||||||
|
|
||||||
public class PetApi {
|
|
||||||
string basePath;
|
|
||||||
public ApiClient apiClient {get; set;}
|
|
||||||
|
|
||||||
public PetApi(String basePath = "http://petstore.swagger.io/v2")
|
|
||||||
{
|
|
||||||
this.basePath = basePath;
|
|
||||||
this.apiClient = new ApiClient(basePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new object
|
/// Represents a collection of functions to interact with the API endpoints
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="apiClient"> an instance of ApiClient
|
public class PetApi {
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="PetApi"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="apiClient"> an instance of ApiClient (optional)
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public PetApi(ApiClient apiClient = null) {
|
public PetApi(ApiClient apiClient = null) {
|
||||||
if (apiClient == null) { // use the default one in Configuration
|
if (apiClient == null) { // use the default one in Configuration
|
||||||
@ -30,22 +24,37 @@ namespace IO.Swagger.Api {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the endpoint base url for the services being accessed
|
/// Initializes a new instance of the <see cref="PetApi"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="basePath"> Base URL
|
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public void SetBasePath(string basePath) {
|
public PetApi(String basePath)
|
||||||
this.basePath = basePath;
|
{
|
||||||
|
this.apiClient = new ApiClient(basePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the endpoint base url for the services being accessed
|
/// Sets the base path of the API client.
|
||||||
/// <returns>Base URL</returns>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public String GetBasePath() {
|
/// <value>The base path</value>
|
||||||
return this.basePath;
|
public void SetBasePath(String basePath) {
|
||||||
|
this.apiClient.basePath = basePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the base path of the API client.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The base path</value>
|
||||||
|
public String GetBasePath(String basePath) {
|
||||||
|
return this.apiClient.basePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the API client.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The API client</value>
|
||||||
|
public ApiClient apiClient {get; set;}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Update an existing pet
|
/// Update an existing pet
|
||||||
@ -72,8 +81,11 @@ namespace IO.Swagger.Api {
|
|||||||
postBody = apiClient.Serialize(Body); // http body (model) parameter
|
postBody = apiClient.Serialize(Body); // http body (model) parameter
|
||||||
|
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
String[] authSettings = new String[] { "petstore_auth" };
|
||||||
|
|
||||||
// make the HTTP request
|
// make the HTTP request
|
||||||
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams);
|
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
|
||||||
|
|
||||||
if (((int)response.StatusCode) >= 400) {
|
if (((int)response.StatusCode) >= 400) {
|
||||||
throw new ApiException ((int)response.StatusCode, "Error calling UpdatePet: " + response.Content);
|
throw new ApiException ((int)response.StatusCode, "Error calling UpdatePet: " + response.Content);
|
||||||
@ -107,8 +119,11 @@ namespace IO.Swagger.Api {
|
|||||||
postBody = apiClient.Serialize(Body); // http body (model) parameter
|
postBody = apiClient.Serialize(Body); // http body (model) parameter
|
||||||
|
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
String[] authSettings = new String[] { "petstore_auth" };
|
||||||
|
|
||||||
// make the HTTP request
|
// make the HTTP request
|
||||||
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams);
|
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
|
||||||
|
|
||||||
if (((int)response.StatusCode) >= 400) {
|
if (((int)response.StatusCode) >= 400) {
|
||||||
throw new ApiException ((int)response.StatusCode, "Error calling AddPet: " + response.Content);
|
throw new ApiException ((int)response.StatusCode, "Error calling AddPet: " + response.Content);
|
||||||
@ -142,8 +157,11 @@ namespace IO.Swagger.Api {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
String[] authSettings = new String[] { "petstore_auth" };
|
||||||
|
|
||||||
// make the HTTP request
|
// make the HTTP request
|
||||||
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams);
|
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
|
||||||
|
|
||||||
if (((int)response.StatusCode) >= 400) {
|
if (((int)response.StatusCode) >= 400) {
|
||||||
throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByStatus: " + response.Content);
|
throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByStatus: " + response.Content);
|
||||||
@ -176,8 +194,11 @@ namespace IO.Swagger.Api {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
String[] authSettings = new String[] { "petstore_auth" };
|
||||||
|
|
||||||
// make the HTTP request
|
// make the HTTP request
|
||||||
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams);
|
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
|
||||||
|
|
||||||
if (((int)response.StatusCode) >= 400) {
|
if (((int)response.StatusCode) >= 400) {
|
||||||
throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByTags: " + response.Content);
|
throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByTags: " + response.Content);
|
||||||
@ -213,8 +234,11 @@ namespace IO.Swagger.Api {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
String[] authSettings = new String[] { "api_key", "petstore_auth" };
|
||||||
|
|
||||||
// make the HTTP request
|
// make the HTTP request
|
||||||
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams);
|
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
|
||||||
|
|
||||||
if (((int)response.StatusCode) >= 400) {
|
if (((int)response.StatusCode) >= 400) {
|
||||||
throw new ApiException ((int)response.StatusCode, "Error calling GetPetById: " + response.Content);
|
throw new ApiException ((int)response.StatusCode, "Error calling GetPetById: " + response.Content);
|
||||||
@ -254,8 +278,11 @@ namespace IO.Swagger.Api {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
String[] authSettings = new String[] { "petstore_auth" };
|
||||||
|
|
||||||
// make the HTTP request
|
// make the HTTP request
|
||||||
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams);
|
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
|
||||||
|
|
||||||
if (((int)response.StatusCode) >= 400) {
|
if (((int)response.StatusCode) >= 400) {
|
||||||
throw new ApiException ((int)response.StatusCode, "Error calling UpdatePetWithForm: " + response.Content);
|
throw new ApiException ((int)response.StatusCode, "Error calling UpdatePetWithForm: " + response.Content);
|
||||||
@ -294,8 +321,11 @@ namespace IO.Swagger.Api {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
String[] authSettings = new String[] { "petstore_auth" };
|
||||||
|
|
||||||
// make the HTTP request
|
// make the HTTP request
|
||||||
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams);
|
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
|
||||||
|
|
||||||
if (((int)response.StatusCode) >= 400) {
|
if (((int)response.StatusCode) >= 400) {
|
||||||
throw new ApiException ((int)response.StatusCode, "Error calling DeletePet: " + response.Content);
|
throw new ApiException ((int)response.StatusCode, "Error calling DeletePet: " + response.Content);
|
||||||
@ -336,8 +366,11 @@ namespace IO.Swagger.Api {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
String[] authSettings = new String[] { "petstore_auth" };
|
||||||
|
|
||||||
// make the HTTP request
|
// make the HTTP request
|
||||||
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams);
|
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
|
||||||
|
|
||||||
if (((int)response.StatusCode) >= 400) {
|
if (((int)response.StatusCode) >= 400) {
|
||||||
throw new ApiException ((int)response.StatusCode, "Error calling UploadFile: " + response.Content);
|
throw new ApiException ((int)response.StatusCode, "Error calling UploadFile: " + response.Content);
|
||||||
|
@ -6,20 +6,14 @@ using IO.Swagger.Model;
|
|||||||
|
|
||||||
namespace IO.Swagger.Api {
|
namespace IO.Swagger.Api {
|
||||||
|
|
||||||
public class StoreApi {
|
|
||||||
string basePath;
|
|
||||||
public ApiClient apiClient {get; set;}
|
|
||||||
|
|
||||||
public StoreApi(String basePath = "http://petstore.swagger.io/v2")
|
|
||||||
{
|
|
||||||
this.basePath = basePath;
|
|
||||||
this.apiClient = new ApiClient(basePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new object
|
/// Represents a collection of functions to interact with the API endpoints
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="apiClient"> an instance of ApiClient
|
public class StoreApi {
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="StoreApi"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="apiClient"> an instance of ApiClient (optional)
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public StoreApi(ApiClient apiClient = null) {
|
public StoreApi(ApiClient apiClient = null) {
|
||||||
if (apiClient == null) { // use the default one in Configuration
|
if (apiClient == null) { // use the default one in Configuration
|
||||||
@ -30,22 +24,37 @@ namespace IO.Swagger.Api {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the endpoint base url for the services being accessed
|
/// Initializes a new instance of the <see cref="StoreApi"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="basePath"> Base URL
|
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public void SetBasePath(string basePath) {
|
public StoreApi(String basePath)
|
||||||
this.basePath = basePath;
|
{
|
||||||
|
this.apiClient = new ApiClient(basePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the endpoint base url for the services being accessed
|
/// Sets the base path of the API client.
|
||||||
/// <returns>Base URL</returns>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public String GetBasePath() {
|
/// <value>The base path</value>
|
||||||
return this.basePath;
|
public void SetBasePath(String basePath) {
|
||||||
|
this.apiClient.basePath = basePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the base path of the API client.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The base path</value>
|
||||||
|
public String GetBasePath(String basePath) {
|
||||||
|
return this.apiClient.basePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the API client.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The API client</value>
|
||||||
|
public ApiClient apiClient {get; set;}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns pet inventories by status Returns a map of status codes to quantities
|
/// Returns pet inventories by status Returns a map of status codes to quantities
|
||||||
@ -70,8 +79,11 @@ namespace IO.Swagger.Api {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
String[] authSettings = new String[] { "api_key" };
|
||||||
|
|
||||||
// make the HTTP request
|
// make the HTTP request
|
||||||
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams);
|
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
|
||||||
|
|
||||||
if (((int)response.StatusCode) >= 400) {
|
if (((int)response.StatusCode) >= 400) {
|
||||||
throw new ApiException ((int)response.StatusCode, "Error calling GetInventory: " + response.Content);
|
throw new ApiException ((int)response.StatusCode, "Error calling GetInventory: " + response.Content);
|
||||||
@ -104,8 +116,11 @@ namespace IO.Swagger.Api {
|
|||||||
postBody = apiClient.Serialize(Body); // http body (model) parameter
|
postBody = apiClient.Serialize(Body); // http body (model) parameter
|
||||||
|
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
String[] authSettings = new String[] { };
|
||||||
|
|
||||||
// make the HTTP request
|
// make the HTTP request
|
||||||
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams);
|
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
|
||||||
|
|
||||||
if (((int)response.StatusCode) >= 400) {
|
if (((int)response.StatusCode) >= 400) {
|
||||||
throw new ApiException ((int)response.StatusCode, "Error calling PlaceOrder: " + response.Content);
|
throw new ApiException ((int)response.StatusCode, "Error calling PlaceOrder: " + response.Content);
|
||||||
@ -141,8 +156,11 @@ namespace IO.Swagger.Api {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
String[] authSettings = new String[] { };
|
||||||
|
|
||||||
// make the HTTP request
|
// make the HTTP request
|
||||||
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams);
|
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
|
||||||
|
|
||||||
if (((int)response.StatusCode) >= 400) {
|
if (((int)response.StatusCode) >= 400) {
|
||||||
throw new ApiException ((int)response.StatusCode, "Error calling GetOrderById: " + response.Content);
|
throw new ApiException ((int)response.StatusCode, "Error calling GetOrderById: " + response.Content);
|
||||||
@ -178,8 +196,11 @@ namespace IO.Swagger.Api {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
String[] authSettings = new String[] { };
|
||||||
|
|
||||||
// make the HTTP request
|
// make the HTTP request
|
||||||
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams);
|
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
|
||||||
|
|
||||||
if (((int)response.StatusCode) >= 400) {
|
if (((int)response.StatusCode) >= 400) {
|
||||||
throw new ApiException ((int)response.StatusCode, "Error calling DeleteOrder: " + response.Content);
|
throw new ApiException ((int)response.StatusCode, "Error calling DeleteOrder: " + response.Content);
|
||||||
|
@ -6,20 +6,14 @@ using IO.Swagger.Model;
|
|||||||
|
|
||||||
namespace IO.Swagger.Api {
|
namespace IO.Swagger.Api {
|
||||||
|
|
||||||
public class UserApi {
|
|
||||||
string basePath;
|
|
||||||
public ApiClient apiClient {get; set;}
|
|
||||||
|
|
||||||
public UserApi(String basePath = "http://petstore.swagger.io/v2")
|
|
||||||
{
|
|
||||||
this.basePath = basePath;
|
|
||||||
this.apiClient = new ApiClient(basePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new object
|
/// Represents a collection of functions to interact with the API endpoints
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="apiClient"> an instance of ApiClient
|
public class UserApi {
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="UserApi"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="apiClient"> an instance of ApiClient (optional)
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public UserApi(ApiClient apiClient = null) {
|
public UserApi(ApiClient apiClient = null) {
|
||||||
if (apiClient == null) { // use the default one in Configuration
|
if (apiClient == null) { // use the default one in Configuration
|
||||||
@ -30,22 +24,37 @@ namespace IO.Swagger.Api {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the endpoint base url for the services being accessed
|
/// Initializes a new instance of the <see cref="UserApi"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="basePath"> Base URL
|
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public void SetBasePath(string basePath) {
|
public UserApi(String basePath)
|
||||||
this.basePath = basePath;
|
{
|
||||||
|
this.apiClient = new ApiClient(basePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the endpoint base url for the services being accessed
|
/// Sets the base path of the API client.
|
||||||
/// <returns>Base URL</returns>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public String GetBasePath() {
|
/// <value>The base path</value>
|
||||||
return this.basePath;
|
public void SetBasePath(String basePath) {
|
||||||
|
this.apiClient.basePath = basePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the base path of the API client.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The base path</value>
|
||||||
|
public String GetBasePath(String basePath) {
|
||||||
|
return this.apiClient.basePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the API client.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The API client</value>
|
||||||
|
public ApiClient apiClient {get; set;}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create user This can only be done by the logged in user.
|
/// Create user This can only be done by the logged in user.
|
||||||
@ -72,8 +81,11 @@ namespace IO.Swagger.Api {
|
|||||||
postBody = apiClient.Serialize(Body); // http body (model) parameter
|
postBody = apiClient.Serialize(Body); // http body (model) parameter
|
||||||
|
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
String[] authSettings = new String[] { };
|
||||||
|
|
||||||
// make the HTTP request
|
// make the HTTP request
|
||||||
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams);
|
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
|
||||||
|
|
||||||
if (((int)response.StatusCode) >= 400) {
|
if (((int)response.StatusCode) >= 400) {
|
||||||
throw new ApiException ((int)response.StatusCode, "Error calling CreateUser: " + response.Content);
|
throw new ApiException ((int)response.StatusCode, "Error calling CreateUser: " + response.Content);
|
||||||
@ -107,8 +119,11 @@ namespace IO.Swagger.Api {
|
|||||||
postBody = apiClient.Serialize(Body); // http body (model) parameter
|
postBody = apiClient.Serialize(Body); // http body (model) parameter
|
||||||
|
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
String[] authSettings = new String[] { };
|
||||||
|
|
||||||
// make the HTTP request
|
// make the HTTP request
|
||||||
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams);
|
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
|
||||||
|
|
||||||
if (((int)response.StatusCode) >= 400) {
|
if (((int)response.StatusCode) >= 400) {
|
||||||
throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithArrayInput: " + response.Content);
|
throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithArrayInput: " + response.Content);
|
||||||
@ -142,8 +157,11 @@ namespace IO.Swagger.Api {
|
|||||||
postBody = apiClient.Serialize(Body); // http body (model) parameter
|
postBody = apiClient.Serialize(Body); // http body (model) parameter
|
||||||
|
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
String[] authSettings = new String[] { };
|
||||||
|
|
||||||
// make the HTTP request
|
// make the HTTP request
|
||||||
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams);
|
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
|
||||||
|
|
||||||
if (((int)response.StatusCode) >= 400) {
|
if (((int)response.StatusCode) >= 400) {
|
||||||
throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithListInput: " + response.Content);
|
throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithListInput: " + response.Content);
|
||||||
@ -179,8 +197,11 @@ namespace IO.Swagger.Api {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
String[] authSettings = new String[] { };
|
||||||
|
|
||||||
// make the HTTP request
|
// make the HTTP request
|
||||||
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams);
|
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
|
||||||
|
|
||||||
if (((int)response.StatusCode) >= 400) {
|
if (((int)response.StatusCode) >= 400) {
|
||||||
throw new ApiException ((int)response.StatusCode, "Error calling LoginUser: " + response.Content);
|
throw new ApiException ((int)response.StatusCode, "Error calling LoginUser: " + response.Content);
|
||||||
@ -211,8 +232,11 @@ namespace IO.Swagger.Api {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
String[] authSettings = new String[] { };
|
||||||
|
|
||||||
// make the HTTP request
|
// make the HTTP request
|
||||||
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams);
|
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
|
||||||
|
|
||||||
if (((int)response.StatusCode) >= 400) {
|
if (((int)response.StatusCode) >= 400) {
|
||||||
throw new ApiException ((int)response.StatusCode, "Error calling LogoutUser: " + response.Content);
|
throw new ApiException ((int)response.StatusCode, "Error calling LogoutUser: " + response.Content);
|
||||||
@ -249,8 +273,11 @@ namespace IO.Swagger.Api {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
String[] authSettings = new String[] { };
|
||||||
|
|
||||||
// make the HTTP request
|
// make the HTTP request
|
||||||
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams);
|
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
|
||||||
|
|
||||||
if (((int)response.StatusCode) >= 400) {
|
if (((int)response.StatusCode) >= 400) {
|
||||||
throw new ApiException ((int)response.StatusCode, "Error calling GetUserByName: " + response.Content);
|
throw new ApiException ((int)response.StatusCode, "Error calling GetUserByName: " + response.Content);
|
||||||
@ -288,8 +315,11 @@ namespace IO.Swagger.Api {
|
|||||||
postBody = apiClient.Serialize(Body); // http body (model) parameter
|
postBody = apiClient.Serialize(Body); // http body (model) parameter
|
||||||
|
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
String[] authSettings = new String[] { };
|
||||||
|
|
||||||
// make the HTTP request
|
// make the HTTP request
|
||||||
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams);
|
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
|
||||||
|
|
||||||
if (((int)response.StatusCode) >= 400) {
|
if (((int)response.StatusCode) >= 400) {
|
||||||
throw new ApiException ((int)response.StatusCode, "Error calling UpdateUser: " + response.Content);
|
throw new ApiException ((int)response.StatusCode, "Error calling UpdateUser: " + response.Content);
|
||||||
@ -326,8 +356,11 @@ namespace IO.Swagger.Api {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
String[] authSettings = new String[] { };
|
||||||
|
|
||||||
// make the HTTP request
|
// make the HTTP request
|
||||||
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams);
|
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
|
||||||
|
|
||||||
if (((int)response.StatusCode) >= 400) {
|
if (((int)response.StatusCode) >= 400) {
|
||||||
throw new ApiException ((int)response.StatusCode, "Error calling DeleteUser: " + response.Content);
|
throw new ApiException ((int)response.StatusCode, "Error calling DeleteUser: " + response.Content);
|
||||||
|
@ -3,8 +3,13 @@ using System.Text;
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace IO.Swagger.Model {
|
namespace IO.Swagger.Model {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
[DataContract]
|
[DataContract]
|
||||||
public class Category {
|
public class Category {
|
||||||
|
|
||||||
@ -18,6 +23,11 @@ namespace IO.Swagger.Model {
|
|||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the string presentation of the object
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>String presentation of the object</returns>
|
||||||
public override string ToString() {
|
public override string ToString() {
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.Append("class Category {\n");
|
sb.Append("class Category {\n");
|
||||||
@ -29,7 +39,16 @@ namespace IO.Swagger.Model {
|
|||||||
sb.Append("}\n");
|
sb.Append("}\n");
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the JSON string presentation of the object
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>JSON string presentation of the object</returns>
|
||||||
|
public string ToJson() {
|
||||||
|
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,13 @@ using System.Text;
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace IO.Swagger.Model {
|
namespace IO.Swagger.Model {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
[DataContract]
|
[DataContract]
|
||||||
public class Order {
|
public class Order {
|
||||||
|
|
||||||
@ -38,6 +43,11 @@ namespace IO.Swagger.Model {
|
|||||||
public bool? Complete { get; set; }
|
public bool? Complete { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the string presentation of the object
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>String presentation of the object</returns>
|
||||||
public override string ToString() {
|
public override string ToString() {
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.Append("class Order {\n");
|
sb.Append("class Order {\n");
|
||||||
@ -57,7 +67,16 @@ namespace IO.Swagger.Model {
|
|||||||
sb.Append("}\n");
|
sb.Append("}\n");
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the JSON string presentation of the object
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>JSON string presentation of the object</returns>
|
||||||
|
public string ToJson() {
|
||||||
|
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,13 @@ using System.Text;
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace IO.Swagger.Model {
|
namespace IO.Swagger.Model {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
[DataContract]
|
[DataContract]
|
||||||
public class Pet {
|
public class Pet {
|
||||||
|
|
||||||
@ -38,6 +43,11 @@ namespace IO.Swagger.Model {
|
|||||||
public string Status { get; set; }
|
public string Status { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the string presentation of the object
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>String presentation of the object</returns>
|
||||||
public override string ToString() {
|
public override string ToString() {
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.Append("class Pet {\n");
|
sb.Append("class Pet {\n");
|
||||||
@ -57,7 +67,16 @@ namespace IO.Swagger.Model {
|
|||||||
sb.Append("}\n");
|
sb.Append("}\n");
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the JSON string presentation of the object
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>JSON string presentation of the object</returns>
|
||||||
|
public string ToJson() {
|
||||||
|
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,13 @@ using System.Text;
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace IO.Swagger.Model {
|
namespace IO.Swagger.Model {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
[DataContract]
|
[DataContract]
|
||||||
public class Tag {
|
public class Tag {
|
||||||
|
|
||||||
@ -18,6 +23,11 @@ namespace IO.Swagger.Model {
|
|||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the string presentation of the object
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>String presentation of the object</returns>
|
||||||
public override string ToString() {
|
public override string ToString() {
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.Append("class Tag {\n");
|
sb.Append("class Tag {\n");
|
||||||
@ -29,7 +39,16 @@ namespace IO.Swagger.Model {
|
|||||||
sb.Append("}\n");
|
sb.Append("}\n");
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the JSON string presentation of the object
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>JSON string presentation of the object</returns>
|
||||||
|
public string ToJson() {
|
||||||
|
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,13 @@ using System.Text;
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace IO.Swagger.Model {
|
namespace IO.Swagger.Model {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
[DataContract]
|
[DataContract]
|
||||||
public class User {
|
public class User {
|
||||||
|
|
||||||
@ -48,6 +53,11 @@ namespace IO.Swagger.Model {
|
|||||||
public int? UserStatus { get; set; }
|
public int? UserStatus { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the string presentation of the object
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>String presentation of the object</returns>
|
||||||
public override string ToString() {
|
public override string ToString() {
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.Append("class User {\n");
|
sb.Append("class User {\n");
|
||||||
@ -71,7 +81,16 @@ namespace IO.Swagger.Model {
|
|||||||
sb.Append("}\n");
|
sb.Append("}\n");
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the JSON string presentation of the object
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>JSON string presentation of the object</returns>
|
||||||
|
public string ToJson() {
|
||||||
|
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,26 +8,41 @@ using Newtonsoft.Json;
|
|||||||
using RestSharp;
|
using RestSharp;
|
||||||
|
|
||||||
namespace IO.Swagger.Client {
|
namespace IO.Swagger.Client {
|
||||||
|
/// <summary>
|
||||||
|
/// API client is mainly responible for making the HTTP call to the API backend
|
||||||
|
/// </summary>
|
||||||
public class ApiClient {
|
public class ApiClient {
|
||||||
public ApiClient() {
|
|
||||||
this.basePath = "http://petstore.swagger.io/v2";
|
|
||||||
this.restClient = new RestClient(this.basePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ApiClient(String basePath) {
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="ApiClient"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="basePath">The base path.</param>
|
||||||
|
public ApiClient(String basePath="http://petstore.swagger.io/v2") {
|
||||||
this.basePath = basePath;
|
this.basePath = basePath;
|
||||||
this.restClient = new RestClient(this.basePath);
|
this.restClient = new RestClient(this.basePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the base path.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The base path.</value>
|
||||||
public string basePath { get; set; }
|
public string basePath { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the RestClient
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The RestClient.</value>
|
||||||
public RestClient restClient { get; set; }
|
public RestClient restClient { get; set; }
|
||||||
|
|
||||||
private Dictionary<String, String> defaultHeaderMap = new Dictionary<String, String>();
|
private Dictionary<String, String> defaultHeaderMap = new Dictionary<String, String>();
|
||||||
|
|
||||||
public Object CallApi(String Path, RestSharp.Method Method, Dictionary<String, String> QueryParams, String PostBody,
|
public Object CallApi(String Path, RestSharp.Method Method, Dictionary<String, String> QueryParams, String PostBody,
|
||||||
Dictionary<String, String> HeaderParams, Dictionary<String, String> FormParams, Dictionary<String, String> FileParams) {
|
Dictionary<String, String> HeaderParams, Dictionary<String, String> FormParams, Dictionary<String, String> FileParams, String[] AuthSettings) {
|
||||||
|
|
||||||
var request = new RestRequest(Path, Method);
|
var request = new RestRequest(Path, Method);
|
||||||
|
|
||||||
|
UpdateParamsForAuth(QueryParams, HeaderParams, AuthSettings);
|
||||||
|
|
||||||
// add default header, if any
|
// add default header, if any
|
||||||
foreach(KeyValuePair<string, string> defaultHeader in this.defaultHeaderMap)
|
foreach(KeyValuePair<string, string> defaultHeader in this.defaultHeaderMap)
|
||||||
request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
||||||
@ -126,5 +141,64 @@ namespace IO.Swagger.Client {
|
|||||||
throw new ApiException(500, e.Message);
|
throw new ApiException(500, e.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the API key with prefix
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj"> Object
|
||||||
|
/// <returns>API key with prefix</returns>
|
||||||
|
public string GetApiKeyWithPrefix (string apiKey)
|
||||||
|
{
|
||||||
|
var apiKeyValue = "";
|
||||||
|
Configuration.apiKey.TryGetValue (apiKey, out apiKeyValue);
|
||||||
|
var apiKeyPrefix = "";
|
||||||
|
if (Configuration.apiKeyPrefix.TryGetValue (apiKey, 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":
|
||||||
|
HeaderParams["api_key"] = GetApiKeyWithPrefix("api_key");
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "petstore_auth":
|
||||||
|
|
||||||
|
//TODO support oauth
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
//TODO show warning about security definition not found
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Encode string in base64 format
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text">String to be encoded</param>
|
||||||
|
public static string Base64Encode(string text) {
|
||||||
|
var textByte = System.Text.Encoding.UTF8.GetBytes(text);
|
||||||
|
return System.Convert.ToBase64String(textByte);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,27 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace IO.Swagger.Client {
|
namespace IO.Swagger.Client {
|
||||||
|
/// <summary>
|
||||||
|
/// API Exception
|
||||||
|
/// </summary>
|
||||||
public class ApiException : Exception {
|
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; }
|
public int ErrorCode { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="ApiException"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="basePath">The base path.</param>
|
||||||
public ApiException() {}
|
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) {
|
public ApiException(int errorCode, string message) : base(message) {
|
||||||
this.ErrorCode = errorCode;
|
this.ErrorCode = errorCode;
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,41 @@ using System.Text;
|
|||||||
using IO.Swagger.Client;
|
using IO.Swagger.Client;
|
||||||
|
|
||||||
namespace IO.Swagger.Client {
|
namespace IO.Swagger.Client {
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a set of configuration settings
|
||||||
|
/// </summary>
|
||||||
public class Configuration{
|
public class Configuration{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the API client. This is the default API client for making HTTP calls.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The API client.</value>
|
||||||
public static ApiClient apiClient = new ApiClient();
|
public static ApiClient apiClient = new ApiClient();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the username (HTTP basic authentication)
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The username.</value>
|
||||||
|
public static String username { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the password (HTTP basic authentication)
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The password.</value>
|
||||||
|
public static String password { 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>();
|
||||||
|
|
||||||
|
/// <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>();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user