forked from loafle/openapi-generator-original
refactor csharp (no compile error)
This commit is contained in:
@@ -10,12 +10,12 @@ namespace {{package}} {
|
||||
{{#operations}}
|
||||
public class {{classname}} {
|
||||
string basePath;
|
||||
protected RestClient restClient;
|
||||
public ApiInvoker apiClient {get; set;}
|
||||
|
||||
public {{classname}}(String basePath = "{{basePath}}")
|
||||
{
|
||||
this.basePath = basePath;
|
||||
this.restClient = new RestClient(basePath);
|
||||
this.apiClient = new ApiInvoker(basePath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -45,37 +45,38 @@ namespace {{package}} {
|
||||
/// <returns>{{#returnType}}{{{returnType}}}{{/returnType}}</returns>
|
||||
public {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {
|
||||
|
||||
var _request = new RestRequest("{{path}}", Method.{{httpMethod}});
|
||||
|
||||
{{#allParams}}{{#required}}
|
||||
// verify the required parameter '{{paramName}}' is set
|
||||
if ({{paramName}} == null) throw new ApiException(400, "Missing required parameter '{{paramName}}' when calling {{nickname}}");
|
||||
{{/required}}{{/allParams}}
|
||||
|
||||
// add default header, if any
|
||||
foreach(KeyValuePair<string, string> defaultHeader in ApiInvoker.GetDefaultHeader())
|
||||
{
|
||||
_request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
||||
}
|
||||
|
||||
_request.AddUrlSegment("format", "json"); // set format to json by default
|
||||
{{#pathParams}}_request.AddUrlSegment("{{baseName}}", ApiInvoker.ParameterToString({{{paramName}}})); // path (url segment) parameter
|
||||
var path = "{{path}}";
|
||||
path = path.Replace("{format}", "json");
|
||||
{{#pathParams}}path = path.Replace("{" + "{{baseName}}" + "}", apiClient.ParameterToString({{{paramName}}}));
|
||||
{{/pathParams}}
|
||||
{{#queryParams}} if ({{paramName}} != null) _request.AddParameter("{{baseName}}", ApiInvoker.ParameterToString({{paramName}})); // query parameter
|
||||
|
||||
var queryParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>();
|
||||
var formParams = new Dictionary<String, String>();
|
||||
var fileParams = new Dictionary<String, String>();
|
||||
String postBody = null;
|
||||
|
||||
{{#queryParams}} if ({{paramName}} != null) queryParams.Add("{{baseName}}", apiClient.ParameterToString({{paramName}})); // query parameter
|
||||
{{/queryParams}}
|
||||
{{#headerParams}} if ({{paramName}} != null) _request.AddHeader("{{baseName}}", ApiInvoker.ParameterToString({{paramName}})); // header parameter
|
||||
{{#headerParams}} if ({{paramName}} != null) headerParams.Add("{{baseName}}", apiClient.ParameterToString({{paramName}})); // header parameter
|
||||
{{/headerParams}}
|
||||
{{#formParams}}if ({{paramName}} != null) {{#isFile}}_request.AddFile("{{baseName}}", {{paramName}});{{/isFile}}{{^isFile}}_request.AddParameter("{{baseName}}", ApiInvoker.ParameterToString({{paramName}})); // form parameter{{/isFile}}
|
||||
{{#formParams}}if ({{paramName}} != null) {{#isFile}}fileParams.Add("{{baseName}}", {{paramName}});{{/isFile}}{{^isFile}}formParams.Add("{{baseName}}", apiClient.ParameterToString({{paramName}})); // form parameter{{/isFile}}
|
||||
{{/formParams}}
|
||||
{{#bodyParam}}_request.AddParameter("application/json", ApiInvoker.Serialize({{paramName}}), ParameterType.RequestBody); // http body (model) parameter
|
||||
{{#bodyParam}}postBody = apiClient.Serialize({{paramName}}); // http body (model) parameter
|
||||
{{/bodyParam}}
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = restClient.Execute(_request);
|
||||
IRestResponse response = (IRestResponse) apiClient.CallApi("{{path}}", Method.{{httpMethod}}, queryParams, postBody, headerParams, formParams, fileParams);
|
||||
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.Content);
|
||||
}
|
||||
{{#returnType}}return ({{{returnType}}}) ApiInvoker.Deserialize(response.Content, typeof({{{returnType}}}));{{/returnType}}{{^returnType}}
|
||||
{{#returnType}}return ({{{returnType}}}) apiClient.Deserialize(response.Content, typeof({{{returnType}}}));{{/returnType}}{{^returnType}}
|
||||
return;{{/returnType}}
|
||||
}
|
||||
{{/operation}}
|
||||
|
||||
@@ -5,10 +5,54 @@ using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using RestSharp;
|
||||
|
||||
namespace {{invokerPackage}} {
|
||||
public class ApiInvoker {
|
||||
private static Dictionary<String, String> defaultHeaderMap = new Dictionary<String, String>();
|
||||
public ApiInvoker() {
|
||||
this.basePath = "{{basePath}}";
|
||||
}
|
||||
|
||||
public ApiInvoker(String basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
|
||||
public string basePath { get; set; }
|
||||
public RestClient restClient { get; set; }
|
||||
private Dictionary<String, String> defaultHeaderMap = new Dictionary<String, String>();
|
||||
|
||||
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) {
|
||||
|
||||
var request = new RestRequest(Path, Method);
|
||||
|
||||
// add default header, if any
|
||||
foreach(KeyValuePair<string, string> defaultHeader in this.defaultHeaderMap)
|
||||
request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
||||
|
||||
// add header parameter, if any
|
||||
foreach(KeyValuePair<string, string> param in HeaderParams)
|
||||
request.AddHeader(param.Key, param.Value);
|
||||
|
||||
// add query parameter, if any
|
||||
foreach(KeyValuePair<string, string> param in QueryParams)
|
||||
request.AddUrlSegment(param.Key, param.Value);
|
||||
|
||||
// add form parameter, if any
|
||||
foreach(KeyValuePair<string, string> param in FormParams)
|
||||
request.AddParameter(param.Key, param.Value);
|
||||
|
||||
// add file parameter, if any
|
||||
foreach(KeyValuePair<string, string> param in FormParams)
|
||||
request.AddFile(param.Key, param.Value);
|
||||
|
||||
if (PostBody == null) {
|
||||
request.AddParameter("application/json", PostBody, ParameterType.RequestBody); // http body (model) parameter
|
||||
}
|
||||
|
||||
return (Object)restClient.Execute(request);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add default header
|
||||
@@ -16,7 +60,7 @@ namespace {{invokerPackage}} {
|
||||
/// <param name="key"> Header field name
|
||||
/// <param name="value"> Header field value
|
||||
/// <returns></returns>
|
||||
public static void AddDefaultHeader(string key, string value) {
|
||||
public void AddDefaultHeader(string key, string value) {
|
||||
defaultHeaderMap.Add(key, value);
|
||||
}
|
||||
|
||||
@@ -24,7 +68,7 @@ namespace {{invokerPackage}} {
|
||||
/// Get default header
|
||||
/// </summary>
|
||||
/// <returns>Dictionary of default header</returns>
|
||||
public static Dictionary<String, String> GetDefaultHeader() {
|
||||
public Dictionary<String, String> GetDefaultHeader() {
|
||||
return defaultHeaderMap;
|
||||
}
|
||||
|
||||
@@ -33,7 +77,7 @@ namespace {{invokerPackage}} {
|
||||
/// </summary>
|
||||
/// <param name="str"> String to be escaped
|
||||
/// <returns>Escaped string</returns>
|
||||
public static string EscapeString(string str) {
|
||||
public string EscapeString(string str) {
|
||||
return str;
|
||||
}
|
||||
|
||||
@@ -42,7 +86,7 @@ namespace {{invokerPackage}} {
|
||||
/// </summary>
|
||||
/// <param name="obj"> The parameter (header, path, query, form)
|
||||
/// <returns>Formatted string</returns>
|
||||
public static string ParameterToString(object obj)
|
||||
public string ParameterToString(object obj)
|
||||
{
|
||||
return (obj is DateTime) ? ((DateTime)obj).ToString ("u") : Convert.ToString (obj);
|
||||
}
|
||||
@@ -53,7 +97,7 @@ namespace {{invokerPackage}} {
|
||||
/// <param name="json"> JSON string
|
||||
/// <param name="type"> Object type
|
||||
/// <returns>Object representation of the JSON string</returns>
|
||||
public static object Deserialize(string content, Type type) {
|
||||
public object Deserialize(string content, Type type) {
|
||||
if (type.GetType() == typeof(Object))
|
||||
return (Object)content;
|
||||
|
||||
@@ -71,7 +115,7 @@ namespace {{invokerPackage}} {
|
||||
/// </summary>
|
||||
/// <param name="obj"> Object
|
||||
/// <returns>JSON string</returns>
|
||||
public static string Serialize(object obj) {
|
||||
public string Serialize(object obj) {
|
||||
try
|
||||
{
|
||||
return obj != null ? JsonConvert.SerializeObject(obj) : null;
|
||||
|
||||
@@ -8,12 +8,12 @@ namespace IO.Swagger.Api {
|
||||
|
||||
public class PetApi {
|
||||
string basePath;
|
||||
protected RestClient restClient;
|
||||
public ApiInvoker apiClient {get; set;}
|
||||
|
||||
public PetApi(String basePath = "http://petstore.swagger.io/v2")
|
||||
{
|
||||
this.basePath = basePath;
|
||||
this.restClient = new RestClient(basePath);
|
||||
this.apiClient = new ApiInvoker(basePath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -42,26 +42,27 @@ namespace IO.Swagger.Api {
|
||||
/// <returns></returns>
|
||||
public void UpdatePet (Pet Body) {
|
||||
|
||||
var _request = new RestRequest("/pet", Method.PUT);
|
||||
|
||||
|
||||
|
||||
// add default header, if any
|
||||
foreach(KeyValuePair<string, string> defaultHeader in ApiInvoker.GetDefaultHeader())
|
||||
{
|
||||
_request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
||||
}
|
||||
var path = "/pet";
|
||||
path = path.Replace("{format}", "json");
|
||||
|
||||
|
||||
var queryParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>();
|
||||
var formParams = new Dictionary<String, String>();
|
||||
var fileParams = new Dictionary<String, String>();
|
||||
String postBody = null;
|
||||
|
||||
_request.AddUrlSegment("format", "json"); // set format to json by default
|
||||
|
||||
|
||||
|
||||
|
||||
_request.AddParameter("application/json", ApiInvoker.Serialize(Body), ParameterType.RequestBody); // http body (model) parameter
|
||||
postBody = apiClient.Serialize(Body); // http body (model) parameter
|
||||
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = restClient.Execute(_request);
|
||||
IRestResponse response = (IRestResponse) apiClient.CallApi("/pet", Method.PUT, queryParams, postBody, headerParams, formParams, fileParams);
|
||||
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling UpdatePet: " + response.Content);
|
||||
}
|
||||
@@ -77,26 +78,27 @@ namespace IO.Swagger.Api {
|
||||
/// <returns></returns>
|
||||
public void AddPet (Pet Body) {
|
||||
|
||||
var _request = new RestRequest("/pet", Method.POST);
|
||||
|
||||
|
||||
|
||||
// add default header, if any
|
||||
foreach(KeyValuePair<string, string> defaultHeader in ApiInvoker.GetDefaultHeader())
|
||||
{
|
||||
_request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
||||
}
|
||||
var path = "/pet";
|
||||
path = path.Replace("{format}", "json");
|
||||
|
||||
|
||||
var queryParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>();
|
||||
var formParams = new Dictionary<String, String>();
|
||||
var fileParams = new Dictionary<String, String>();
|
||||
String postBody = null;
|
||||
|
||||
_request.AddUrlSegment("format", "json"); // set format to json by default
|
||||
|
||||
|
||||
|
||||
|
||||
_request.AddParameter("application/json", ApiInvoker.Serialize(Body), ParameterType.RequestBody); // http body (model) parameter
|
||||
postBody = apiClient.Serialize(Body); // http body (model) parameter
|
||||
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = restClient.Execute(_request);
|
||||
IRestResponse response = (IRestResponse) apiClient.CallApi("/pet", Method.POST, queryParams, postBody, headerParams, formParams, fileParams);
|
||||
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling AddPet: " + response.Content);
|
||||
}
|
||||
@@ -112,30 +114,31 @@ namespace IO.Swagger.Api {
|
||||
/// <returns>List<Pet></returns>
|
||||
public List<Pet> FindPetsByStatus (List<string> Status) {
|
||||
|
||||
var _request = new RestRequest("/pet/findByStatus", Method.GET);
|
||||
|
||||
|
||||
|
||||
// add default header, if any
|
||||
foreach(KeyValuePair<string, string> defaultHeader in ApiInvoker.GetDefaultHeader())
|
||||
{
|
||||
_request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
||||
}
|
||||
|
||||
_request.AddUrlSegment("format", "json"); // set format to json by default
|
||||
var path = "/pet/findByStatus";
|
||||
path = path.Replace("{format}", "json");
|
||||
|
||||
if (Status != null) _request.AddParameter("status", ApiInvoker.ParameterToString(Status)); // query parameter
|
||||
|
||||
var queryParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>();
|
||||
var formParams = new Dictionary<String, String>();
|
||||
var fileParams = new Dictionary<String, String>();
|
||||
String postBody = null;
|
||||
|
||||
if (Status != null) queryParams.Add("status", apiClient.ParameterToString(Status)); // query parameter
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = restClient.Execute(_request);
|
||||
IRestResponse response = (IRestResponse) apiClient.CallApi("/pet/findByStatus", Method.GET, queryParams, postBody, headerParams, formParams, fileParams);
|
||||
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByStatus: " + response.Content);
|
||||
}
|
||||
return (List<Pet>) ApiInvoker.Deserialize(response.Content, typeof(List<Pet>));
|
||||
return (List<Pet>) apiClient.Deserialize(response.Content, typeof(List<Pet>));
|
||||
}
|
||||
|
||||
|
||||
@@ -146,30 +149,31 @@ namespace IO.Swagger.Api {
|
||||
/// <returns>List<Pet></returns>
|
||||
public List<Pet> FindPetsByTags (List<string> Tags) {
|
||||
|
||||
var _request = new RestRequest("/pet/findByTags", Method.GET);
|
||||
|
||||
|
||||
|
||||
// add default header, if any
|
||||
foreach(KeyValuePair<string, string> defaultHeader in ApiInvoker.GetDefaultHeader())
|
||||
{
|
||||
_request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
||||
}
|
||||
|
||||
_request.AddUrlSegment("format", "json"); // set format to json by default
|
||||
var path = "/pet/findByTags";
|
||||
path = path.Replace("{format}", "json");
|
||||
|
||||
if (Tags != null) _request.AddParameter("tags", ApiInvoker.ParameterToString(Tags)); // query parameter
|
||||
|
||||
var queryParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>();
|
||||
var formParams = new Dictionary<String, String>();
|
||||
var fileParams = new Dictionary<String, String>();
|
||||
String postBody = null;
|
||||
|
||||
if (Tags != null) queryParams.Add("tags", apiClient.ParameterToString(Tags)); // query parameter
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = restClient.Execute(_request);
|
||||
IRestResponse response = (IRestResponse) apiClient.CallApi("/pet/findByTags", Method.GET, queryParams, postBody, headerParams, formParams, fileParams);
|
||||
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByTags: " + response.Content);
|
||||
}
|
||||
return (List<Pet>) ApiInvoker.Deserialize(response.Content, typeof(List<Pet>));
|
||||
return (List<Pet>) apiClient.Deserialize(response.Content, typeof(List<Pet>));
|
||||
}
|
||||
|
||||
|
||||
@@ -180,33 +184,34 @@ namespace IO.Swagger.Api {
|
||||
/// <returns>Pet</returns>
|
||||
public Pet GetPetById (long? PetId) {
|
||||
|
||||
var _request = new RestRequest("/pet/{petId}", Method.GET);
|
||||
|
||||
|
||||
// verify the required parameter 'PetId' is set
|
||||
if (PetId == null) throw new ApiException(400, "Missing required parameter 'PetId' when calling GetPetById");
|
||||
|
||||
|
||||
// add default header, if any
|
||||
foreach(KeyValuePair<string, string> defaultHeader in ApiInvoker.GetDefaultHeader())
|
||||
{
|
||||
_request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
||||
}
|
||||
|
||||
_request.AddUrlSegment("format", "json"); // set format to json by default
|
||||
_request.AddUrlSegment("petId", ApiInvoker.ParameterToString(PetId)); // path (url segment) parameter
|
||||
var path = "/pet/{petId}";
|
||||
path = path.Replace("{format}", "json");
|
||||
path = path.Replace("{" + "petId" + "}", apiClient.ParameterToString(PetId));
|
||||
|
||||
|
||||
var queryParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>();
|
||||
var formParams = new Dictionary<String, String>();
|
||||
var fileParams = new Dictionary<String, String>();
|
||||
String postBody = null;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = restClient.Execute(_request);
|
||||
IRestResponse response = (IRestResponse) apiClient.CallApi("/pet/{petId}", Method.GET, queryParams, postBody, headerParams, formParams, fileParams);
|
||||
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling GetPetById: " + response.Content);
|
||||
}
|
||||
return (Pet) ApiInvoker.Deserialize(response.Content, typeof(Pet));
|
||||
return (Pet) apiClient.Deserialize(response.Content, typeof(Pet));
|
||||
}
|
||||
|
||||
|
||||
@@ -219,31 +224,32 @@ namespace IO.Swagger.Api {
|
||||
/// <returns></returns>
|
||||
public void UpdatePetWithForm (string PetId, string Name, string Status) {
|
||||
|
||||
var _request = new RestRequest("/pet/{petId}", Method.POST);
|
||||
|
||||
|
||||
// verify the required parameter 'PetId' is set
|
||||
if (PetId == null) throw new ApiException(400, "Missing required parameter 'PetId' when calling UpdatePetWithForm");
|
||||
|
||||
|
||||
// add default header, if any
|
||||
foreach(KeyValuePair<string, string> defaultHeader in ApiInvoker.GetDefaultHeader())
|
||||
{
|
||||
_request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
||||
}
|
||||
var path = "/pet/{petId}";
|
||||
path = path.Replace("{format}", "json");
|
||||
path = path.Replace("{" + "petId" + "}", apiClient.ParameterToString(PetId));
|
||||
|
||||
|
||||
var queryParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>();
|
||||
var formParams = new Dictionary<String, String>();
|
||||
var fileParams = new Dictionary<String, String>();
|
||||
String postBody = null;
|
||||
|
||||
_request.AddUrlSegment("format", "json"); // set format to json by default
|
||||
_request.AddUrlSegment("petId", ApiInvoker.ParameterToString(PetId)); // path (url segment) parameter
|
||||
|
||||
|
||||
|
||||
if (Name != null) _request.AddParameter("name", ApiInvoker.ParameterToString(Name)); // form parameter
|
||||
if (Status != null) _request.AddParameter("status", ApiInvoker.ParameterToString(Status)); // form parameter
|
||||
if (Name != null) formParams.Add("name", apiClient.ParameterToString(Name)); // form parameter
|
||||
if (Status != null) formParams.Add("status", apiClient.ParameterToString(Status)); // form parameter
|
||||
|
||||
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = restClient.Execute(_request);
|
||||
IRestResponse response = (IRestResponse) apiClient.CallApi("/pet/{petId}", Method.POST, queryParams, postBody, headerParams, formParams, fileParams);
|
||||
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling UpdatePetWithForm: " + response.Content);
|
||||
}
|
||||
@@ -260,30 +266,31 @@ namespace IO.Swagger.Api {
|
||||
/// <returns></returns>
|
||||
public void DeletePet (string ApiKey, long? PetId) {
|
||||
|
||||
var _request = new RestRequest("/pet/{petId}", Method.DELETE);
|
||||
|
||||
|
||||
// verify the required parameter 'PetId' is set
|
||||
if (PetId == null) throw new ApiException(400, "Missing required parameter 'PetId' when calling DeletePet");
|
||||
|
||||
|
||||
// add default header, if any
|
||||
foreach(KeyValuePair<string, string> defaultHeader in ApiInvoker.GetDefaultHeader())
|
||||
{
|
||||
_request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
||||
}
|
||||
var path = "/pet/{petId}";
|
||||
path = path.Replace("{format}", "json");
|
||||
path = path.Replace("{" + "petId" + "}", apiClient.ParameterToString(PetId));
|
||||
|
||||
|
||||
var queryParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>();
|
||||
var formParams = new Dictionary<String, String>();
|
||||
var fileParams = new Dictionary<String, String>();
|
||||
String postBody = null;
|
||||
|
||||
_request.AddUrlSegment("format", "json"); // set format to json by default
|
||||
_request.AddUrlSegment("petId", ApiInvoker.ParameterToString(PetId)); // path (url segment) parameter
|
||||
|
||||
|
||||
if (ApiKey != null) _request.AddHeader("api_key", ApiInvoker.ParameterToString(ApiKey)); // header parameter
|
||||
if (ApiKey != null) headerParams.Add("api_key", apiClient.ParameterToString(ApiKey)); // header parameter
|
||||
|
||||
|
||||
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = restClient.Execute(_request);
|
||||
IRestResponse response = (IRestResponse) apiClient.CallApi("/pet/{petId}", Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams);
|
||||
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling DeletePet: " + response.Content);
|
||||
}
|
||||
@@ -301,31 +308,32 @@ namespace IO.Swagger.Api {
|
||||
/// <returns></returns>
|
||||
public void UploadFile (long? PetId, string AdditionalMetadata, string File) {
|
||||
|
||||
var _request = new RestRequest("/pet/{petId}/uploadImage", Method.POST);
|
||||
|
||||
|
||||
// verify the required parameter 'PetId' is set
|
||||
if (PetId == null) throw new ApiException(400, "Missing required parameter 'PetId' when calling UploadFile");
|
||||
|
||||
|
||||
// add default header, if any
|
||||
foreach(KeyValuePair<string, string> defaultHeader in ApiInvoker.GetDefaultHeader())
|
||||
{
|
||||
_request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
||||
}
|
||||
var path = "/pet/{petId}/uploadImage";
|
||||
path = path.Replace("{format}", "json");
|
||||
path = path.Replace("{" + "petId" + "}", apiClient.ParameterToString(PetId));
|
||||
|
||||
|
||||
var queryParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>();
|
||||
var formParams = new Dictionary<String, String>();
|
||||
var fileParams = new Dictionary<String, String>();
|
||||
String postBody = null;
|
||||
|
||||
_request.AddUrlSegment("format", "json"); // set format to json by default
|
||||
_request.AddUrlSegment("petId", ApiInvoker.ParameterToString(PetId)); // path (url segment) parameter
|
||||
|
||||
|
||||
|
||||
if (AdditionalMetadata != null) _request.AddParameter("additionalMetadata", ApiInvoker.ParameterToString(AdditionalMetadata)); // form parameter
|
||||
if (File != null) _request.AddFile("file", File);
|
||||
if (AdditionalMetadata != null) formParams.Add("additionalMetadata", apiClient.ParameterToString(AdditionalMetadata)); // form parameter
|
||||
if (File != null) fileParams.Add("file", File);
|
||||
|
||||
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = restClient.Execute(_request);
|
||||
IRestResponse response = (IRestResponse) apiClient.CallApi("/pet/{petId}/uploadImage", Method.POST, queryParams, postBody, headerParams, formParams, fileParams);
|
||||
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling UploadFile: " + response.Content);
|
||||
}
|
||||
|
||||
@@ -8,12 +8,12 @@ namespace IO.Swagger.Api {
|
||||
|
||||
public class StoreApi {
|
||||
string basePath;
|
||||
protected RestClient restClient;
|
||||
public ApiInvoker apiClient {get; set;}
|
||||
|
||||
public StoreApi(String basePath = "http://petstore.swagger.io/v2")
|
||||
{
|
||||
this.basePath = basePath;
|
||||
this.restClient = new RestClient(basePath);
|
||||
this.apiClient = new ApiInvoker(basePath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -41,29 +41,30 @@ namespace IO.Swagger.Api {
|
||||
/// <returns>Dictionary<String, int?></returns>
|
||||
public Dictionary<String, int?> GetInventory () {
|
||||
|
||||
var _request = new RestRequest("/store/inventory", Method.GET);
|
||||
|
||||
|
||||
|
||||
// add default header, if any
|
||||
foreach(KeyValuePair<string, string> defaultHeader in ApiInvoker.GetDefaultHeader())
|
||||
{
|
||||
_request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
||||
}
|
||||
|
||||
_request.AddUrlSegment("format", "json"); // set format to json by default
|
||||
var path = "/store/inventory";
|
||||
path = path.Replace("{format}", "json");
|
||||
|
||||
|
||||
var queryParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>();
|
||||
var formParams = new Dictionary<String, String>();
|
||||
var fileParams = new Dictionary<String, String>();
|
||||
String postBody = null;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = restClient.Execute(_request);
|
||||
IRestResponse response = (IRestResponse) apiClient.CallApi("/store/inventory", Method.GET, queryParams, postBody, headerParams, formParams, fileParams);
|
||||
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling GetInventory: " + response.Content);
|
||||
}
|
||||
return (Dictionary<String, int?>) ApiInvoker.Deserialize(response.Content, typeof(Dictionary<String, int?>));
|
||||
return (Dictionary<String, int?>) apiClient.Deserialize(response.Content, typeof(Dictionary<String, int?>));
|
||||
}
|
||||
|
||||
|
||||
@@ -74,30 +75,31 @@ namespace IO.Swagger.Api {
|
||||
/// <returns>Order</returns>
|
||||
public Order PlaceOrder (Order Body) {
|
||||
|
||||
var _request = new RestRequest("/store/order", Method.POST);
|
||||
|
||||
|
||||
|
||||
// add default header, if any
|
||||
foreach(KeyValuePair<string, string> defaultHeader in ApiInvoker.GetDefaultHeader())
|
||||
{
|
||||
_request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
||||
}
|
||||
var path = "/store/order";
|
||||
path = path.Replace("{format}", "json");
|
||||
|
||||
|
||||
var queryParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>();
|
||||
var formParams = new Dictionary<String, String>();
|
||||
var fileParams = new Dictionary<String, String>();
|
||||
String postBody = null;
|
||||
|
||||
_request.AddUrlSegment("format", "json"); // set format to json by default
|
||||
|
||||
|
||||
|
||||
|
||||
_request.AddParameter("application/json", ApiInvoker.Serialize(Body), ParameterType.RequestBody); // http body (model) parameter
|
||||
postBody = apiClient.Serialize(Body); // http body (model) parameter
|
||||
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = restClient.Execute(_request);
|
||||
IRestResponse response = (IRestResponse) apiClient.CallApi("/store/order", Method.POST, queryParams, postBody, headerParams, formParams, fileParams);
|
||||
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling PlaceOrder: " + response.Content);
|
||||
}
|
||||
return (Order) ApiInvoker.Deserialize(response.Content, typeof(Order));
|
||||
return (Order) apiClient.Deserialize(response.Content, typeof(Order));
|
||||
}
|
||||
|
||||
|
||||
@@ -108,33 +110,34 @@ namespace IO.Swagger.Api {
|
||||
/// <returns>Order</returns>
|
||||
public Order GetOrderById (string OrderId) {
|
||||
|
||||
var _request = new RestRequest("/store/order/{orderId}", Method.GET);
|
||||
|
||||
|
||||
// verify the required parameter 'OrderId' is set
|
||||
if (OrderId == null) throw new ApiException(400, "Missing required parameter 'OrderId' when calling GetOrderById");
|
||||
|
||||
|
||||
// add default header, if any
|
||||
foreach(KeyValuePair<string, string> defaultHeader in ApiInvoker.GetDefaultHeader())
|
||||
{
|
||||
_request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
||||
}
|
||||
|
||||
_request.AddUrlSegment("format", "json"); // set format to json by default
|
||||
_request.AddUrlSegment("orderId", ApiInvoker.ParameterToString(OrderId)); // path (url segment) parameter
|
||||
var path = "/store/order/{orderId}";
|
||||
path = path.Replace("{format}", "json");
|
||||
path = path.Replace("{" + "orderId" + "}", apiClient.ParameterToString(OrderId));
|
||||
|
||||
|
||||
var queryParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>();
|
||||
var formParams = new Dictionary<String, String>();
|
||||
var fileParams = new Dictionary<String, String>();
|
||||
String postBody = null;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = restClient.Execute(_request);
|
||||
IRestResponse response = (IRestResponse) apiClient.CallApi("/store/order/{orderId}", Method.GET, queryParams, postBody, headerParams, formParams, fileParams);
|
||||
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling GetOrderById: " + response.Content);
|
||||
}
|
||||
return (Order) ApiInvoker.Deserialize(response.Content, typeof(Order));
|
||||
return (Order) apiClient.Deserialize(response.Content, typeof(Order));
|
||||
}
|
||||
|
||||
|
||||
@@ -145,29 +148,30 @@ namespace IO.Swagger.Api {
|
||||
/// <returns></returns>
|
||||
public void DeleteOrder (string OrderId) {
|
||||
|
||||
var _request = new RestRequest("/store/order/{orderId}", Method.DELETE);
|
||||
|
||||
|
||||
// verify the required parameter 'OrderId' is set
|
||||
if (OrderId == null) throw new ApiException(400, "Missing required parameter 'OrderId' when calling DeleteOrder");
|
||||
|
||||
|
||||
// add default header, if any
|
||||
foreach(KeyValuePair<string, string> defaultHeader in ApiInvoker.GetDefaultHeader())
|
||||
{
|
||||
_request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
||||
}
|
||||
|
||||
_request.AddUrlSegment("format", "json"); // set format to json by default
|
||||
_request.AddUrlSegment("orderId", ApiInvoker.ParameterToString(OrderId)); // path (url segment) parameter
|
||||
var path = "/store/order/{orderId}";
|
||||
path = path.Replace("{format}", "json");
|
||||
path = path.Replace("{" + "orderId" + "}", apiClient.ParameterToString(OrderId));
|
||||
|
||||
|
||||
var queryParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>();
|
||||
var formParams = new Dictionary<String, String>();
|
||||
var fileParams = new Dictionary<String, String>();
|
||||
String postBody = null;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = restClient.Execute(_request);
|
||||
IRestResponse response = (IRestResponse) apiClient.CallApi("/store/order/{orderId}", Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams);
|
||||
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling DeleteOrder: " + response.Content);
|
||||
}
|
||||
|
||||
@@ -8,12 +8,12 @@ namespace IO.Swagger.Api {
|
||||
|
||||
public class UserApi {
|
||||
string basePath;
|
||||
protected RestClient restClient;
|
||||
public ApiInvoker apiClient {get; set;}
|
||||
|
||||
public UserApi(String basePath = "http://petstore.swagger.io/v2")
|
||||
{
|
||||
this.basePath = basePath;
|
||||
this.restClient = new RestClient(basePath);
|
||||
this.apiClient = new ApiInvoker(basePath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -42,26 +42,27 @@ namespace IO.Swagger.Api {
|
||||
/// <returns></returns>
|
||||
public void CreateUser (User Body) {
|
||||
|
||||
var _request = new RestRequest("/user", Method.POST);
|
||||
|
||||
|
||||
|
||||
// add default header, if any
|
||||
foreach(KeyValuePair<string, string> defaultHeader in ApiInvoker.GetDefaultHeader())
|
||||
{
|
||||
_request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
||||
}
|
||||
var path = "/user";
|
||||
path = path.Replace("{format}", "json");
|
||||
|
||||
|
||||
var queryParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>();
|
||||
var formParams = new Dictionary<String, String>();
|
||||
var fileParams = new Dictionary<String, String>();
|
||||
String postBody = null;
|
||||
|
||||
_request.AddUrlSegment("format", "json"); // set format to json by default
|
||||
|
||||
|
||||
|
||||
|
||||
_request.AddParameter("application/json", ApiInvoker.Serialize(Body), ParameterType.RequestBody); // http body (model) parameter
|
||||
postBody = apiClient.Serialize(Body); // http body (model) parameter
|
||||
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = restClient.Execute(_request);
|
||||
IRestResponse response = (IRestResponse) apiClient.CallApi("/user", Method.POST, queryParams, postBody, headerParams, formParams, fileParams);
|
||||
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling CreateUser: " + response.Content);
|
||||
}
|
||||
@@ -77,26 +78,27 @@ namespace IO.Swagger.Api {
|
||||
/// <returns></returns>
|
||||
public void CreateUsersWithArrayInput (List<User> Body) {
|
||||
|
||||
var _request = new RestRequest("/user/createWithArray", Method.POST);
|
||||
|
||||
|
||||
|
||||
// add default header, if any
|
||||
foreach(KeyValuePair<string, string> defaultHeader in ApiInvoker.GetDefaultHeader())
|
||||
{
|
||||
_request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
||||
}
|
||||
var path = "/user/createWithArray";
|
||||
path = path.Replace("{format}", "json");
|
||||
|
||||
|
||||
var queryParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>();
|
||||
var formParams = new Dictionary<String, String>();
|
||||
var fileParams = new Dictionary<String, String>();
|
||||
String postBody = null;
|
||||
|
||||
_request.AddUrlSegment("format", "json"); // set format to json by default
|
||||
|
||||
|
||||
|
||||
|
||||
_request.AddParameter("application/json", ApiInvoker.Serialize(Body), ParameterType.RequestBody); // http body (model) parameter
|
||||
postBody = apiClient.Serialize(Body); // http body (model) parameter
|
||||
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = restClient.Execute(_request);
|
||||
IRestResponse response = (IRestResponse) apiClient.CallApi("/user/createWithArray", Method.POST, queryParams, postBody, headerParams, formParams, fileParams);
|
||||
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithArrayInput: " + response.Content);
|
||||
}
|
||||
@@ -112,26 +114,27 @@ namespace IO.Swagger.Api {
|
||||
/// <returns></returns>
|
||||
public void CreateUsersWithListInput (List<User> Body) {
|
||||
|
||||
var _request = new RestRequest("/user/createWithList", Method.POST);
|
||||
|
||||
|
||||
|
||||
// add default header, if any
|
||||
foreach(KeyValuePair<string, string> defaultHeader in ApiInvoker.GetDefaultHeader())
|
||||
{
|
||||
_request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
||||
}
|
||||
var path = "/user/createWithList";
|
||||
path = path.Replace("{format}", "json");
|
||||
|
||||
|
||||
var queryParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>();
|
||||
var formParams = new Dictionary<String, String>();
|
||||
var fileParams = new Dictionary<String, String>();
|
||||
String postBody = null;
|
||||
|
||||
_request.AddUrlSegment("format", "json"); // set format to json by default
|
||||
|
||||
|
||||
|
||||
|
||||
_request.AddParameter("application/json", ApiInvoker.Serialize(Body), ParameterType.RequestBody); // http body (model) parameter
|
||||
postBody = apiClient.Serialize(Body); // http body (model) parameter
|
||||
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = restClient.Execute(_request);
|
||||
IRestResponse response = (IRestResponse) apiClient.CallApi("/user/createWithList", Method.POST, queryParams, postBody, headerParams, formParams, fileParams);
|
||||
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithListInput: " + response.Content);
|
||||
}
|
||||
@@ -148,31 +151,32 @@ namespace IO.Swagger.Api {
|
||||
/// <returns>string</returns>
|
||||
public string LoginUser (string Username, string Password) {
|
||||
|
||||
var _request = new RestRequest("/user/login", Method.GET);
|
||||
|
||||
|
||||
|
||||
// add default header, if any
|
||||
foreach(KeyValuePair<string, string> defaultHeader in ApiInvoker.GetDefaultHeader())
|
||||
{
|
||||
_request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
||||
}
|
||||
|
||||
_request.AddUrlSegment("format", "json"); // set format to json by default
|
||||
var path = "/user/login";
|
||||
path = path.Replace("{format}", "json");
|
||||
|
||||
if (Username != null) _request.AddParameter("username", ApiInvoker.ParameterToString(Username)); // query parameter
|
||||
if (Password != null) _request.AddParameter("password", ApiInvoker.ParameterToString(Password)); // query parameter
|
||||
|
||||
var queryParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>();
|
||||
var formParams = new Dictionary<String, String>();
|
||||
var fileParams = new Dictionary<String, String>();
|
||||
String postBody = null;
|
||||
|
||||
if (Username != null) queryParams.Add("username", apiClient.ParameterToString(Username)); // query parameter
|
||||
if (Password != null) queryParams.Add("password", apiClient.ParameterToString(Password)); // query parameter
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = restClient.Execute(_request);
|
||||
IRestResponse response = (IRestResponse) apiClient.CallApi("/user/login", Method.GET, queryParams, postBody, headerParams, formParams, fileParams);
|
||||
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling LoginUser: " + response.Content);
|
||||
}
|
||||
return (string) ApiInvoker.Deserialize(response.Content, typeof(string));
|
||||
return (string) apiClient.Deserialize(response.Content, typeof(string));
|
||||
}
|
||||
|
||||
|
||||
@@ -182,25 +186,26 @@ namespace IO.Swagger.Api {
|
||||
/// <returns></returns>
|
||||
public void LogoutUser () {
|
||||
|
||||
var _request = new RestRequest("/user/logout", Method.GET);
|
||||
|
||||
|
||||
|
||||
// add default header, if any
|
||||
foreach(KeyValuePair<string, string> defaultHeader in ApiInvoker.GetDefaultHeader())
|
||||
{
|
||||
_request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
||||
}
|
||||
|
||||
_request.AddUrlSegment("format", "json"); // set format to json by default
|
||||
var path = "/user/logout";
|
||||
path = path.Replace("{format}", "json");
|
||||
|
||||
|
||||
var queryParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>();
|
||||
var formParams = new Dictionary<String, String>();
|
||||
var fileParams = new Dictionary<String, String>();
|
||||
String postBody = null;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = restClient.Execute(_request);
|
||||
IRestResponse response = (IRestResponse) apiClient.CallApi("/user/logout", Method.GET, queryParams, postBody, headerParams, formParams, fileParams);
|
||||
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling LogoutUser: " + response.Content);
|
||||
}
|
||||
@@ -216,33 +221,34 @@ namespace IO.Swagger.Api {
|
||||
/// <returns>User</returns>
|
||||
public User GetUserByName (string Username) {
|
||||
|
||||
var _request = new RestRequest("/user/{username}", Method.GET);
|
||||
|
||||
|
||||
// verify the required parameter 'Username' is set
|
||||
if (Username == null) throw new ApiException(400, "Missing required parameter 'Username' when calling GetUserByName");
|
||||
|
||||
|
||||
// add default header, if any
|
||||
foreach(KeyValuePair<string, string> defaultHeader in ApiInvoker.GetDefaultHeader())
|
||||
{
|
||||
_request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
||||
}
|
||||
|
||||
_request.AddUrlSegment("format", "json"); // set format to json by default
|
||||
_request.AddUrlSegment("username", ApiInvoker.ParameterToString(Username)); // path (url segment) parameter
|
||||
var path = "/user/{username}";
|
||||
path = path.Replace("{format}", "json");
|
||||
path = path.Replace("{" + "username" + "}", apiClient.ParameterToString(Username));
|
||||
|
||||
|
||||
var queryParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>();
|
||||
var formParams = new Dictionary<String, String>();
|
||||
var fileParams = new Dictionary<String, String>();
|
||||
String postBody = null;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = restClient.Execute(_request);
|
||||
IRestResponse response = (IRestResponse) apiClient.CallApi("/user/{username}", Method.GET, queryParams, postBody, headerParams, formParams, fileParams);
|
||||
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling GetUserByName: " + response.Content);
|
||||
}
|
||||
return (User) ApiInvoker.Deserialize(response.Content, typeof(User));
|
||||
return (User) apiClient.Deserialize(response.Content, typeof(User));
|
||||
}
|
||||
|
||||
|
||||
@@ -254,30 +260,31 @@ namespace IO.Swagger.Api {
|
||||
/// <returns></returns>
|
||||
public void UpdateUser (string Username, User Body) {
|
||||
|
||||
var _request = new RestRequest("/user/{username}", Method.PUT);
|
||||
|
||||
|
||||
// verify the required parameter 'Username' is set
|
||||
if (Username == null) throw new ApiException(400, "Missing required parameter 'Username' when calling UpdateUser");
|
||||
|
||||
|
||||
// add default header, if any
|
||||
foreach(KeyValuePair<string, string> defaultHeader in ApiInvoker.GetDefaultHeader())
|
||||
{
|
||||
_request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
||||
}
|
||||
var path = "/user/{username}";
|
||||
path = path.Replace("{format}", "json");
|
||||
path = path.Replace("{" + "username" + "}", apiClient.ParameterToString(Username));
|
||||
|
||||
|
||||
var queryParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>();
|
||||
var formParams = new Dictionary<String, String>();
|
||||
var fileParams = new Dictionary<String, String>();
|
||||
String postBody = null;
|
||||
|
||||
_request.AddUrlSegment("format", "json"); // set format to json by default
|
||||
_request.AddUrlSegment("username", ApiInvoker.ParameterToString(Username)); // path (url segment) parameter
|
||||
|
||||
|
||||
|
||||
|
||||
_request.AddParameter("application/json", ApiInvoker.Serialize(Body), ParameterType.RequestBody); // http body (model) parameter
|
||||
postBody = apiClient.Serialize(Body); // http body (model) parameter
|
||||
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = restClient.Execute(_request);
|
||||
IRestResponse response = (IRestResponse) apiClient.CallApi("/user/{username}", Method.PUT, queryParams, postBody, headerParams, formParams, fileParams);
|
||||
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling UpdateUser: " + response.Content);
|
||||
}
|
||||
@@ -293,29 +300,30 @@ namespace IO.Swagger.Api {
|
||||
/// <returns></returns>
|
||||
public void DeleteUser (string Username) {
|
||||
|
||||
var _request = new RestRequest("/user/{username}", Method.DELETE);
|
||||
|
||||
|
||||
// verify the required parameter 'Username' is set
|
||||
if (Username == null) throw new ApiException(400, "Missing required parameter 'Username' when calling DeleteUser");
|
||||
|
||||
|
||||
// add default header, if any
|
||||
foreach(KeyValuePair<string, string> defaultHeader in ApiInvoker.GetDefaultHeader())
|
||||
{
|
||||
_request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
||||
}
|
||||
|
||||
_request.AddUrlSegment("format", "json"); // set format to json by default
|
||||
_request.AddUrlSegment("username", ApiInvoker.ParameterToString(Username)); // path (url segment) parameter
|
||||
var path = "/user/{username}";
|
||||
path = path.Replace("{format}", "json");
|
||||
path = path.Replace("{" + "username" + "}", apiClient.ParameterToString(Username));
|
||||
|
||||
|
||||
var queryParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>();
|
||||
var formParams = new Dictionary<String, String>();
|
||||
var fileParams = new Dictionary<String, String>();
|
||||
String postBody = null;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = restClient.Execute(_request);
|
||||
IRestResponse response = (IRestResponse) apiClient.CallApi("/user/{username}", Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams);
|
||||
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling DeleteUser: " + response.Content);
|
||||
}
|
||||
|
||||
@@ -5,10 +5,54 @@ using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using RestSharp;
|
||||
|
||||
namespace IO.Swagger.Client {
|
||||
public class ApiInvoker {
|
||||
private static Dictionary<String, String> defaultHeaderMap = new Dictionary<String, String>();
|
||||
public ApiInvoker() {
|
||||
this.basePath = "http://petstore.swagger.io/v2";
|
||||
}
|
||||
|
||||
public ApiInvoker(String basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
|
||||
public string basePath { get; set; }
|
||||
public RestClient restClient { get; set; }
|
||||
private Dictionary<String, String> defaultHeaderMap = new Dictionary<String, String>();
|
||||
|
||||
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) {
|
||||
|
||||
var request = new RestRequest(Path, Method);
|
||||
|
||||
// add default header, if any
|
||||
foreach(KeyValuePair<string, string> defaultHeader in this.defaultHeaderMap)
|
||||
request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
||||
|
||||
// add header parameter, if any
|
||||
foreach(KeyValuePair<string, string> param in HeaderParams)
|
||||
request.AddHeader(param.Key, param.Value);
|
||||
|
||||
// add query parameter, if any
|
||||
foreach(KeyValuePair<string, string> param in QueryParams)
|
||||
request.AddUrlSegment(param.Key, param.Value);
|
||||
|
||||
// add form parameter, if any
|
||||
foreach(KeyValuePair<string, string> param in FormParams)
|
||||
request.AddParameter(param.Key, param.Value);
|
||||
|
||||
// add file parameter, if any
|
||||
foreach(KeyValuePair<string, string> param in FormParams)
|
||||
request.AddFile(param.Key, param.Value);
|
||||
|
||||
if (PostBody == null) {
|
||||
request.AddParameter("application/json", PostBody, ParameterType.RequestBody); // http body (model) parameter
|
||||
}
|
||||
|
||||
return (Object)restClient.Execute(request);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add default header
|
||||
@@ -16,7 +60,7 @@ namespace IO.Swagger.Client {
|
||||
/// <param name="key"> Header field name
|
||||
/// <param name="value"> Header field value
|
||||
/// <returns></returns>
|
||||
public static void AddDefaultHeader(string key, string value) {
|
||||
public void AddDefaultHeader(string key, string value) {
|
||||
defaultHeaderMap.Add(key, value);
|
||||
}
|
||||
|
||||
@@ -24,7 +68,7 @@ namespace IO.Swagger.Client {
|
||||
/// Get default header
|
||||
/// </summary>
|
||||
/// <returns>Dictionary of default header</returns>
|
||||
public static Dictionary<String, String> GetDefaultHeader() {
|
||||
public Dictionary<String, String> GetDefaultHeader() {
|
||||
return defaultHeaderMap;
|
||||
}
|
||||
|
||||
@@ -33,7 +77,7 @@ namespace IO.Swagger.Client {
|
||||
/// </summary>
|
||||
/// <param name="str"> String to be escaped
|
||||
/// <returns>Escaped string</returns>
|
||||
public static string EscapeString(string str) {
|
||||
public string EscapeString(string str) {
|
||||
return str;
|
||||
}
|
||||
|
||||
@@ -42,7 +86,7 @@ namespace IO.Swagger.Client {
|
||||
/// </summary>
|
||||
/// <param name="obj"> The parameter (header, path, query, form)
|
||||
/// <returns>Formatted string</returns>
|
||||
public static string ParameterToString(object obj)
|
||||
public string ParameterToString(object obj)
|
||||
{
|
||||
return (obj is DateTime) ? ((DateTime)obj).ToString ("u") : Convert.ToString (obj);
|
||||
}
|
||||
@@ -53,7 +97,7 @@ namespace IO.Swagger.Client {
|
||||
/// <param name="json"> JSON string
|
||||
/// <param name="type"> Object type
|
||||
/// <returns>Object representation of the JSON string</returns>
|
||||
public static object Deserialize(string content, Type type) {
|
||||
public object Deserialize(string content, Type type) {
|
||||
if (type.GetType() == typeof(Object))
|
||||
return (Object)content;
|
||||
|
||||
@@ -71,7 +115,7 @@ namespace IO.Swagger.Client {
|
||||
/// </summary>
|
||||
/// <param name="obj"> Object
|
||||
/// <returns>JSON string</returns>
|
||||
public static string Serialize(object obj) {
|
||||
public string Serialize(object obj) {
|
||||
try
|
||||
{
|
||||
return obj != null ? JsonConvert.SerializeObject(obj) : null;
|
||||
|
||||
Reference in New Issue
Block a user