diff --git a/; b/; new file mode 100644 index 00000000000..40162ff7505 --- /dev/null +++ b/; @@ -0,0 +1,289 @@ +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; +using System.IO; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; +using RestSharp; + +namespace {{packageName}}.Client { + /// + /// API client is mainly responible for making the HTTP call to the API backend + /// + public class ApiClient { + + /// + /// Initializes a new instance of the class. + /// + /// The base path. + public ApiClient(String basePath="{{basePath}}") { + this.BasePath = basePath; + this.RestClient = new RestClient(this.BasePath); + } + + /// + /// Gets or sets the base path. + /// + /// The base path. + public string BasePath { get; set; } + + /// + /// Gets or sets the RestClient + /// + /// The RestClient. + public RestClient RestClient { get; set; } + + private Dictionary DefaultHeaderMap = new Dictionary(); + + public Object CallApi(String path, RestSharp.Method method, Dictionary queryParams, String postBody, + Dictionary headerParams, Dictionary formParams, + Dictionary fileParams, String[] authSettings) { + var response = Task.Run(async () => { + var resp = await CallApiAsync(path, method, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + return resp; + }); + return response.Result; + } + + public async Task CallApiAsync(String path, RestSharp.Method method, Dictionary queryParams, String postBody, + Dictionary headerParams, Dictionary formParams, Dictionary fileParams, String[] authSettings) { + + var request = new RestRequest(path, method); + + UpdateParamsForAuth(queryParams, headerParams, authSettings); + + // add default header, if any + foreach(KeyValuePair defaultHeader in this.DefaultHeaderMap) + request.AddHeader(defaultHeader.Key, defaultHeader.Value); + + // add header parameter, if any + foreach(KeyValuePair param in headerParams) + request.AddHeader(param.Key, param.Value); + + // add query parameter, if any + foreach(KeyValuePair param in queryParams) + request.AddQueryParameter(param.Key, param.Value); + + // add form parameter, if any + foreach(KeyValuePair param in formParams) + request.AddParameter(param.Key, param.Value); + + // add file parameter, if any + foreach(KeyValuePair param in fileParams) + request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType); + + + if (postBody != null) { + request.AddParameter("application/json", postBody, ParameterType.RequestBody); // http body (model) parameter + } + + return (Object) await RestClient.ExecuteTaskAsync(request); + + } + + /// + /// Add default header + /// + /// Header field name + /// Header field value + /// + public void AddDefaultHeader(string key, string value) { + DefaultHeaderMap.Add(key, value); + } + + /// + /// Get default header + /// + /// Dictionary of default header + public Dictionary GetDefaultHeader() { + return DefaultHeaderMap; + } + + /// + /// escape string (url-encoded) + /// + /// String to be escaped + /// Escaped string + public string EscapeString(string str) { + return str; + } + + /// + /// Create FileParameter based on Stream + /// + /// parameter name + /// Stream + /// FileParameter + public FileParameter ParameterToFile(string name, Stream stream) + { + if (stream is FileStream) { + return FileParameter.Create(name, StreamToByteArray(stream), ((FileStream)stream).Name); + } else { + return FileParameter.Create(name, StreamToByteArray(stream), "temp_name_here"); + } + } + + /// + /// if parameter is DateTime, output in ISO8601 format + /// if parameter is a list of string, join the list with "," + /// otherwise just return the string + /// + /// The parameter (header, path, query, form) + /// Formatted string + public string ParameterToString(object obj) + { + if (obj is DateTime) { + return ((DateTime)obj).ToString ("u"); + } else if (obj is List) { + return String.Join(",", obj as List); + } else { + return Convert.ToString (obj); + } + } + + /// + /// Deserialize the JSON string into a proper object + /// + /// HTTP body (e.g. string, JSON) + /// Object type + /// Object representation of the JSON string + public object Deserialize(string content, Type type, IList headers=null) { + if (type.GetType() == typeof(Object)) { // return an object + return (Object)content; + } else if (type.Name == "Stream") { + String fileName, filePath; + if (String.IsNullOrEmpty (Configuration.TempFolderPath)) { + filePath = System.IO.Path.GetTempPath (); + } else { + filePath = Configuration.TempFolderPath; + } + + Regex regex = new Regex(@"Content-Disposition:.*filename=['""]?([^'""\s]+)['""]?$"); + Match match = regex.Match(headers.ToString()); + if (match.Success) { + // replace first and last " or ', if found + fileName = filePath + match.Value.Replace("\"", "").Replace("'",""); + } else { + fileName = filePath + Guid.NewGuid().ToString(); + } + File.WriteAllText (fileName, content); + return new FileStream(fileName, FileMode.Open); + } else if (type.Name.StartsWith("System.Nullable`1[[System.DateTime")) { // return a datetime object + return DateTime.Parse(content, null, System.Globalization.DateTimeStyles.RoundtripKind); + } else if (type.Name == "String" || type.Name.StartsWith("System.Nullable")) { // return primitive + return ConvertType(content, type); + } + + // at this point, it must be a model (json) + try + { + return JsonConvert.DeserializeObject(content, type); + } + catch (IOException e) { + throw new ApiException(500, e.Message); + } + } + + /// + /// Serialize an object into JSON string + /// + /// Object + /// JSON string + public string Serialize(object obj) { + try + { + return obj != null ? JsonConvert.SerializeObject(obj) : null; + } + catch (Exception e) { + throw new ApiException(500, e.Message); + } + } + + /// + /// Get the API key with prefix + /// + /// Object + /// API key with prefix + public string GetApiKeyWithPrefix (string apiKeyIdentifier) + { + var apiKeyValue = ""; + Configuration.ApiKey.TryGetValue (apiKeyIdentifier, out apiKeyValue); + var apiKeyPrefix = ""; + if (Configuration.ApiKeyPrefix.TryGetValue (apiKeyIdentifier, out apiKeyPrefix)) { + return apiKeyPrefix + " " + apiKeyValue; + } else { + return apiKeyValue; + } + } + + /// + /// Update parameters based on authentication + /// + /// Query parameters + /// Header parameters + /// Authentication settings + public void UpdateParamsForAuth(Dictionary queryParams, Dictionary 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; + } + } + + } + + /// + /// convert a stream to byte array (byte[]) + /// Ref: http://stackoverflow.com/questions/221925/creating-a-byte-array-from-a-stream + /// + /// input stream + /// Array of Byte + public byte[] StreamToByteArray(Stream input) + { + byte[] buffer = new byte[16*1024]; + using (MemoryStream ms = new MemoryStream()) + { + int read; + while ((read = input.Read(buffer, 0, buffer.Length)) > 0) + { + ms.Write(buffer, 0, read); + } + return ms.ToArray(); + } + } + + /// + /// Encode string in base64 format + /// + /// String to be encoded + public static string Base64Encode(string text) { + var textByte = System.Text.Encoding.UTF8.GetBytes(text); + return System.Convert.ToBase64String(textByte); + } + + /// + /// Dynamically cast the object into target type + /// Ref: http://stackoverflow.com/questions/4925718/c-dynamic-runtime-cast + /// + /// Object to be casted + /// Target type + public static dynamic ConvertType(dynamic source, Type dest) { + return Convert.ChangeType(source, dest); + } + + } +} diff --git a/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache index f4ffee145ed..fc3825491d2 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache @@ -10,279 +10,280 @@ using Newtonsoft.Json; using RestSharp; namespace {{packageName}}.Client { - /// - /// API client is mainly responible for making the HTTP call to the API backend - /// - public class ApiClient { - /// - /// Initializes a new instance of the class. + /// API client is mainly responible for making the HTTP call to the API backend /// - /// The base path. - public ApiClient(String basePath="{{basePath}}") { - this.BasePath = basePath; - this.RestClient = new RestClient(this.BasePath); - } - - /// - /// Gets or sets the base path. - /// - /// The base path. - public string BasePath { get; set; } - - /// - /// Gets or sets the RestClient - /// - /// The RestClient. - public RestClient RestClient { get; set; } - - private Dictionary DefaultHeaderMap = new Dictionary(); - - public Object CallApi(String path, RestSharp.Method method, Dictionary queryParams, String postBody, - Dictionary headerParams, Dictionary formParams, Dictionary fileParams, String[] authSettings) { - var response = Task.Run(async () => { - var resp = await CallApiAsync(path, method, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - return resp; - }); - return response.Result; - } - - public async Task CallApiAsync(String path, RestSharp.Method method, Dictionary queryParams, String postBody, - Dictionary headerParams, Dictionary formParams, Dictionary fileParams, String[] authSettings) { - - var request = new RestRequest(path, method); - - UpdateParamsForAuth(queryParams, headerParams, authSettings); - - // add default header, if any - foreach(KeyValuePair defaultHeader in this.DefaultHeaderMap) - request.AddHeader(defaultHeader.Key, defaultHeader.Value); - - // add header parameter, if any - foreach(KeyValuePair param in headerParams) - request.AddHeader(param.Key, param.Value); - - // add query parameter, if any - foreach(KeyValuePair param in queryParams) - request.AddQueryParameter(param.Key, param.Value); - - // add form parameter, if any - foreach(KeyValuePair param in formParams) - request.AddParameter(param.Key, param.Value); - - // add file parameter, if any - foreach(KeyValuePair param in fileParams) - request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType); - - - if (postBody != null) { - request.AddParameter("application/json", postBody, ParameterType.RequestBody); // http body (model) parameter - } - - return (Object) await RestClient.ExecuteTaskAsync(request); - - } - - /// - /// Add default header - /// - /// Header field name - /// Header field value - /// - public void AddDefaultHeader(string key, string value) { - DefaultHeaderMap.Add(key, value); - } - - /// - /// Get default header - /// - /// Dictionary of default header - public Dictionary GetDefaultHeader() { - return DefaultHeaderMap; - } - - /// - /// escape string (url-encoded) - /// - /// String to be escaped - /// Escaped string - public string EscapeString(string str) { - return str; - } - - /// - /// Create FileParameter based on Stream - /// - /// parameter name - /// Stream - /// FileParameter - public FileParameter ParameterToFile(string name, Stream stream) - { - if (stream is FileStream) { - return FileParameter.Create(name, StreamToByteArray(stream), ((FileStream)stream).Name); - } else { - return FileParameter.Create(name, StreamToByteArray(stream), "temp_name_here"); - } - } - - /// - /// if parameter is DateTime, output in ISO8601 format - /// if parameter is a list of string, join the list with "," - /// otherwise just return the string - /// - /// The parameter (header, path, query, form) - /// Formatted string - public string ParameterToString(object obj) - { - if (obj is DateTime) { - return ((DateTime)obj).ToString ("u"); - } else if (obj is List) { - return String.Join(",", obj as List); - } else { - return Convert.ToString (obj); - } - } - - /// - /// Deserialize the JSON string into a proper object - /// - /// HTTP body (e.g. string, JSON) - /// Object type - /// Object representation of the JSON string - public object Deserialize(string content, Type type, IList headers=null) { - if (type.GetType() == typeof(Object)) { // return an object - return (Object)content; - } else if (type.Name == "Stream") { - String fileName, filePath; - if (String.IsNullOrEmpty (Configuration.TempFolderPath)) { - filePath = System.IO.Path.GetTempPath (); - } else { - filePath = Configuration.TempFolderPath; - } - - Regex regex = new Regex(@"Content-Disposition:.*filename=['""]?([^'""\s]+)['""]?$"); - Match match = regex.Match(headers.ToString()); - if (match.Success) { - // replace first and last " or ', if found - fileName = filePath + match.Value.Replace("\"", "").Replace("'",""); - } else { - fileName = filePath + Guid.NewGuid().ToString(); - } - File.WriteAllText (fileName, content); - return new FileStream(fileName, FileMode.Open); - } else if (type.Name.StartsWith("System.Nullable`1[[System.DateTime")) { // return a datetime object - return DateTime.Parse(content, null, System.Globalization.DateTimeStyles.RoundtripKind); - } else if (type.Name == "String" || type.Name.StartsWith("System.Nullable")) { // return primitive - return ConvertType(content, type); - } - - // at this point, it must be a model (json) - try - { - return JsonConvert.DeserializeObject(content, type); - } - catch (IOException e) { - throw new ApiException(500, e.Message); - } - } - - /// - /// Serialize an object into JSON string - /// - /// Object - /// JSON string - public string Serialize(object obj) { - try - { - return obj != null ? JsonConvert.SerializeObject(obj) : null; - } - catch (Exception e) { - throw new ApiException(500, e.Message); - } - } - - /// - /// Get the API key with prefix - /// - /// Object - /// API key with prefix - public string GetApiKeyWithPrefix (string apiKeyIdentifier) - { - var apiKeyValue = ""; - Configuration.ApiKey.TryGetValue (apiKeyIdentifier, out apiKeyValue); - var apiKeyPrefix = ""; - if (Configuration.ApiKeyPrefix.TryGetValue (apiKeyIdentifier, out apiKeyPrefix)) { - return apiKeyPrefix + " " + apiKeyValue; - } else { - return apiKeyValue; - } - } - - /// - /// Update parameters based on authentication - /// - /// Query parameters - /// Header parameters - /// Authentication settings - public void UpdateParamsForAuth(Dictionary queryParams, Dictionary headerParams, string[] authSettings) { - if (authSettings == null || authSettings.Length == 0) - return; + public class ApiClient { - 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; + /// + /// Initializes a new instance of the class. + /// + /// The base path. + public ApiClient(String basePath="{{basePath}}") { + this.BasePath = basePath; + this.RestClient = new RestClient(this.BasePath); } - } - - } - - /// - /// convert a stream to byte array (byte[]) - /// Ref: http://stackoverflow.com/questions/221925/creating-a-byte-array-from-a-stream - /// - /// input stream - /// Array of Byte - public byte[] StreamToByteArray(Stream input) - { - byte[] buffer = new byte[16*1024]; - using (MemoryStream ms = new MemoryStream()) - { - int read; - while ((read = input.Read(buffer, 0, buffer.Length)) > 0) - { - ms.Write(buffer, 0, read); + + /// + /// Gets or sets the base path. + /// + /// The base path. + public string BasePath { get; set; } + + /// + /// Gets or sets the RestClient + /// + /// The RestClient. + public RestClient RestClient { get; set; } + + private Dictionary DefaultHeaderMap = new Dictionary(); + + public Object CallApi(String path, RestSharp.Method method, Dictionary queryParams, String postBody, + Dictionary headerParams, Dictionary formParams, + Dictionary fileParams, String[] authSettings) { + var response = Task.Run(async () => { + var resp = await CallApiAsync(path, method, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + return resp; + }); + return response.Result; + } + + public async Task CallApiAsync(String path, RestSharp.Method method, Dictionary queryParams, String postBody, + Dictionary headerParams, Dictionary formParams, Dictionary fileParams, String[] authSettings) { + + var request = new RestRequest(path, method); + + UpdateParamsForAuth(queryParams, headerParams, authSettings); + + // add default header, if any + foreach(KeyValuePair defaultHeader in this.DefaultHeaderMap) + request.AddHeader(defaultHeader.Key, defaultHeader.Value); + + // add header parameter, if any + foreach(KeyValuePair param in headerParams) + request.AddHeader(param.Key, param.Value); + + // add query parameter, if any + foreach(KeyValuePair param in queryParams) + request.AddQueryParameter(param.Key, param.Value); + + // add form parameter, if any + foreach(KeyValuePair param in formParams) + request.AddParameter(param.Key, param.Value); + + // add file parameter, if any + foreach(KeyValuePair param in fileParams) + request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType); + + + if (postBody != null) { + request.AddParameter("application/json", postBody, ParameterType.RequestBody); // http body (model) parameter } - return ms.ToArray(); + + return (Object) await RestClient.ExecuteTaskAsync(request); + } + + /// + /// Add default header + /// + /// Header field name + /// Header field value + /// + public void AddDefaultHeader(string key, string value) { + DefaultHeaderMap.Add(key, value); + } + + /// + /// Get default header + /// + /// Dictionary of default header + public Dictionary GetDefaultHeader() { + return DefaultHeaderMap; + } + + /// + /// escape string (url-encoded) + /// + /// String to be escaped + /// Escaped string + public string EscapeString(string str) { + return str; + } + + /// + /// Create FileParameter based on Stream + /// + /// parameter name + /// Input stream + /// FileParameter + public FileParameter ParameterToFile(string name, Stream stream) + { + if (stream is FileStream) { + return FileParameter.Create(name, StreamToByteArray(stream), ((FileStream)stream).Name); + } else { + return FileParameter.Create(name, StreamToByteArray(stream), "temp_name_here"); + } + } + + /// + /// if parameter is DateTime, output in ISO8601 format + /// if parameter is a list of string, join the list with "," + /// otherwise just return the string + /// + /// The parameter (header, path, query, form) + /// Formatted string + public string ParameterToString(object obj) + { + if (obj is DateTime) { + return ((DateTime)obj).ToString ("u"); + } else if (obj is List) { + return String.Join(",", obj as List); + } else { + return Convert.ToString (obj); + } + } + + /// + /// Deserialize the JSON string into a proper object + /// + /// HTTP body (e.g. string, JSON) + /// Object type + /// Object representation of the JSON string + public object Deserialize(string content, Type type, IList headers=null) { + if (type.GetType() == typeof(Object)) { // return an object + return (Object)content; + } else if (type.Name == "Stream") { + String fileName, filePath; + if (String.IsNullOrEmpty (Configuration.TempFolderPath)) { + filePath = System.IO.Path.GetTempPath (); + } else { + filePath = Configuration.TempFolderPath; + } + + Regex regex = new Regex(@"Content-Disposition:.*filename=['""]?([^'""\s]+)['""]?$"); + Match match = regex.Match(headers.ToString()); + if (match.Success) { + // replace first and last " or ', if found + fileName = filePath + match.Value.Replace("\"", "").Replace("'",""); + } else { + fileName = filePath + Guid.NewGuid().ToString(); + } + File.WriteAllText (fileName, content); + return new FileStream(fileName, FileMode.Open); + } else if (type.Name.StartsWith("System.Nullable`1[[System.DateTime")) { // return a datetime object + return DateTime.Parse(content, null, System.Globalization.DateTimeStyles.RoundtripKind); + } else if (type.Name == "String" || type.Name.StartsWith("System.Nullable")) { // return primitive + return ConvertType(content, type); + } + + // at this point, it must be a model (json) + try + { + return JsonConvert.DeserializeObject(content, type); + } + catch (IOException e) { + throw new ApiException(500, e.Message); + } + } + + /// + /// Serialize an object into JSON string + /// + /// Object + /// JSON string + public string Serialize(object obj) { + try + { + return obj != null ? JsonConvert.SerializeObject(obj) : null; + } + catch (Exception e) { + throw new ApiException(500, e.Message); + } + } + + /// + /// Get the API key with prefix + /// + /// Object + /// API key with prefix + public string GetApiKeyWithPrefix (string apiKeyIdentifier) + { + var apiKeyValue = ""; + Configuration.ApiKey.TryGetValue (apiKeyIdentifier, out apiKeyValue); + var apiKeyPrefix = ""; + if (Configuration.ApiKeyPrefix.TryGetValue (apiKeyIdentifier, out apiKeyPrefix)) { + return apiKeyPrefix + " " + apiKeyValue; + } else { + return apiKeyValue; + } + } + + /// + /// Update parameters based on authentication + /// + /// Query parameters + /// Header parameters + /// Authentication settings + public void UpdateParamsForAuth(Dictionary queryParams, Dictionary 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; + } + } + + } + + /// + /// convert a stream to byte array (byte[]) + /// Ref: http://stackoverflow.com/questions/221925/creating-a-byte-array-from-a-stream + /// + /// input stream + /// Array of Byte + public byte[] StreamToByteArray(Stream input) + { + byte[] buffer = new byte[16*1024]; + using (MemoryStream ms = new MemoryStream()) + { + int read; + while ((read = input.Read(buffer, 0, buffer.Length)) > 0) + { + ms.Write(buffer, 0, read); + } + return ms.ToArray(); + } + } + + /// + /// Encode string in base64 format + /// + /// String to be encoded + public static string Base64Encode(string text) { + var textByte = System.Text.Encoding.UTF8.GetBytes(text); + return System.Convert.ToBase64String(textByte); + } + + /// + /// Dynamically cast the object into target type + /// Ref: http://stackoverflow.com/questions/4925718/c-dynamic-runtime-cast + /// + /// Object to be casted + /// Target type + public static dynamic ConvertType(dynamic source, Type dest) { + return Convert.ChangeType(source, dest); + } + } - - /// - /// Encode string in base64 format - /// - /// String to be encoded - public static string Base64Encode(string text) { - var textByte = System.Text.Encoding.UTF8.GetBytes(text); - return System.Convert.ToBase64String(textByte); - } - - /// - /// Dynamically cast the object into target type - /// Ref: http://stackoverflow.com/questions/4925718/c-dynamic-runtime-cast - /// - /// Object to be casted - /// Target type - public static dynamic ConvertType(dynamic source, Type dest) { - return Convert.ChangeType(source, dest); - } - - } } diff --git a/modules/swagger-codegen/src/main/resources/csharp/api.mustache b/modules/swagger-codegen/src/main/resources/csharp/api.mustache index 47fcc1bef1d..2f6cca4c388 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/api.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/api.mustache @@ -8,165 +8,162 @@ using {{packageName}}.Client; {{/hasImport}} namespace {{packageName}}.Api { - {{#operations}} - public interface I{{classname}} { - {{#operation}} - /// - /// {{summary}} {{notes}} - /// - {{#allParams}}/// {{description}} - {{/allParams}}{{#returnType}}/// {{{returnType}}}{{/returnType}} - {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); - - /// - /// {{summary}} {{notes}} - /// - {{#allParams}}/// {{description}} - {{/allParams}}{{#returnType}}/// {{{returnType}}}{{/returnType}} - {{#returnType}}Task<{{{returnType}}}>{{/returnType}}{{^returnType}}Task{{/returnType}} {{nickname}}Async ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); - {{/operation}} - } - - /// - /// Represents a collection of functions to interact with the API endpoints - /// - public class {{classname}} : I{{classname}} { - - /// - /// Initializes a new instance of the class. - /// - /// an instance of ApiClient (optional) - /// - public {{classname}}(ApiClient apiClient = null) { - if (apiClient == null) { // use the default one in Configuration - this.ApiClient = Configuration.DefaultApiClient; - } else { - this.ApiClient = apiClient; - } + {{#operations}} + public interface I{{classname}} { + {{#operation}} + /// + /// {{summary}} {{notes}} + /// + {{#allParams}}/// {{description}} + {{/allParams}}{{#returnType}}/// {{{returnType}}} + {{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); + + /// + /// {{summary}} {{notes}} + /// + {{#allParams}}/// {{description}} + {{/allParams}}{{#returnType}}/// {{{returnType}}} + Task<{{{returnType}}}>{{/returnType}}{{^returnType}}Task{{/returnType}} {{nickname}}Async ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); + {{/operation}} } - + /// - /// Initializes a new instance of the class. + /// Represents a collection of functions to interact with the API endpoints /// - /// - public {{classname}}(String basePath) - { - this.ApiClient = new ApiClient(basePath); - } - - /// - /// Sets the base path of the API client. - /// - /// The base path - public void SetBasePath(String basePath) { - this.ApiClient.BasePath = basePath; - } - - /// - /// Gets the base path of the API client. - /// - /// The base path - public String GetBasePath(String basePath) { - return this.ApiClient.BasePath; - } - - /// - /// Gets or sets the API client. - /// - /// The API client - public ApiClient ApiClient {get; set;} - - - {{#operation}} - /// - /// {{summary}} {{notes}} - /// - {{#allParams}}/// {{description}} - {{/allParams}}{{#returnType}}/// {{{returnType}}}{{/returnType}} - public {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { - - {{#allParams}}{{#required}} - // verify the required parameter '{{paramName}}' is set - if ({{paramName}} == null) throw new ApiException(400, "Missing required parameter '{{paramName}}' when calling {{nickname}}"); - {{/required}}{{/allParams}} - - var path = "{{path}}"; - path = path.Replace("{format}", "json"); - {{#pathParams}}path = path.Replace("{" + "{{baseName}}" + "}", ApiClient.ParameterToString({{{paramName}}})); - {{/pathParams}} - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - {{#queryParams}} if ({{paramName}} != null) queryParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // query parameter - {{/queryParams}} - {{#headerParams}} if ({{paramName}} != null) headerParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // header parameter - {{/headerParams}} - {{#formParams}}if ({{paramName}} != null) {{#isFile}}fileParams.Add("{{baseName}}", ApiClient.ParameterToFile("{{baseName}}", {{paramName}}));{{/isFile}}{{^isFile}}formParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // form parameter{{/isFile}} - {{/formParams}} - {{#bodyParam}}postBody = ApiClient.Serialize({{paramName}}); // http body (model) parameter - {{/bodyParam}} - - // authentication setting, if any - String[] authSettings = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} }; - - // make the HTTP request - IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.{{httpMethod}}, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.Content, response.Content); - } - - {{#returnType}}return ({{{returnType}}}) ApiClient.Deserialize(response.Content, typeof({{{returnType}}}), response.Headers);{{/returnType}}{{^returnType}}return;{{/returnType}} - } - - /// - /// {{summary}} {{notes}} - /// - {{#allParams}}/// {{description}} - {{/allParams}}{{#returnType}}/// {{{returnType}}}{{/returnType}} - public async {{#returnType}}Task<{{{returnType}}}>{{/returnType}}{{^returnType}}Task{{/returnType}} {{nickname}}Async ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { - - {{#allParams}}{{#required}} - // verify the required parameter '{{paramName}}' is set - if ({{paramName}} == null) throw new ApiException(400, "Missing required parameter '{{paramName}}' when calling {{nickname}}"); - {{/required}}{{/allParams}} - - var path = "{{path}}"; - path = path.Replace("{format}", "json"); - {{#pathParams}}path = path.Replace("{" + "{{baseName}}" + "}", ApiClient.ParameterToString({{{paramName}}})); - {{/pathParams}} - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - {{#queryParams}} if ({{paramName}} != null) queryParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // query parameter - {{/queryParams}} - {{#headerParams}} if ({{paramName}} != null) headerParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // header parameter - {{/headerParams}} - {{#formParams}}if ({{paramName}} != null) {{#isFile}}fileParams.Add("{{baseName}}", ApiClient.ParameterToFile("{{baseName}}", {{paramName}}));{{/isFile}}{{^isFile}}formParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // form parameter{{/isFile}} - {{/formParams}} - {{#bodyParam}}postBody = ApiClient.Serialize({{paramName}}); // http body (model) parameter - {{/bodyParam}} - - // authentication setting, if any - String[] authSettings = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} }; - - // make the HTTP request - IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.{{httpMethod}}, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.Content, response.Content); - } - {{#returnType}}return ({{{returnType}}}) ApiClient.Deserialize(response.Content, typeof({{{returnType}}}), response.Headers);{{/returnType}}{{^returnType}} - return;{{/returnType}} - } - {{/operation}} - } - {{/operations}} + public class {{classname}} : I{{classname}} { + + /// + /// Initializes a new instance of the class. + /// + /// an instance of ApiClient (optional) + /// + public {{classname}}(ApiClient apiClient = null) { + if (apiClient == null) { // use the default one in Configuration + this.ApiClient = Configuration.DefaultApiClient; + } else { + this.ApiClient = apiClient; + } + } + + /// + /// Initializes a new instance of the class. + /// + /// + public {{classname}}(String basePath) + { + this.ApiClient = new ApiClient(basePath); + } + + /// + /// Sets the base path of the API client. + /// + /// The base path + public void SetBasePath(String basePath) { + this.ApiClient.BasePath = basePath; + } + + /// + /// Gets the base path of the API client. + /// + /// The base path + public String GetBasePath(String basePath) { + return this.ApiClient.BasePath; + } + + /// + /// Gets or sets the API client. + /// + /// The API client + public ApiClient ApiClient {get; set;} + + {{#operation}} + /// + /// {{summary}} {{notes}} + /// + {{#allParams}}/// {{description}} + {{/allParams}}{{#returnType}}/// {{{returnType}}} + public {{{returnType}}}{{/returnType}}{{^returnType}}public void{{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { + + {{#allParams}}{{#required}} + // verify the required parameter '{{paramName}}' is set + if ({{paramName}} == null) throw new ApiException(400, "Missing required parameter '{{paramName}}' when calling {{nickname}}"); + {{/required}}{{/allParams}} + + var path = "{{path}}"; + path = path.Replace("{format}", "json"); + {{#pathParams}}path = path.Replace("{" + "{{baseName}}" + "}", ApiClient.ParameterToString({{{paramName}}})); + {{/pathParams}} + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + {{#queryParams}} if ({{paramName}} != null) queryParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // query parameter + {{/queryParams}} + {{#headerParams}} if ({{paramName}} != null) headerParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // header parameter + {{/headerParams}} + {{#formParams}}if ({{paramName}} != null) {{#isFile}}fileParams.Add("{{baseName}}", ApiClient.ParameterToFile("{{baseName}}", {{paramName}}));{{/isFile}}{{^isFile}}formParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // form parameter{{/isFile}} + {{/formParams}} + {{#bodyParam}}postBody = ApiClient.Serialize({{paramName}}); // http body (model) parameter + {{/bodyParam}} + + // authentication setting, if any + String[] authSettings = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} }; + + // make the HTTP request + IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.{{httpMethod}}, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.Content, response.Content); + } + + {{#returnType}}return ({{{returnType}}}) ApiClient.Deserialize(response.Content, typeof({{{returnType}}}), response.Headers);{{/returnType}}{{^returnType}}return;{{/returnType}} + } + + /// + /// {{summary}} {{notes}} + /// + {{#allParams}}/// {{description}} + {{/allParams}}{{#returnType}}/// {{{returnType}}} + public async Task<{{{returnType}}}>{{/returnType}}{{^returnType}}public async Task{{/returnType}} {{nickname}}Async ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { + {{#allParams}}{{#required}}// verify the required parameter '{{paramName}}' is set + if ({{paramName}} == null) throw new ApiException(400, "Missing required parameter '{{paramName}}' when calling {{nickname}}"); + {{/required}}{{/allParams}} + + var path = "{{path}}"; + path = path.Replace("{format}", "json"); + {{#pathParams}}path = path.Replace("{" + "{{baseName}}" + "}", ApiClient.ParameterToString({{{paramName}}})); + {{/pathParams}} + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + {{#queryParams}} if ({{paramName}} != null) queryParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // query parameter + {{/queryParams}} + {{#headerParams}} if ({{paramName}} != null) headerParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // header parameter + {{/headerParams}} + {{#formParams}}if ({{paramName}} != null) {{#isFile}}fileParams.Add("{{baseName}}", ApiClient.ParameterToFile("{{baseName}}", {{paramName}}));{{/isFile}}{{^isFile}}formParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // form parameter{{/isFile}} + {{/formParams}} + {{#bodyParam}}postBody = ApiClient.Serialize({{paramName}}); // http body (model) parameter + {{/bodyParam}} + + // authentication setting, if any + String[] authSettings = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} }; + + // make the HTTP request + IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.{{httpMethod}}, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.Content, response.Content); + } + {{#returnType}}return ({{{returnType}}}) ApiClient.Deserialize(response.Content, typeof({{{returnType}}}), response.Headers);{{/returnType}}{{^returnType}} + return;{{/returnType}} + } + {{/operation}} + } + {{/operations}} } diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/PetApi.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/PetApi.cs index ab213f94f5a..82f7d1a8fa0 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/PetApi.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/PetApi.cs @@ -7,825 +7,792 @@ using IO.Swagger.Client; using IO.Swagger.Model; namespace IO.Swagger.Api { + + public interface IPetApi { + + /// + /// Update an existing pet + /// + /// Pet object that needs to be added to the store + void UpdatePet (Pet body); - public interface IPetApi { - - /// - /// Update an existing pet - /// - /// Pet object that needs to be added to the store - - void UpdatePet (Pet body); - - /// - /// Update an existing pet - /// - /// Pet object that needs to be added to the store - - Task UpdatePetAsync (Pet body); - - /// - /// Add a new pet to the store - /// - /// Pet object that needs to be added to the store - - void AddPet (Pet body); - - /// - /// Add a new pet to the store - /// - /// Pet object that needs to be added to the store - - Task AddPetAsync (Pet body); - - /// - /// Finds Pets by status Multiple status values can be provided with comma seperated strings - /// - /// Status values that need to be considered for filter - /// List - List FindPetsByStatus (List status); - - /// - /// Finds Pets by status Multiple status values can be provided with comma seperated strings - /// - /// Status values that need to be considered for filter - /// List - Task> FindPetsByStatusAsync (List status); - - /// - /// Finds Pets by tags Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. - /// - /// Tags to filter by - /// List - List FindPetsByTags (List tags); - - /// - /// Finds Pets by tags Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. - /// - /// Tags to filter by - /// List - Task> FindPetsByTagsAsync (List tags); - - /// - /// Find pet by ID Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions - /// - /// ID of pet that needs to be fetched - /// Pet - Pet GetPetById (long? petId); - - /// - /// Find pet by ID Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions - /// - /// ID of pet that needs to be fetched - /// Pet - Task GetPetByIdAsync (long? petId); - - /// - /// Updates a pet in the store with form data - /// - /// ID of pet that needs to be updated - /// Updated name of the pet - /// Updated status of the pet - - void UpdatePetWithForm (string petId, string name, string status); - - /// - /// Updates a pet in the store with form data - /// - /// ID of pet that needs to be updated - /// Updated name of the pet - /// Updated status of the pet - - Task UpdatePetWithFormAsync (string petId, string name, string status); - - /// - /// Deletes a pet - /// - /// - /// Pet id to delete - - void DeletePet (string apiKey, long? petId); - - /// - /// Deletes a pet - /// - /// - /// Pet id to delete - - Task DeletePetAsync (string apiKey, long? petId); - - /// - /// uploads an image - /// - /// ID of pet to update - /// Additional data to pass to server - /// file to upload - - void UploadFile (long? petId, string additionalMetadata, Stream file); - - /// - /// uploads an image - /// - /// ID of pet to update - /// Additional data to pass to server - /// file to upload - - Task UploadFileAsync (long? petId, string additionalMetadata, Stream file); - - } - - /// - /// Represents a collection of functions to interact with the API endpoints - /// - public class PetApi : IPetApi { - - /// - /// Initializes a new instance of the class. - /// - /// an instance of ApiClient (optional) - /// - public PetApi(ApiClient apiClient = null) { - if (apiClient == null) { // use the default one in Configuration - this.ApiClient = Configuration.DefaultApiClient; - } else { - this.ApiClient = apiClient; - } - } - - /// - /// Initializes a new instance of the class. - /// - /// - public PetApi(String basePath) - { - this.ApiClient = new ApiClient(basePath); - } - - /// - /// Sets the base path of the API client. - /// - /// The base path - public void SetBasePath(String basePath) { - this.ApiClient.BasePath = basePath; - } - - /// - /// Gets the base path of the API client. - /// - /// The base path - public String GetBasePath(String basePath) { - return this.ApiClient.BasePath; - } - - /// - /// Gets or sets the API client. - /// - /// The API client - public ApiClient ApiClient {get; set;} - - - - /// - /// Update an existing pet - /// - /// Pet object that needs to be added to the store - - public void UpdatePet (Pet body) { - - - - var path = "/pet"; - path = path.Replace("{format}", "json"); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - - postBody = ApiClient.Serialize(body); // http body (model) parameter - - - // authentication setting, if any - String[] authSettings = new String[] { "petstore_auth" }; - - // make the HTTP request - IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling UpdatePet: " + response.Content, response.Content); - } - - return; - } - - /// - /// Update an existing pet - /// - /// Pet object that needs to be added to the store - - public async Task UpdatePetAsync (Pet body) { - - - - var path = "/pet"; - path = path.Replace("{format}", "json"); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - - postBody = ApiClient.Serialize(body); // http body (model) parameter - - - // authentication setting, if any - String[] authSettings = new String[] { "petstore_auth" }; - - // make the HTTP request - IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling UpdatePet: " + response.Content, response.Content); - } - - return; - } - - /// - /// Add a new pet to the store - /// - /// Pet object that needs to be added to the store - - public void AddPet (Pet body) { - - - - var path = "/pet"; - path = path.Replace("{format}", "json"); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - - postBody = ApiClient.Serialize(body); // http body (model) parameter - - - // authentication setting, if any - String[] authSettings = new String[] { "petstore_auth" }; - - // make the HTTP request - IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling AddPet: " + response.Content, response.Content); - } - - return; - } - - /// - /// Add a new pet to the store - /// - /// Pet object that needs to be added to the store - - public async Task AddPetAsync (Pet body) { - - - - var path = "/pet"; - path = path.Replace("{format}", "json"); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - - postBody = ApiClient.Serialize(body); // http body (model) parameter - - - // authentication setting, if any - String[] authSettings = new String[] { "petstore_auth" }; - - // make the HTTP request - IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling AddPet: " + response.Content, response.Content); - } - - return; - } - - /// - /// Finds Pets by status Multiple status values can be provided with comma seperated strings - /// - /// Status values that need to be considered for filter - /// List - public List FindPetsByStatus (List status) { - - - - var path = "/pet/findByStatus"; - path = path.Replace("{format}", "json"); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - if (status != null) queryParams.Add("status", ApiClient.ParameterToString(status)); // query parameter - - - - - - // authentication setting, if any - String[] authSettings = new String[] { "petstore_auth" }; - - // make the HTTP request - IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByStatus: " + response.Content, response.Content); - } - - return (List) ApiClient.Deserialize(response.Content, typeof(List), response.Headers); - } - - /// - /// Finds Pets by status Multiple status values can be provided with comma seperated strings - /// - /// Status values that need to be considered for filter - /// List - public async Task> FindPetsByStatusAsync (List status) { - - - - var path = "/pet/findByStatus"; - path = path.Replace("{format}", "json"); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - if (status != null) queryParams.Add("status", ApiClient.ParameterToString(status)); // query parameter - - - - - - // authentication setting, if any - String[] authSettings = new String[] { "petstore_auth" }; - - // make the HTTP request - IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByStatus: " + response.Content, response.Content); - } - return (List) ApiClient.Deserialize(response.Content, typeof(List), response.Headers); - } - - /// - /// Finds Pets by tags Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. - /// - /// Tags to filter by - /// List - public List FindPetsByTags (List tags) { - - - - var path = "/pet/findByTags"; - path = path.Replace("{format}", "json"); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - if (tags != null) queryParams.Add("tags", ApiClient.ParameterToString(tags)); // query parameter - - - - - - // authentication setting, if any - String[] authSettings = new String[] { "petstore_auth" }; - - // make the HTTP request - IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByTags: " + response.Content, response.Content); - } - - return (List) ApiClient.Deserialize(response.Content, typeof(List), response.Headers); - } - - /// - /// Finds Pets by tags Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. - /// - /// Tags to filter by - /// List - public async Task> FindPetsByTagsAsync (List tags) { - - - - var path = "/pet/findByTags"; - path = path.Replace("{format}", "json"); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - if (tags != null) queryParams.Add("tags", ApiClient.ParameterToString(tags)); // query parameter - - - - - - // authentication setting, if any - String[] authSettings = new String[] { "petstore_auth" }; - - // make the HTTP request - IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByTags: " + response.Content, response.Content); - } - return (List) ApiClient.Deserialize(response.Content, typeof(List), response.Headers); - } - - /// - /// Find pet by ID Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions - /// - /// ID of pet that needs to be fetched - /// Pet - public Pet GetPetById (long? petId) { - - - // verify the required parameter 'petId' is set - if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling GetPetById"); - - - var path = "/pet/{petId}"; - path = path.Replace("{format}", "json"); - path = path.Replace("{" + "petId" + "}", ApiClient.ParameterToString(petId)); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - - - - // authentication setting, if any - String[] authSettings = new String[] { "api_key", "petstore_auth" }; - - // make the HTTP request - IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling GetPetById: " + response.Content, response.Content); - } - - return (Pet) ApiClient.Deserialize(response.Content, typeof(Pet), response.Headers); - } - - /// - /// Find pet by ID Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions - /// - /// ID of pet that needs to be fetched - /// Pet - public async Task GetPetByIdAsync (long? petId) { - - - // verify the required parameter 'petId' is set - if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling GetPetById"); - - - var path = "/pet/{petId}"; - path = path.Replace("{format}", "json"); - path = path.Replace("{" + "petId" + "}", ApiClient.ParameterToString(petId)); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - - - - // authentication setting, if any - String[] authSettings = new String[] { "api_key", "petstore_auth" }; - - // make the HTTP request - IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling GetPetById: " + response.Content, response.Content); - } - return (Pet) ApiClient.Deserialize(response.Content, typeof(Pet), response.Headers); - } - - /// - /// Updates a pet in the store with form data - /// - /// ID of pet that needs to be updated - /// Updated name of the pet - /// Updated status of the pet - - public void UpdatePetWithForm (string petId, string name, string status) { - - - // verify the required parameter 'petId' is set - if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling UpdatePetWithForm"); - - - var path = "/pet/{petId}"; - path = path.Replace("{format}", "json"); - path = path.Replace("{" + "petId" + "}", ApiClient.ParameterToString(petId)); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - if (name != null) formParams.Add("name", ApiClient.ParameterToString(name)); // form parameter - if (status != null) formParams.Add("status", ApiClient.ParameterToString(status)); // form parameter - - - - // authentication setting, if any - String[] authSettings = new String[] { "petstore_auth" }; - - // make the HTTP request - IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling UpdatePetWithForm: " + response.Content, response.Content); - } - - return; - } - - /// - /// Updates a pet in the store with form data - /// - /// ID of pet that needs to be updated - /// Updated name of the pet - /// Updated status of the pet - - public async Task UpdatePetWithFormAsync (string petId, string name, string status) { - - - // verify the required parameter 'petId' is set - if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling UpdatePetWithForm"); - - - var path = "/pet/{petId}"; - path = path.Replace("{format}", "json"); - path = path.Replace("{" + "petId" + "}", ApiClient.ParameterToString(petId)); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - if (name != null) formParams.Add("name", ApiClient.ParameterToString(name)); // form parameter - if (status != null) formParams.Add("status", ApiClient.ParameterToString(status)); // form parameter - - - - // authentication setting, if any - String[] authSettings = new String[] { "petstore_auth" }; - - // make the HTTP request - IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling UpdatePetWithForm: " + response.Content, response.Content); - } - - return; - } - - /// - /// Deletes a pet - /// - /// - /// Pet id to delete - - public void DeletePet (string apiKey, long? petId) { - - - // verify the required parameter 'petId' is set - if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling DeletePet"); - - - var path = "/pet/{petId}"; - path = path.Replace("{format}", "json"); - path = path.Replace("{" + "petId" + "}", ApiClient.ParameterToString(petId)); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - if (apiKey != null) headerParams.Add("api_key", ApiClient.ParameterToString(apiKey)); // header parameter - - - - - // authentication setting, if any - String[] authSettings = new String[] { "petstore_auth" }; - - // make the HTTP request - IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling DeletePet: " + response.Content, response.Content); - } - - return; - } - - /// - /// Deletes a pet - /// - /// - /// Pet id to delete - - public async Task DeletePetAsync (string apiKey, long? petId) { - - - // verify the required parameter 'petId' is set - if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling DeletePet"); - - - var path = "/pet/{petId}"; - path = path.Replace("{format}", "json"); - path = path.Replace("{" + "petId" + "}", ApiClient.ParameterToString(petId)); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - if (apiKey != null) headerParams.Add("api_key", ApiClient.ParameterToString(apiKey)); // header parameter - - - - - // authentication setting, if any - String[] authSettings = new String[] { "petstore_auth" }; - - // make the HTTP request - IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling DeletePet: " + response.Content, response.Content); - } - - return; - } - - /// - /// uploads an image - /// - /// ID of pet to update - /// Additional data to pass to server - /// file to upload - - public void UploadFile (long? petId, string additionalMetadata, Stream file) { - - - // verify the required parameter 'petId' is set - if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling UploadFile"); - - - var path = "/pet/{petId}/uploadImage"; - path = path.Replace("{format}", "json"); - path = path.Replace("{" + "petId" + "}", ApiClient.ParameterToString(petId)); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - if (additionalMetadata != null) formParams.Add("additionalMetadata", ApiClient.ParameterToString(additionalMetadata)); // form parameter - if (file != null) fileParams.Add("file", ApiClient.ParameterToFile("file", file)); - - - - // authentication setting, if any - String[] authSettings = new String[] { "petstore_auth" }; - - // make the HTTP request - IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling UploadFile: " + response.Content, response.Content); - } - - return; - } - - /// - /// uploads an image - /// - /// ID of pet to update - /// Additional data to pass to server - /// file to upload - - public async Task UploadFileAsync (long? petId, string additionalMetadata, Stream file) { - - - // verify the required parameter 'petId' is set - if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling UploadFile"); - - - var path = "/pet/{petId}/uploadImage"; - path = path.Replace("{format}", "json"); - path = path.Replace("{" + "petId" + "}", ApiClient.ParameterToString(petId)); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - if (additionalMetadata != null) formParams.Add("additionalMetadata", ApiClient.ParameterToString(additionalMetadata)); // form parameter - if (file != null) fileParams.Add("file", ApiClient.ParameterToFile("file", file)); - - - - // authentication setting, if any - String[] authSettings = new String[] { "petstore_auth" }; - - // make the HTTP request - IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling UploadFile: " + response.Content, response.Content); - } - - return; - } - - } + /// + /// Update an existing pet + /// + /// Pet object that needs to be added to the store + Task UpdatePetAsync (Pet body); + + /// + /// Add a new pet to the store + /// + /// Pet object that needs to be added to the store + void AddPet (Pet body); + /// + /// Add a new pet to the store + /// + /// Pet object that needs to be added to the store + Task AddPetAsync (Pet body); + + /// + /// Finds Pets by status Multiple status values can be provided with comma seperated strings + /// + /// Status values that need to be considered for filter + /// List + List FindPetsByStatus (List status); + + /// + /// Finds Pets by status Multiple status values can be provided with comma seperated strings + /// + /// Status values that need to be considered for filter + /// List + Task> FindPetsByStatusAsync (List status); + + /// + /// Finds Pets by tags Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. + /// + /// Tags to filter by + /// List + List FindPetsByTags (List tags); + + /// + /// Finds Pets by tags Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. + /// + /// Tags to filter by + /// List + Task> FindPetsByTagsAsync (List tags); + + /// + /// Find pet by ID Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions + /// + /// ID of pet that needs to be fetched + /// Pet + Pet GetPetById (long? petId); + + /// + /// Find pet by ID Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions + /// + /// ID of pet that needs to be fetched + /// Pet + Task GetPetByIdAsync (long? petId); + + /// + /// Updates a pet in the store with form data + /// + /// ID of pet that needs to be updated + /// Updated name of the pet + /// Updated status of the pet + void UpdatePetWithForm (string petId, string name, string status); + + /// + /// Updates a pet in the store with form data + /// + /// ID of pet that needs to be updated + /// Updated name of the pet + /// Updated status of the pet + Task UpdatePetWithFormAsync (string petId, string name, string status); + + /// + /// Deletes a pet + /// + /// + /// Pet id to delete + void DeletePet (string apiKey, long? petId); + + /// + /// Deletes a pet + /// + /// + /// Pet id to delete + Task DeletePetAsync (string apiKey, long? petId); + + /// + /// uploads an image + /// + /// ID of pet to update + /// Additional data to pass to server + /// file to upload + void UploadFile (long? petId, string additionalMetadata, Stream file); + + /// + /// uploads an image + /// + /// ID of pet to update + /// Additional data to pass to server + /// file to upload + Task UploadFileAsync (long? petId, string additionalMetadata, Stream file); + + } + + /// + /// Represents a collection of functions to interact with the API endpoints + /// + public class PetApi : IPetApi { + + /// + /// Initializes a new instance of the class. + /// + /// an instance of ApiClient (optional) + /// + public PetApi(ApiClient apiClient = null) { + if (apiClient == null) { // use the default one in Configuration + this.ApiClient = Configuration.DefaultApiClient; + } else { + this.ApiClient = apiClient; + } + } + + /// + /// Initializes a new instance of the class. + /// + /// + public PetApi(String basePath) + { + this.ApiClient = new ApiClient(basePath); + } + + /// + /// Sets the base path of the API client. + /// + /// The base path + public void SetBasePath(String basePath) { + this.ApiClient.BasePath = basePath; + } + + /// + /// Gets the base path of the API client. + /// + /// The base path + public String GetBasePath(String basePath) { + return this.ApiClient.BasePath; + } + + /// + /// Gets or sets the API client. + /// + /// The API client + public ApiClient ApiClient {get; set;} + + + /// + /// Update an existing pet + /// + /// Pet object that needs to be added to the store + public void UpdatePet (Pet body) { + + + + var path = "/pet"; + path = path.Replace("{format}", "json"); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + + postBody = ApiClient.Serialize(body); // http body (model) parameter + + + // authentication setting, if any + String[] authSettings = new String[] { "petstore_auth" }; + + // make the HTTP request + IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling UpdatePet: " + response.Content, response.Content); + } + + return; + } + + /// + /// Update an existing pet + /// + /// Pet object that needs to be added to the store + public async Task UpdatePetAsync (Pet body) { + + + var path = "/pet"; + path = path.Replace("{format}", "json"); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + + postBody = ApiClient.Serialize(body); // http body (model) parameter + + + // authentication setting, if any + String[] authSettings = new String[] { "petstore_auth" }; + + // make the HTTP request + IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling UpdatePet: " + response.Content, response.Content); + } + + return; + } + + /// + /// Add a new pet to the store + /// + /// Pet object that needs to be added to the store + public void AddPet (Pet body) { + + + + var path = "/pet"; + path = path.Replace("{format}", "json"); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + + postBody = ApiClient.Serialize(body); // http body (model) parameter + + + // authentication setting, if any + String[] authSettings = new String[] { "petstore_auth" }; + + // make the HTTP request + IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling AddPet: " + response.Content, response.Content); + } + + return; + } + + /// + /// Add a new pet to the store + /// + /// Pet object that needs to be added to the store + public async Task AddPetAsync (Pet body) { + + + var path = "/pet"; + path = path.Replace("{format}", "json"); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + + postBody = ApiClient.Serialize(body); // http body (model) parameter + + + // authentication setting, if any + String[] authSettings = new String[] { "petstore_auth" }; + + // make the HTTP request + IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling AddPet: " + response.Content, response.Content); + } + + return; + } + + /// + /// Finds Pets by status Multiple status values can be provided with comma seperated strings + /// + /// Status values that need to be considered for filter + /// List + public List FindPetsByStatus (List status) { + + + + var path = "/pet/findByStatus"; + path = path.Replace("{format}", "json"); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + if (status != null) queryParams.Add("status", ApiClient.ParameterToString(status)); // query parameter + + + + + + // authentication setting, if any + String[] authSettings = new String[] { "petstore_auth" }; + + // make the HTTP request + IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByStatus: " + response.Content, response.Content); + } + + return (List) ApiClient.Deserialize(response.Content, typeof(List), response.Headers); + } + + /// + /// Finds Pets by status Multiple status values can be provided with comma seperated strings + /// + /// Status values that need to be considered for filter + /// List + public async Task> FindPetsByStatusAsync (List status) { + + + var path = "/pet/findByStatus"; + path = path.Replace("{format}", "json"); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + if (status != null) queryParams.Add("status", ApiClient.ParameterToString(status)); // query parameter + + + + + + // authentication setting, if any + String[] authSettings = new String[] { "petstore_auth" }; + + // make the HTTP request + IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByStatus: " + response.Content, response.Content); + } + return (List) ApiClient.Deserialize(response.Content, typeof(List), response.Headers); + } + + /// + /// Finds Pets by tags Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. + /// + /// Tags to filter by + /// List + public List FindPetsByTags (List tags) { + + + + var path = "/pet/findByTags"; + path = path.Replace("{format}", "json"); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + if (tags != null) queryParams.Add("tags", ApiClient.ParameterToString(tags)); // query parameter + + + + + + // authentication setting, if any + String[] authSettings = new String[] { "petstore_auth" }; + + // make the HTTP request + IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByTags: " + response.Content, response.Content); + } + + return (List) ApiClient.Deserialize(response.Content, typeof(List), response.Headers); + } + + /// + /// Finds Pets by tags Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. + /// + /// Tags to filter by + /// List + public async Task> FindPetsByTagsAsync (List tags) { + + + var path = "/pet/findByTags"; + path = path.Replace("{format}", "json"); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + if (tags != null) queryParams.Add("tags", ApiClient.ParameterToString(tags)); // query parameter + + + + + + // authentication setting, if any + String[] authSettings = new String[] { "petstore_auth" }; + + // make the HTTP request + IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByTags: " + response.Content, response.Content); + } + return (List) ApiClient.Deserialize(response.Content, typeof(List), response.Headers); + } + + /// + /// Find pet by ID Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions + /// + /// ID of pet that needs to be fetched + /// Pet + public Pet GetPetById (long? petId) { + + + // verify the required parameter 'petId' is set + if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling GetPetById"); + + + var path = "/pet/{petId}"; + path = path.Replace("{format}", "json"); + path = path.Replace("{" + "petId" + "}", ApiClient.ParameterToString(petId)); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + + + + // authentication setting, if any + String[] authSettings = new String[] { "api_key", "petstore_auth" }; + + // make the HTTP request + IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling GetPetById: " + response.Content, response.Content); + } + + return (Pet) ApiClient.Deserialize(response.Content, typeof(Pet), response.Headers); + } + + /// + /// Find pet by ID Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions + /// + /// ID of pet that needs to be fetched + /// Pet + public async Task GetPetByIdAsync (long? petId) { + // verify the required parameter 'petId' is set + if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling GetPetById"); + + + var path = "/pet/{petId}"; + path = path.Replace("{format}", "json"); + path = path.Replace("{" + "petId" + "}", ApiClient.ParameterToString(petId)); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + + + + // authentication setting, if any + String[] authSettings = new String[] { "api_key", "petstore_auth" }; + + // make the HTTP request + IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling GetPetById: " + response.Content, response.Content); + } + return (Pet) ApiClient.Deserialize(response.Content, typeof(Pet), response.Headers); + } + + /// + /// Updates a pet in the store with form data + /// + /// ID of pet that needs to be updated + /// Updated name of the pet + /// Updated status of the pet + public void UpdatePetWithForm (string petId, string name, string status) { + + + // verify the required parameter 'petId' is set + if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling UpdatePetWithForm"); + + + var path = "/pet/{petId}"; + path = path.Replace("{format}", "json"); + path = path.Replace("{" + "petId" + "}", ApiClient.ParameterToString(petId)); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + if (name != null) formParams.Add("name", ApiClient.ParameterToString(name)); // form parameter + if (status != null) formParams.Add("status", ApiClient.ParameterToString(status)); // form parameter + + + + // authentication setting, if any + String[] authSettings = new String[] { "petstore_auth" }; + + // make the HTTP request + IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling UpdatePetWithForm: " + response.Content, response.Content); + } + + return; + } + + /// + /// Updates a pet in the store with form data + /// + /// ID of pet that needs to be updated + /// Updated name of the pet + /// Updated status of the pet + public async Task UpdatePetWithFormAsync (string petId, string name, string status) { + // verify the required parameter 'petId' is set + if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling UpdatePetWithForm"); + + + var path = "/pet/{petId}"; + path = path.Replace("{format}", "json"); + path = path.Replace("{" + "petId" + "}", ApiClient.ParameterToString(petId)); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + if (name != null) formParams.Add("name", ApiClient.ParameterToString(name)); // form parameter + if (status != null) formParams.Add("status", ApiClient.ParameterToString(status)); // form parameter + + + + // authentication setting, if any + String[] authSettings = new String[] { "petstore_auth" }; + + // make the HTTP request + IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling UpdatePetWithForm: " + response.Content, response.Content); + } + + return; + } + + /// + /// Deletes a pet + /// + /// + /// Pet id to delete + public void DeletePet (string apiKey, long? petId) { + + + // verify the required parameter 'petId' is set + if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling DeletePet"); + + + var path = "/pet/{petId}"; + path = path.Replace("{format}", "json"); + path = path.Replace("{" + "petId" + "}", ApiClient.ParameterToString(petId)); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + if (apiKey != null) headerParams.Add("api_key", ApiClient.ParameterToString(apiKey)); // header parameter + + + + + // authentication setting, if any + String[] authSettings = new String[] { "petstore_auth" }; + + // make the HTTP request + IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling DeletePet: " + response.Content, response.Content); + } + + return; + } + + /// + /// Deletes a pet + /// + /// + /// Pet id to delete + public async Task DeletePetAsync (string apiKey, long? petId) { + // verify the required parameter 'petId' is set + if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling DeletePet"); + + + var path = "/pet/{petId}"; + path = path.Replace("{format}", "json"); + path = path.Replace("{" + "petId" + "}", ApiClient.ParameterToString(petId)); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + if (apiKey != null) headerParams.Add("api_key", ApiClient.ParameterToString(apiKey)); // header parameter + + + + + // authentication setting, if any + String[] authSettings = new String[] { "petstore_auth" }; + + // make the HTTP request + IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling DeletePet: " + response.Content, response.Content); + } + + return; + } + + /// + /// uploads an image + /// + /// ID of pet to update + /// Additional data to pass to server + /// file to upload + public void UploadFile (long? petId, string additionalMetadata, Stream file) { + + + // verify the required parameter 'petId' is set + if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling UploadFile"); + + + var path = "/pet/{petId}/uploadImage"; + path = path.Replace("{format}", "json"); + path = path.Replace("{" + "petId" + "}", ApiClient.ParameterToString(petId)); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + if (additionalMetadata != null) formParams.Add("additionalMetadata", ApiClient.ParameterToString(additionalMetadata)); // form parameter + if (file != null) fileParams.Add("file", ApiClient.ParameterToFile("file", file)); + + + + // authentication setting, if any + String[] authSettings = new String[] { "petstore_auth" }; + + // make the HTTP request + IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling UploadFile: " + response.Content, response.Content); + } + + return; + } + + /// + /// uploads an image + /// + /// ID of pet to update + /// Additional data to pass to server + /// file to upload + public async Task UploadFileAsync (long? petId, string additionalMetadata, Stream file) { + // verify the required parameter 'petId' is set + if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling UploadFile"); + + + var path = "/pet/{petId}/uploadImage"; + path = path.Replace("{format}", "json"); + path = path.Replace("{" + "petId" + "}", ApiClient.ParameterToString(petId)); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + if (additionalMetadata != null) formParams.Add("additionalMetadata", ApiClient.ParameterToString(additionalMetadata)); // form parameter + if (file != null) fileParams.Add("file", ApiClient.ParameterToFile("file", file)); + + + + // authentication setting, if any + String[] authSettings = new String[] { "petstore_auth" }; + + // make the HTTP request + IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling UploadFile: " + response.Content, response.Content); + } + + return; + } + + } + } diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/StoreApi.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/StoreApi.cs index ad9e296721c..97dedb9a1dd 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/StoreApi.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/StoreApi.cs @@ -7,421 +7,410 @@ using IO.Swagger.Client; using IO.Swagger.Model; namespace IO.Swagger.Api { + + public interface IStoreApi { + + /// + /// Returns pet inventories by status Returns a map of status codes to quantities + /// + /// Dictionary + Dictionary GetInventory (); - public interface IStoreApi { - - /// - /// Returns pet inventories by status Returns a map of status codes to quantities - /// - /// Dictionary - Dictionary GetInventory (); - - /// - /// Returns pet inventories by status Returns a map of status codes to quantities - /// - /// Dictionary - Task> GetInventoryAsync (); - - /// - /// Place an order for a pet - /// - /// order placed for purchasing the pet - /// Order - Order PlaceOrder (Order body); - - /// - /// Place an order for a pet - /// - /// order placed for purchasing the pet - /// Order - Task PlaceOrderAsync (Order body); - - /// - /// Find purchase order by ID For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions - /// - /// ID of pet that needs to be fetched - /// Order - Order GetOrderById (string orderId); - - /// - /// Find purchase order by ID For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions - /// - /// ID of pet that needs to be fetched - /// Order - Task GetOrderByIdAsync (string orderId); - - /// - /// Delete purchase order by ID For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors - /// - /// ID of the order that needs to be deleted - - void DeleteOrder (string orderId); - - /// - /// Delete purchase order by ID For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors - /// - /// ID of the order that needs to be deleted - - Task DeleteOrderAsync (string orderId); - - } - - /// - /// Represents a collection of functions to interact with the API endpoints - /// - public class StoreApi : IStoreApi { - - /// - /// Initializes a new instance of the class. - /// - /// an instance of ApiClient (optional) - /// - public StoreApi(ApiClient apiClient = null) { - if (apiClient == null) { // use the default one in Configuration - this.ApiClient = Configuration.DefaultApiClient; - } else { - this.ApiClient = apiClient; - } - } - - /// - /// Initializes a new instance of the class. - /// - /// - public StoreApi(String basePath) - { - this.ApiClient = new ApiClient(basePath); - } - - /// - /// Sets the base path of the API client. - /// - /// The base path - public void SetBasePath(String basePath) { - this.ApiClient.BasePath = basePath; - } - - /// - /// Gets the base path of the API client. - /// - /// The base path - public String GetBasePath(String basePath) { - return this.ApiClient.BasePath; - } - - /// - /// Gets or sets the API client. - /// - /// The API client - public ApiClient ApiClient {get; set;} - - - - /// - /// Returns pet inventories by status Returns a map of status codes to quantities - /// - /// Dictionary - public Dictionary GetInventory () { - - - - var path = "/store/inventory"; - path = path.Replace("{format}", "json"); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - - - - // authentication setting, if any - String[] authSettings = new String[] { "api_key" }; - - // make the HTTP request - IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling GetInventory: " + response.Content, response.Content); - } - - return (Dictionary) ApiClient.Deserialize(response.Content, typeof(Dictionary), response.Headers); - } - - /// - /// Returns pet inventories by status Returns a map of status codes to quantities - /// - /// Dictionary - public async Task> GetInventoryAsync () { - - - - var path = "/store/inventory"; - path = path.Replace("{format}", "json"); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - - - - // authentication setting, if any - String[] authSettings = new String[] { "api_key" }; - - // make the HTTP request - IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling GetInventory: " + response.Content, response.Content); - } - return (Dictionary) ApiClient.Deserialize(response.Content, typeof(Dictionary), response.Headers); - } - - /// - /// Place an order for a pet - /// - /// order placed for purchasing the pet - /// Order - public Order PlaceOrder (Order body) { - - - - var path = "/store/order"; - path = path.Replace("{format}", "json"); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - - postBody = ApiClient.Serialize(body); // http body (model) parameter - - - // authentication setting, if any - String[] authSettings = new String[] { }; - - // make the HTTP request - IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling PlaceOrder: " + response.Content, response.Content); - } - - return (Order) ApiClient.Deserialize(response.Content, typeof(Order), response.Headers); - } - - /// - /// Place an order for a pet - /// - /// order placed for purchasing the pet - /// Order - public async Task PlaceOrderAsync (Order body) { - - - - var path = "/store/order"; - path = path.Replace("{format}", "json"); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - - postBody = ApiClient.Serialize(body); // http body (model) parameter - - - // authentication setting, if any - String[] authSettings = new String[] { }; - - // make the HTTP request - IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling PlaceOrder: " + response.Content, response.Content); - } - return (Order) ApiClient.Deserialize(response.Content, typeof(Order), response.Headers); - } - - /// - /// Find purchase order by ID For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions - /// - /// ID of pet that needs to be fetched - /// Order - public Order GetOrderById (string orderId) { - - - // verify the required parameter 'orderId' is set - if (orderId == null) throw new ApiException(400, "Missing required parameter 'orderId' when calling GetOrderById"); - - - var path = "/store/order/{orderId}"; - path = path.Replace("{format}", "json"); - path = path.Replace("{" + "orderId" + "}", ApiClient.ParameterToString(orderId)); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - - - - // authentication setting, if any - String[] authSettings = new String[] { }; - - // make the HTTP request - IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling GetOrderById: " + response.Content, response.Content); - } - - return (Order) ApiClient.Deserialize(response.Content, typeof(Order), response.Headers); - } - - /// - /// Find purchase order by ID For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions - /// - /// ID of pet that needs to be fetched - /// Order - public async Task GetOrderByIdAsync (string orderId) { - - - // verify the required parameter 'orderId' is set - if (orderId == null) throw new ApiException(400, "Missing required parameter 'orderId' when calling GetOrderById"); - - - var path = "/store/order/{orderId}"; - path = path.Replace("{format}", "json"); - path = path.Replace("{" + "orderId" + "}", ApiClient.ParameterToString(orderId)); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - - - - // authentication setting, if any - String[] authSettings = new String[] { }; - - // make the HTTP request - IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling GetOrderById: " + response.Content, response.Content); - } - return (Order) ApiClient.Deserialize(response.Content, typeof(Order), response.Headers); - } - - /// - /// Delete purchase order by ID For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors - /// - /// ID of the order that needs to be deleted - - public void DeleteOrder (string orderId) { - - - // verify the required parameter 'orderId' is set - if (orderId == null) throw new ApiException(400, "Missing required parameter 'orderId' when calling DeleteOrder"); - - - var path = "/store/order/{orderId}"; - path = path.Replace("{format}", "json"); - path = path.Replace("{" + "orderId" + "}", ApiClient.ParameterToString(orderId)); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - - - - // authentication setting, if any - String[] authSettings = new String[] { }; - - // make the HTTP request - IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling DeleteOrder: " + response.Content, response.Content); - } - - return; - } - - /// - /// Delete purchase order by ID For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors - /// - /// ID of the order that needs to be deleted - - public async Task DeleteOrderAsync (string orderId) { - - - // verify the required parameter 'orderId' is set - if (orderId == null) throw new ApiException(400, "Missing required parameter 'orderId' when calling DeleteOrder"); - - - var path = "/store/order/{orderId}"; - path = path.Replace("{format}", "json"); - path = path.Replace("{" + "orderId" + "}", ApiClient.ParameterToString(orderId)); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - - - - // authentication setting, if any - String[] authSettings = new String[] { }; - - // make the HTTP request - IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling DeleteOrder: " + response.Content, response.Content); - } - - return; - } - - } + /// + /// Returns pet inventories by status Returns a map of status codes to quantities + /// + /// Dictionary + Task> GetInventoryAsync (); + + /// + /// Place an order for a pet + /// + /// order placed for purchasing the pet + /// Order + Order PlaceOrder (Order body); + /// + /// Place an order for a pet + /// + /// order placed for purchasing the pet + /// Order + Task PlaceOrderAsync (Order body); + + /// + /// Find purchase order by ID For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + /// + /// ID of pet that needs to be fetched + /// Order + Order GetOrderById (string orderId); + + /// + /// Find purchase order by ID For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + /// + /// ID of pet that needs to be fetched + /// Order + Task GetOrderByIdAsync (string orderId); + + /// + /// Delete purchase order by ID For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + /// + /// ID of the order that needs to be deleted + void DeleteOrder (string orderId); + + /// + /// Delete purchase order by ID For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + /// + /// ID of the order that needs to be deleted + Task DeleteOrderAsync (string orderId); + + } + + /// + /// Represents a collection of functions to interact with the API endpoints + /// + public class StoreApi : IStoreApi { + + /// + /// Initializes a new instance of the class. + /// + /// an instance of ApiClient (optional) + /// + public StoreApi(ApiClient apiClient = null) { + if (apiClient == null) { // use the default one in Configuration + this.ApiClient = Configuration.DefaultApiClient; + } else { + this.ApiClient = apiClient; + } + } + + /// + /// Initializes a new instance of the class. + /// + /// + public StoreApi(String basePath) + { + this.ApiClient = new ApiClient(basePath); + } + + /// + /// Sets the base path of the API client. + /// + /// The base path + public void SetBasePath(String basePath) { + this.ApiClient.BasePath = basePath; + } + + /// + /// Gets the base path of the API client. + /// + /// The base path + public String GetBasePath(String basePath) { + return this.ApiClient.BasePath; + } + + /// + /// Gets or sets the API client. + /// + /// The API client + public ApiClient ApiClient {get; set;} + + + /// + /// Returns pet inventories by status Returns a map of status codes to quantities + /// + /// Dictionary + public Dictionary GetInventory () { + + + + var path = "/store/inventory"; + path = path.Replace("{format}", "json"); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + + + + // authentication setting, if any + String[] authSettings = new String[] { "api_key" }; + + // make the HTTP request + IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling GetInventory: " + response.Content, response.Content); + } + + return (Dictionary) ApiClient.Deserialize(response.Content, typeof(Dictionary), response.Headers); + } + + /// + /// Returns pet inventories by status Returns a map of status codes to quantities + /// + /// Dictionary + public async Task> GetInventoryAsync () { + + + var path = "/store/inventory"; + path = path.Replace("{format}", "json"); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + + + + // authentication setting, if any + String[] authSettings = new String[] { "api_key" }; + + // make the HTTP request + IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling GetInventory: " + response.Content, response.Content); + } + return (Dictionary) ApiClient.Deserialize(response.Content, typeof(Dictionary), response.Headers); + } + + /// + /// Place an order for a pet + /// + /// order placed for purchasing the pet + /// Order + public Order PlaceOrder (Order body) { + + + + var path = "/store/order"; + path = path.Replace("{format}", "json"); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + + postBody = ApiClient.Serialize(body); // http body (model) parameter + + + // authentication setting, if any + String[] authSettings = new String[] { }; + + // make the HTTP request + IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling PlaceOrder: " + response.Content, response.Content); + } + + return (Order) ApiClient.Deserialize(response.Content, typeof(Order), response.Headers); + } + + /// + /// Place an order for a pet + /// + /// order placed for purchasing the pet + /// Order + public async Task PlaceOrderAsync (Order body) { + + + var path = "/store/order"; + path = path.Replace("{format}", "json"); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + + postBody = ApiClient.Serialize(body); // http body (model) parameter + + + // authentication setting, if any + String[] authSettings = new String[] { }; + + // make the HTTP request + IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling PlaceOrder: " + response.Content, response.Content); + } + return (Order) ApiClient.Deserialize(response.Content, typeof(Order), response.Headers); + } + + /// + /// Find purchase order by ID For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + /// + /// ID of pet that needs to be fetched + /// Order + public Order GetOrderById (string orderId) { + + + // verify the required parameter 'orderId' is set + if (orderId == null) throw new ApiException(400, "Missing required parameter 'orderId' when calling GetOrderById"); + + + var path = "/store/order/{orderId}"; + path = path.Replace("{format}", "json"); + path = path.Replace("{" + "orderId" + "}", ApiClient.ParameterToString(orderId)); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + + + + // authentication setting, if any + String[] authSettings = new String[] { }; + + // make the HTTP request + IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling GetOrderById: " + response.Content, response.Content); + } + + return (Order) ApiClient.Deserialize(response.Content, typeof(Order), response.Headers); + } + + /// + /// Find purchase order by ID For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + /// + /// ID of pet that needs to be fetched + /// Order + public async Task GetOrderByIdAsync (string orderId) { + // verify the required parameter 'orderId' is set + if (orderId == null) throw new ApiException(400, "Missing required parameter 'orderId' when calling GetOrderById"); + + + var path = "/store/order/{orderId}"; + path = path.Replace("{format}", "json"); + path = path.Replace("{" + "orderId" + "}", ApiClient.ParameterToString(orderId)); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + + + + // authentication setting, if any + String[] authSettings = new String[] { }; + + // make the HTTP request + IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling GetOrderById: " + response.Content, response.Content); + } + return (Order) ApiClient.Deserialize(response.Content, typeof(Order), response.Headers); + } + + /// + /// Delete purchase order by ID For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + /// + /// ID of the order that needs to be deleted + public void DeleteOrder (string orderId) { + + + // verify the required parameter 'orderId' is set + if (orderId == null) throw new ApiException(400, "Missing required parameter 'orderId' when calling DeleteOrder"); + + + var path = "/store/order/{orderId}"; + path = path.Replace("{format}", "json"); + path = path.Replace("{" + "orderId" + "}", ApiClient.ParameterToString(orderId)); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + + + + // authentication setting, if any + String[] authSettings = new String[] { }; + + // make the HTTP request + IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling DeleteOrder: " + response.Content, response.Content); + } + + return; + } + + /// + /// Delete purchase order by ID For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + /// + /// ID of the order that needs to be deleted + public async Task DeleteOrderAsync (string orderId) { + // verify the required parameter 'orderId' is set + if (orderId == null) throw new ApiException(400, "Missing required parameter 'orderId' when calling DeleteOrder"); + + + var path = "/store/order/{orderId}"; + path = path.Replace("{format}", "json"); + path = path.Replace("{" + "orderId" + "}", ApiClient.ParameterToString(orderId)); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + + + + // authentication setting, if any + String[] authSettings = new String[] { }; + + // make the HTTP request + IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling DeleteOrder: " + response.Content, response.Content); + } + + return; + } + + } + } diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/UserApi.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/UserApi.cs index 92b35a640e6..f497b9d35a2 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/UserApi.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/UserApi.cs @@ -7,796 +7,760 @@ using IO.Swagger.Client; using IO.Swagger.Model; namespace IO.Swagger.Api { + + public interface IUserApi { + + /// + /// Create user This can only be done by the logged in user. + /// + /// Created user object + void CreateUser (User body); - public interface IUserApi { - - /// - /// Create user This can only be done by the logged in user. - /// - /// Created user object - - void CreateUser (User body); - - /// - /// Create user This can only be done by the logged in user. - /// - /// Created user object - - Task CreateUserAsync (User body); - - /// - /// Creates list of users with given input array - /// - /// List of user object - - void CreateUsersWithArrayInput (List body); - - /// - /// Creates list of users with given input array - /// - /// List of user object - - Task CreateUsersWithArrayInputAsync (List body); - - /// - /// Creates list of users with given input array - /// - /// List of user object - - void CreateUsersWithListInput (List body); - - /// - /// Creates list of users with given input array - /// - /// List of user object - - Task CreateUsersWithListInputAsync (List body); - - /// - /// Logs user into the system - /// - /// The user name for login - /// The password for login in clear text - /// string - string LoginUser (string username, string password); - - /// - /// Logs user into the system - /// - /// The user name for login - /// The password for login in clear text - /// string - Task LoginUserAsync (string username, string password); - - /// - /// Logs out current logged in user session - /// - - void LogoutUser (); - - /// - /// Logs out current logged in user session - /// - - Task LogoutUserAsync (); - - /// - /// Get user by user name - /// - /// The name that needs to be fetched. Use user1 for testing. - /// User - User GetUserByName (string username); - - /// - /// Get user by user name - /// - /// The name that needs to be fetched. Use user1 for testing. - /// User - Task GetUserByNameAsync (string username); - - /// - /// Updated user This can only be done by the logged in user. - /// - /// name that need to be deleted - /// Updated user object - - void UpdateUser (string username, User body); - - /// - /// Updated user This can only be done by the logged in user. - /// - /// name that need to be deleted - /// Updated user object - - Task UpdateUserAsync (string username, User body); - - /// - /// Delete user This can only be done by the logged in user. - /// - /// The name that needs to be deleted - - void DeleteUser (string username); - - /// - /// Delete user This can only be done by the logged in user. - /// - /// The name that needs to be deleted - - Task DeleteUserAsync (string username); - - } - - /// - /// Represents a collection of functions to interact with the API endpoints - /// - public class UserApi : IUserApi { - - /// - /// Initializes a new instance of the class. - /// - /// an instance of ApiClient (optional) - /// - public UserApi(ApiClient apiClient = null) { - if (apiClient == null) { // use the default one in Configuration - this.ApiClient = Configuration.DefaultApiClient; - } else { - this.ApiClient = apiClient; - } - } - - /// - /// Initializes a new instance of the class. - /// - /// - public UserApi(String basePath) - { - this.ApiClient = new ApiClient(basePath); - } - - /// - /// Sets the base path of the API client. - /// - /// The base path - public void SetBasePath(String basePath) { - this.ApiClient.BasePath = basePath; - } - - /// - /// Gets the base path of the API client. - /// - /// The base path - public String GetBasePath(String basePath) { - return this.ApiClient.BasePath; - } - - /// - /// Gets or sets the API client. - /// - /// The API client - public ApiClient ApiClient {get; set;} - - - - /// - /// Create user This can only be done by the logged in user. - /// - /// Created user object - - public void CreateUser (User body) { - - - - var path = "/user"; - path = path.Replace("{format}", "json"); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - - postBody = ApiClient.Serialize(body); // http body (model) parameter - - - // authentication setting, if any - String[] authSettings = new String[] { }; - - // make the HTTP request - IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling CreateUser: " + response.Content, response.Content); - } - - return; - } - - /// - /// Create user This can only be done by the logged in user. - /// - /// Created user object - - public async Task CreateUserAsync (User body) { - - - - var path = "/user"; - path = path.Replace("{format}", "json"); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - - postBody = ApiClient.Serialize(body); // http body (model) parameter - - - // authentication setting, if any - String[] authSettings = new String[] { }; - - // make the HTTP request - IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling CreateUser: " + response.Content, response.Content); - } - - return; - } - - /// - /// Creates list of users with given input array - /// - /// List of user object - - public void CreateUsersWithArrayInput (List body) { - - - - var path = "/user/createWithArray"; - path = path.Replace("{format}", "json"); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - - postBody = ApiClient.Serialize(body); // http body (model) parameter - - - // authentication setting, if any - String[] authSettings = new String[] { }; - - // make the HTTP request - IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithArrayInput: " + response.Content, response.Content); - } - - return; - } - - /// - /// Creates list of users with given input array - /// - /// List of user object - - public async Task CreateUsersWithArrayInputAsync (List body) { - - - - var path = "/user/createWithArray"; - path = path.Replace("{format}", "json"); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - - postBody = ApiClient.Serialize(body); // http body (model) parameter - - - // authentication setting, if any - String[] authSettings = new String[] { }; - - // make the HTTP request - IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithArrayInput: " + response.Content, response.Content); - } - - return; - } - - /// - /// Creates list of users with given input array - /// - /// List of user object - - public void CreateUsersWithListInput (List body) { - - - - var path = "/user/createWithList"; - path = path.Replace("{format}", "json"); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - - postBody = ApiClient.Serialize(body); // http body (model) parameter - - - // authentication setting, if any - String[] authSettings = new String[] { }; - - // make the HTTP request - IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithListInput: " + response.Content, response.Content); - } - - return; - } - - /// - /// Creates list of users with given input array - /// - /// List of user object - - public async Task CreateUsersWithListInputAsync (List body) { - - - - var path = "/user/createWithList"; - path = path.Replace("{format}", "json"); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - - postBody = ApiClient.Serialize(body); // http body (model) parameter - - - // authentication setting, if any - String[] authSettings = new String[] { }; - - // make the HTTP request - IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithListInput: " + response.Content, response.Content); - } - - return; - } - - /// - /// Logs user into the system - /// - /// The user name for login - /// The password for login in clear text - /// string - public string LoginUser (string username, string password) { - - - - var path = "/user/login"; - path = path.Replace("{format}", "json"); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - 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 - - - - - - // authentication setting, if any - String[] authSettings = new String[] { }; - - // make the HTTP request - IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling LoginUser: " + response.Content, response.Content); - } - - return (string) ApiClient.Deserialize(response.Content, typeof(string), response.Headers); - } - - /// - /// Logs user into the system - /// - /// The user name for login - /// The password for login in clear text - /// string - public async Task LoginUserAsync (string username, string password) { - - - - var path = "/user/login"; - path = path.Replace("{format}", "json"); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - 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 - - - - - - // authentication setting, if any - String[] authSettings = new String[] { }; - - // make the HTTP request - IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling LoginUser: " + response.Content, response.Content); - } - return (string) ApiClient.Deserialize(response.Content, typeof(string), response.Headers); - } - - /// - /// Logs out current logged in user session - /// - - public void LogoutUser () { - - - - var path = "/user/logout"; - path = path.Replace("{format}", "json"); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - - - - // authentication setting, if any - String[] authSettings = new String[] { }; - - // make the HTTP request - IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling LogoutUser: " + response.Content, response.Content); - } - - return; - } - - /// - /// Logs out current logged in user session - /// - - public async Task LogoutUserAsync () { - - - - var path = "/user/logout"; - path = path.Replace("{format}", "json"); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - - - - // authentication setting, if any - String[] authSettings = new String[] { }; - - // make the HTTP request - IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling LogoutUser: " + response.Content, response.Content); - } - - return; - } - - /// - /// Get user by user name - /// - /// The name that needs to be fetched. Use user1 for testing. - /// User - public User GetUserByName (string username) { - - - // verify the required parameter 'username' is set - if (username == null) throw new ApiException(400, "Missing required parameter 'username' when calling GetUserByName"); - - - var path = "/user/{username}"; - path = path.Replace("{format}", "json"); - path = path.Replace("{" + "username" + "}", ApiClient.ParameterToString(username)); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - - - - // authentication setting, if any - String[] authSettings = new String[] { }; - - // make the HTTP request - IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling GetUserByName: " + response.Content, response.Content); - } - - return (User) ApiClient.Deserialize(response.Content, typeof(User), response.Headers); - } - - /// - /// Get user by user name - /// - /// The name that needs to be fetched. Use user1 for testing. - /// User - public async Task GetUserByNameAsync (string username) { - - - // verify the required parameter 'username' is set - if (username == null) throw new ApiException(400, "Missing required parameter 'username' when calling GetUserByName"); - - - var path = "/user/{username}"; - path = path.Replace("{format}", "json"); - path = path.Replace("{" + "username" + "}", ApiClient.ParameterToString(username)); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - - - - // authentication setting, if any - String[] authSettings = new String[] { }; - - // make the HTTP request - IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling GetUserByName: " + response.Content, response.Content); - } - return (User) ApiClient.Deserialize(response.Content, typeof(User), response.Headers); - } - - /// - /// Updated user This can only be done by the logged in user. - /// - /// name that need to be deleted - /// Updated user object - - public void UpdateUser (string username, User body) { - - - // verify the required parameter 'username' is set - if (username == null) throw new ApiException(400, "Missing required parameter 'username' when calling UpdateUser"); - - - var path = "/user/{username}"; - path = path.Replace("{format}", "json"); - path = path.Replace("{" + "username" + "}", ApiClient.ParameterToString(username)); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - - postBody = ApiClient.Serialize(body); // http body (model) parameter - - - // authentication setting, if any - String[] authSettings = new String[] { }; - - // make the HTTP request - IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling UpdateUser: " + response.Content, response.Content); - } - - return; - } - - /// - /// Updated user This can only be done by the logged in user. - /// - /// name that need to be deleted - /// Updated user object - - public async Task UpdateUserAsync (string username, User body) { - - - // verify the required parameter 'username' is set - if (username == null) throw new ApiException(400, "Missing required parameter 'username' when calling UpdateUser"); - - - var path = "/user/{username}"; - path = path.Replace("{format}", "json"); - path = path.Replace("{" + "username" + "}", ApiClient.ParameterToString(username)); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - - postBody = ApiClient.Serialize(body); // http body (model) parameter - - - // authentication setting, if any - String[] authSettings = new String[] { }; - - // make the HTTP request - IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling UpdateUser: " + response.Content, response.Content); - } - - return; - } - - /// - /// Delete user This can only be done by the logged in user. - /// - /// The name that needs to be deleted - - public void DeleteUser (string username) { - - - // verify the required parameter 'username' is set - if (username == null) throw new ApiException(400, "Missing required parameter 'username' when calling DeleteUser"); - - - var path = "/user/{username}"; - path = path.Replace("{format}", "json"); - path = path.Replace("{" + "username" + "}", ApiClient.ParameterToString(username)); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - - - - // authentication setting, if any - String[] authSettings = new String[] { }; - - // make the HTTP request - IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling DeleteUser: " + response.Content, response.Content); - } - - return; - } - - /// - /// Delete user This can only be done by the logged in user. - /// - /// The name that needs to be deleted - - public async Task DeleteUserAsync (string username) { - - - // verify the required parameter 'username' is set - if (username == null) throw new ApiException(400, "Missing required parameter 'username' when calling DeleteUser"); - - - var path = "/user/{username}"; - path = path.Replace("{format}", "json"); - path = path.Replace("{" + "username" + "}", ApiClient.ParameterToString(username)); - - - var queryParams = new Dictionary(); - var headerParams = new Dictionary(); - var formParams = new Dictionary(); - var fileParams = new Dictionary(); - String postBody = null; - - - - - - - // authentication setting, if any - String[] authSettings = new String[] { }; - - // make the HTTP request - IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { - throw new ApiException ((int)response.StatusCode, "Error calling DeleteUser: " + response.Content, response.Content); - } - - return; - } - - } + /// + /// Create user This can only be done by the logged in user. + /// + /// Created user object + Task CreateUserAsync (User body); + + /// + /// Creates list of users with given input array + /// + /// List of user object + void CreateUsersWithArrayInput (List body); + /// + /// Creates list of users with given input array + /// + /// List of user object + Task CreateUsersWithArrayInputAsync (List body); + + /// + /// Creates list of users with given input array + /// + /// List of user object + void CreateUsersWithListInput (List body); + + /// + /// Creates list of users with given input array + /// + /// List of user object + Task CreateUsersWithListInputAsync (List body); + + /// + /// Logs user into the system + /// + /// The user name for login + /// The password for login in clear text + /// string + string LoginUser (string username, string password); + + /// + /// Logs user into the system + /// + /// The user name for login + /// The password for login in clear text + /// string + Task LoginUserAsync (string username, string password); + + /// + /// Logs out current logged in user session + /// + void LogoutUser (); + + /// + /// Logs out current logged in user session + /// + Task LogoutUserAsync (); + + /// + /// Get user by user name + /// + /// The name that needs to be fetched. Use user1 for testing. + /// User + User GetUserByName (string username); + + /// + /// Get user by user name + /// + /// The name that needs to be fetched. Use user1 for testing. + /// User + Task GetUserByNameAsync (string username); + + /// + /// Updated user This can only be done by the logged in user. + /// + /// name that need to be deleted + /// Updated user object + void UpdateUser (string username, User body); + + /// + /// Updated user This can only be done by the logged in user. + /// + /// name that need to be deleted + /// Updated user object + Task UpdateUserAsync (string username, User body); + + /// + /// Delete user This can only be done by the logged in user. + /// + /// The name that needs to be deleted + void DeleteUser (string username); + + /// + /// Delete user This can only be done by the logged in user. + /// + /// The name that needs to be deleted + Task DeleteUserAsync (string username); + + } + + /// + /// Represents a collection of functions to interact with the API endpoints + /// + public class UserApi : IUserApi { + + /// + /// Initializes a new instance of the class. + /// + /// an instance of ApiClient (optional) + /// + public UserApi(ApiClient apiClient = null) { + if (apiClient == null) { // use the default one in Configuration + this.ApiClient = Configuration.DefaultApiClient; + } else { + this.ApiClient = apiClient; + } + } + + /// + /// Initializes a new instance of the class. + /// + /// + public UserApi(String basePath) + { + this.ApiClient = new ApiClient(basePath); + } + + /// + /// Sets the base path of the API client. + /// + /// The base path + public void SetBasePath(String basePath) { + this.ApiClient.BasePath = basePath; + } + + /// + /// Gets the base path of the API client. + /// + /// The base path + public String GetBasePath(String basePath) { + return this.ApiClient.BasePath; + } + + /// + /// Gets or sets the API client. + /// + /// The API client + public ApiClient ApiClient {get; set;} + + + /// + /// Create user This can only be done by the logged in user. + /// + /// Created user object + public void CreateUser (User body) { + + + + var path = "/user"; + path = path.Replace("{format}", "json"); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + + postBody = ApiClient.Serialize(body); // http body (model) parameter + + + // authentication setting, if any + String[] authSettings = new String[] { }; + + // make the HTTP request + IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling CreateUser: " + response.Content, response.Content); + } + + return; + } + + /// + /// Create user This can only be done by the logged in user. + /// + /// Created user object + public async Task CreateUserAsync (User body) { + + + var path = "/user"; + path = path.Replace("{format}", "json"); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + + postBody = ApiClient.Serialize(body); // http body (model) parameter + + + // authentication setting, if any + String[] authSettings = new String[] { }; + + // make the HTTP request + IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling CreateUser: " + response.Content, response.Content); + } + + return; + } + + /// + /// Creates list of users with given input array + /// + /// List of user object + public void CreateUsersWithArrayInput (List body) { + + + + var path = "/user/createWithArray"; + path = path.Replace("{format}", "json"); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + + postBody = ApiClient.Serialize(body); // http body (model) parameter + + + // authentication setting, if any + String[] authSettings = new String[] { }; + + // make the HTTP request + IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithArrayInput: " + response.Content, response.Content); + } + + return; + } + + /// + /// Creates list of users with given input array + /// + /// List of user object + public async Task CreateUsersWithArrayInputAsync (List body) { + + + var path = "/user/createWithArray"; + path = path.Replace("{format}", "json"); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + + postBody = ApiClient.Serialize(body); // http body (model) parameter + + + // authentication setting, if any + String[] authSettings = new String[] { }; + + // make the HTTP request + IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithArrayInput: " + response.Content, response.Content); + } + + return; + } + + /// + /// Creates list of users with given input array + /// + /// List of user object + public void CreateUsersWithListInput (List body) { + + + + var path = "/user/createWithList"; + path = path.Replace("{format}", "json"); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + + postBody = ApiClient.Serialize(body); // http body (model) parameter + + + // authentication setting, if any + String[] authSettings = new String[] { }; + + // make the HTTP request + IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithListInput: " + response.Content, response.Content); + } + + return; + } + + /// + /// Creates list of users with given input array + /// + /// List of user object + public async Task CreateUsersWithListInputAsync (List body) { + + + var path = "/user/createWithList"; + path = path.Replace("{format}", "json"); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + + postBody = ApiClient.Serialize(body); // http body (model) parameter + + + // authentication setting, if any + String[] authSettings = new String[] { }; + + // make the HTTP request + IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithListInput: " + response.Content, response.Content); + } + + return; + } + + /// + /// Logs user into the system + /// + /// The user name for login + /// The password for login in clear text + /// string + public string LoginUser (string username, string password) { + + + + var path = "/user/login"; + path = path.Replace("{format}", "json"); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + 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 + + + + + + // authentication setting, if any + String[] authSettings = new String[] { }; + + // make the HTTP request + IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling LoginUser: " + response.Content, response.Content); + } + + return (string) ApiClient.Deserialize(response.Content, typeof(string), response.Headers); + } + + /// + /// Logs user into the system + /// + /// The user name for login + /// The password for login in clear text + /// string + public async Task LoginUserAsync (string username, string password) { + + + var path = "/user/login"; + path = path.Replace("{format}", "json"); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + 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 + + + + + + // authentication setting, if any + String[] authSettings = new String[] { }; + + // make the HTTP request + IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling LoginUser: " + response.Content, response.Content); + } + return (string) ApiClient.Deserialize(response.Content, typeof(string), response.Headers); + } + + /// + /// Logs out current logged in user session + /// + public void LogoutUser () { + + + + var path = "/user/logout"; + path = path.Replace("{format}", "json"); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + + + + // authentication setting, if any + String[] authSettings = new String[] { }; + + // make the HTTP request + IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling LogoutUser: " + response.Content, response.Content); + } + + return; + } + + /// + /// Logs out current logged in user session + /// + public async Task LogoutUserAsync () { + + + var path = "/user/logout"; + path = path.Replace("{format}", "json"); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + + + + // authentication setting, if any + String[] authSettings = new String[] { }; + + // make the HTTP request + IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling LogoutUser: " + response.Content, response.Content); + } + + return; + } + + /// + /// Get user by user name + /// + /// The name that needs to be fetched. Use user1 for testing. + /// User + public User GetUserByName (string username) { + + + // verify the required parameter 'username' is set + if (username == null) throw new ApiException(400, "Missing required parameter 'username' when calling GetUserByName"); + + + var path = "/user/{username}"; + path = path.Replace("{format}", "json"); + path = path.Replace("{" + "username" + "}", ApiClient.ParameterToString(username)); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + + + + // authentication setting, if any + String[] authSettings = new String[] { }; + + // make the HTTP request + IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling GetUserByName: " + response.Content, response.Content); + } + + return (User) ApiClient.Deserialize(response.Content, typeof(User), response.Headers); + } + + /// + /// Get user by user name + /// + /// The name that needs to be fetched. Use user1 for testing. + /// User + public async Task GetUserByNameAsync (string username) { + // verify the required parameter 'username' is set + if (username == null) throw new ApiException(400, "Missing required parameter 'username' when calling GetUserByName"); + + + var path = "/user/{username}"; + path = path.Replace("{format}", "json"); + path = path.Replace("{" + "username" + "}", ApiClient.ParameterToString(username)); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + + + + // authentication setting, if any + String[] authSettings = new String[] { }; + + // make the HTTP request + IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling GetUserByName: " + response.Content, response.Content); + } + return (User) ApiClient.Deserialize(response.Content, typeof(User), response.Headers); + } + + /// + /// Updated user This can only be done by the logged in user. + /// + /// name that need to be deleted + /// Updated user object + public void UpdateUser (string username, User body) { + + + // verify the required parameter 'username' is set + if (username == null) throw new ApiException(400, "Missing required parameter 'username' when calling UpdateUser"); + + + var path = "/user/{username}"; + path = path.Replace("{format}", "json"); + path = path.Replace("{" + "username" + "}", ApiClient.ParameterToString(username)); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + + postBody = ApiClient.Serialize(body); // http body (model) parameter + + + // authentication setting, if any + String[] authSettings = new String[] { }; + + // make the HTTP request + IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling UpdateUser: " + response.Content, response.Content); + } + + return; + } + + /// + /// Updated user This can only be done by the logged in user. + /// + /// name that need to be deleted + /// Updated user object + public async Task UpdateUserAsync (string username, User body) { + // verify the required parameter 'username' is set + if (username == null) throw new ApiException(400, "Missing required parameter 'username' when calling UpdateUser"); + + + var path = "/user/{username}"; + path = path.Replace("{format}", "json"); + path = path.Replace("{" + "username" + "}", ApiClient.ParameterToString(username)); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + + postBody = ApiClient.Serialize(body); // http body (model) parameter + + + // authentication setting, if any + String[] authSettings = new String[] { }; + + // make the HTTP request + IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling UpdateUser: " + response.Content, response.Content); + } + + return; + } + + /// + /// Delete user This can only be done by the logged in user. + /// + /// The name that needs to be deleted + public void DeleteUser (string username) { + + + // verify the required parameter 'username' is set + if (username == null) throw new ApiException(400, "Missing required parameter 'username' when calling DeleteUser"); + + + var path = "/user/{username}"; + path = path.Replace("{format}", "json"); + path = path.Replace("{" + "username" + "}", ApiClient.ParameterToString(username)); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + + + + // authentication setting, if any + String[] authSettings = new String[] { }; + + // make the HTTP request + IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling DeleteUser: " + response.Content, response.Content); + } + + return; + } + + /// + /// Delete user This can only be done by the logged in user. + /// + /// The name that needs to be deleted + public async Task DeleteUserAsync (string username) { + // verify the required parameter 'username' is set + if (username == null) throw new ApiException(400, "Missing required parameter 'username' when calling DeleteUser"); + + + var path = "/user/{username}"; + path = path.Replace("{format}", "json"); + path = path.Replace("{" + "username" + "}", ApiClient.ParameterToString(username)); + + + var queryParams = new Dictionary(); + var headerParams = new Dictionary(); + var formParams = new Dictionary(); + var fileParams = new Dictionary(); + String postBody = null; + + + + + + + // authentication setting, if any + String[] authSettings = new String[] { }; + + // make the HTTP request + IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + if (((int)response.StatusCode) >= 400) { + throw new ApiException ((int)response.StatusCode, "Error calling DeleteUser: " + response.Content, response.Content); + } + + return; + } + + } + } diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/ApiClient.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/ApiClient.cs index 4940687de3d..1e259af15d4 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/ApiClient.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/ApiClient.cs @@ -10,284 +10,285 @@ using Newtonsoft.Json; using RestSharp; namespace IO.Swagger.Client { - /// - /// API client is mainly responible for making the HTTP call to the API backend - /// - public class ApiClient { - /// - /// Initializes a new instance of the class. + /// API client is mainly responible for making the HTTP call to the API backend /// - /// The base path. - public ApiClient(String basePath="http://petstore.swagger.io/v2") { - this.BasePath = basePath; - this.RestClient = new RestClient(this.BasePath); - } - - /// - /// Gets or sets the base path. - /// - /// The base path. - public string BasePath { get; set; } - - /// - /// Gets or sets the RestClient - /// - /// The RestClient. - public RestClient RestClient { get; set; } - - private Dictionary DefaultHeaderMap = new Dictionary(); - - public Object CallApi(String path, RestSharp.Method method, Dictionary queryParams, String postBody, - Dictionary headerParams, Dictionary formParams, Dictionary fileParams, String[] authSettings) { - var response = Task.Run(async () => { - var resp = await CallApiAsync(path, method, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - return resp; - }); - return response.Result; - } - - public async Task CallApiAsync(String path, RestSharp.Method method, Dictionary queryParams, String postBody, - Dictionary headerParams, Dictionary formParams, Dictionary fileParams, String[] authSettings) { - - var request = new RestRequest(path, method); - - UpdateParamsForAuth(queryParams, headerParams, authSettings); - - // add default header, if any - foreach(KeyValuePair defaultHeader in this.DefaultHeaderMap) - request.AddHeader(defaultHeader.Key, defaultHeader.Value); - - // add header parameter, if any - foreach(KeyValuePair param in headerParams) - request.AddHeader(param.Key, param.Value); - - // add query parameter, if any - foreach(KeyValuePair param in queryParams) - request.AddQueryParameter(param.Key, param.Value); - - // add form parameter, if any - foreach(KeyValuePair param in formParams) - request.AddParameter(param.Key, param.Value); - - // add file parameter, if any - foreach(KeyValuePair param in fileParams) - request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType); - - - if (postBody != null) { - request.AddParameter("application/json", postBody, ParameterType.RequestBody); // http body (model) parameter - } - - return (Object) await RestClient.ExecuteTaskAsync(request); - - } - - /// - /// Add default header - /// - /// Header field name - /// Header field value - /// - public void AddDefaultHeader(string key, string value) { - DefaultHeaderMap.Add(key, value); - } - - /// - /// Get default header - /// - /// Dictionary of default header - public Dictionary GetDefaultHeader() { - return DefaultHeaderMap; - } - - /// - /// escape string (url-encoded) - /// - /// String to be escaped - /// Escaped string - public string EscapeString(string str) { - return str; - } - - /// - /// Create FileParameter based on Stream - /// - /// parameter name - /// Stream - /// FileParameter - public FileParameter ParameterToFile(string name, Stream stream) - { - if (stream is FileStream) { - return FileParameter.Create(name, StreamToByteArray(stream), ((FileStream)stream).Name); - } else { - return FileParameter.Create(name, StreamToByteArray(stream), "temp_name_here"); - } - } - - /// - /// if parameter is DateTime, output in ISO8601 format - /// if parameter is a list of string, join the list with "," - /// otherwise just return the string - /// - /// The parameter (header, path, query, form) - /// Formatted string - public string ParameterToString(object obj) - { - if (obj is DateTime) { - return ((DateTime)obj).ToString ("u"); - } else if (obj is List) { - return String.Join(",", obj as List); - } else { - return Convert.ToString (obj); - } - } - - /// - /// Deserialize the JSON string into a proper object - /// - /// HTTP body (e.g. string, JSON) - /// Object type - /// Object representation of the JSON string - public object Deserialize(string content, Type type, IList headers=null) { - if (type.GetType() == typeof(Object)) { // return an object - return (Object)content; - } else if (type.Name == "Stream") { - String fileName, filePath; - if (String.IsNullOrEmpty (Configuration.TempFolderPath)) { - filePath = System.IO.Path.GetTempPath (); - } else { - filePath = Configuration.TempFolderPath; - } - - Regex regex = new Regex(@"Content-Disposition:.*filename=['""]?([^'""\s]+)['""]?$"); - Match match = regex.Match(headers.ToString()); - if (match.Success) { - // replace first and last " or ', if found - fileName = filePath + match.Value.Replace("\"", "").Replace("'",""); - } else { - fileName = filePath + Guid.NewGuid().ToString(); - } - File.WriteAllText (fileName, content); - return new FileStream(fileName, FileMode.Open); - } else if (type.Name.StartsWith("System.Nullable`1[[System.DateTime")) { // return a datetime object - return DateTime.Parse(content, null, System.Globalization.DateTimeStyles.RoundtripKind); - } else if (type.Name == "String" || type.Name.StartsWith("System.Nullable")) { // return primitive - return ConvertType(content, type); - } - - // at this point, it must be a model (json) - try - { - return JsonConvert.DeserializeObject(content, type); - } - catch (IOException e) { - throw new ApiException(500, e.Message); - } - } - - /// - /// Serialize an object into JSON string - /// - /// Object - /// JSON string - public string Serialize(object obj) { - try - { - return obj != null ? JsonConvert.SerializeObject(obj) : null; - } - catch (Exception e) { - throw new ApiException(500, e.Message); - } - } - - /// - /// Get the API key with prefix - /// - /// Object - /// API key with prefix - public string GetApiKeyWithPrefix (string apiKeyIdentifier) - { - var apiKeyValue = ""; - Configuration.ApiKey.TryGetValue (apiKeyIdentifier, out apiKeyValue); - var apiKeyPrefix = ""; - if (Configuration.ApiKeyPrefix.TryGetValue (apiKeyIdentifier, out apiKeyPrefix)) { - return apiKeyPrefix + " " + apiKeyValue; - } else { - return apiKeyValue; - } - } - - /// - /// Update parameters based on authentication - /// - /// Query parameters - /// Header parameters - /// Authentication settings - public void UpdateParamsForAuth(Dictionary queryParams, Dictionary headerParams, string[] authSettings) { - if (authSettings == null || authSettings.Length == 0) - return; + public class ApiClient { - 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; + /// + /// Initializes a new instance of the class. + /// + /// The base path. + public ApiClient(String basePath="http://petstore.swagger.io/v2") { + this.BasePath = basePath; + this.RestClient = new RestClient(this.BasePath); } - } - - } - - /// - /// convert a stream to byte array (byte[]) - /// Ref: http://stackoverflow.com/questions/221925/creating-a-byte-array-from-a-stream - /// - /// input stream - /// Array of Byte - public byte[] StreamToByteArray(Stream input) - { - byte[] buffer = new byte[16*1024]; - using (MemoryStream ms = new MemoryStream()) - { - int read; - while ((read = input.Read(buffer, 0, buffer.Length)) > 0) - { - ms.Write(buffer, 0, read); + + /// + /// Gets or sets the base path. + /// + /// The base path. + public string BasePath { get; set; } + + /// + /// Gets or sets the RestClient + /// + /// The RestClient. + public RestClient RestClient { get; set; } + + private Dictionary DefaultHeaderMap = new Dictionary(); + + public Object CallApi(String path, RestSharp.Method method, Dictionary queryParams, String postBody, + Dictionary headerParams, Dictionary formParams, + Dictionary fileParams, String[] authSettings) { + var response = Task.Run(async () => { + var resp = await CallApiAsync(path, method, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + return resp; + }); + return response.Result; + } + + public async Task CallApiAsync(String path, RestSharp.Method method, Dictionary queryParams, String postBody, + Dictionary headerParams, Dictionary formParams, Dictionary fileParams, String[] authSettings) { + + var request = new RestRequest(path, method); + + UpdateParamsForAuth(queryParams, headerParams, authSettings); + + // add default header, if any + foreach(KeyValuePair defaultHeader in this.DefaultHeaderMap) + request.AddHeader(defaultHeader.Key, defaultHeader.Value); + + // add header parameter, if any + foreach(KeyValuePair param in headerParams) + request.AddHeader(param.Key, param.Value); + + // add query parameter, if any + foreach(KeyValuePair param in queryParams) + request.AddQueryParameter(param.Key, param.Value); + + // add form parameter, if any + foreach(KeyValuePair param in formParams) + request.AddParameter(param.Key, param.Value); + + // add file parameter, if any + foreach(KeyValuePair param in fileParams) + request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType); + + + if (postBody != null) { + request.AddParameter("application/json", postBody, ParameterType.RequestBody); // http body (model) parameter } - return ms.ToArray(); + + return (Object) await RestClient.ExecuteTaskAsync(request); + } + + /// + /// Add default header + /// + /// Header field name + /// Header field value + /// + public void AddDefaultHeader(string key, string value) { + DefaultHeaderMap.Add(key, value); + } + + /// + /// Get default header + /// + /// Dictionary of default header + public Dictionary GetDefaultHeader() { + return DefaultHeaderMap; + } + + /// + /// escape string (url-encoded) + /// + /// String to be escaped + /// Escaped string + public string EscapeString(string str) { + return str; + } + + /// + /// Create FileParameter based on Stream + /// + /// parameter name + /// Input stream + /// FileParameter + public FileParameter ParameterToFile(string name, Stream stream) + { + if (stream is FileStream) { + return FileParameter.Create(name, StreamToByteArray(stream), ((FileStream)stream).Name); + } else { + return FileParameter.Create(name, StreamToByteArray(stream), "temp_name_here"); + } + } + + /// + /// if parameter is DateTime, output in ISO8601 format + /// if parameter is a list of string, join the list with "," + /// otherwise just return the string + /// + /// The parameter (header, path, query, form) + /// Formatted string + public string ParameterToString(object obj) + { + if (obj is DateTime) { + return ((DateTime)obj).ToString ("u"); + } else if (obj is List) { + return String.Join(",", obj as List); + } else { + return Convert.ToString (obj); + } + } + + /// + /// Deserialize the JSON string into a proper object + /// + /// HTTP body (e.g. string, JSON) + /// Object type + /// Object representation of the JSON string + public object Deserialize(string content, Type type, IList headers=null) { + if (type.GetType() == typeof(Object)) { // return an object + return (Object)content; + } else if (type.Name == "Stream") { + String fileName, filePath; + if (String.IsNullOrEmpty (Configuration.TempFolderPath)) { + filePath = System.IO.Path.GetTempPath (); + } else { + filePath = Configuration.TempFolderPath; + } + + Regex regex = new Regex(@"Content-Disposition:.*filename=['""]?([^'""\s]+)['""]?$"); + Match match = regex.Match(headers.ToString()); + if (match.Success) { + // replace first and last " or ', if found + fileName = filePath + match.Value.Replace("\"", "").Replace("'",""); + } else { + fileName = filePath + Guid.NewGuid().ToString(); + } + File.WriteAllText (fileName, content); + return new FileStream(fileName, FileMode.Open); + } else if (type.Name.StartsWith("System.Nullable`1[[System.DateTime")) { // return a datetime object + return DateTime.Parse(content, null, System.Globalization.DateTimeStyles.RoundtripKind); + } else if (type.Name == "String" || type.Name.StartsWith("System.Nullable")) { // return primitive + return ConvertType(content, type); + } + + // at this point, it must be a model (json) + try + { + return JsonConvert.DeserializeObject(content, type); + } + catch (IOException e) { + throw new ApiException(500, e.Message); + } + } + + /// + /// Serialize an object into JSON string + /// + /// Object + /// JSON string + public string Serialize(object obj) { + try + { + return obj != null ? JsonConvert.SerializeObject(obj) : null; + } + catch (Exception e) { + throw new ApiException(500, e.Message); + } + } + + /// + /// Get the API key with prefix + /// + /// Object + /// API key with prefix + public string GetApiKeyWithPrefix (string apiKeyIdentifier) + { + var apiKeyValue = ""; + Configuration.ApiKey.TryGetValue (apiKeyIdentifier, out apiKeyValue); + var apiKeyPrefix = ""; + if (Configuration.ApiKeyPrefix.TryGetValue (apiKeyIdentifier, out apiKeyPrefix)) { + return apiKeyPrefix + " " + apiKeyValue; + } else { + return apiKeyValue; + } + } + + /// + /// Update parameters based on authentication + /// + /// Query parameters + /// Header parameters + /// Authentication settings + public void UpdateParamsForAuth(Dictionary queryParams, Dictionary 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; + } + } + + } + + /// + /// convert a stream to byte array (byte[]) + /// Ref: http://stackoverflow.com/questions/221925/creating-a-byte-array-from-a-stream + /// + /// input stream + /// Array of Byte + public byte[] StreamToByteArray(Stream input) + { + byte[] buffer = new byte[16*1024]; + using (MemoryStream ms = new MemoryStream()) + { + int read; + while ((read = input.Read(buffer, 0, buffer.Length)) > 0) + { + ms.Write(buffer, 0, read); + } + return ms.ToArray(); + } + } + + /// + /// Encode string in base64 format + /// + /// String to be encoded + public static string Base64Encode(string text) { + var textByte = System.Text.Encoding.UTF8.GetBytes(text); + return System.Convert.ToBase64String(textByte); + } + + /// + /// Dynamically cast the object into target type + /// Ref: http://stackoverflow.com/questions/4925718/c-dynamic-runtime-cast + /// + /// Object to be casted + /// Target type + public static dynamic ConvertType(dynamic source, Type dest) { + return Convert.ChangeType(source, dest); + } + } - - /// - /// Encode string in base64 format - /// - /// String to be encoded - public static string Base64Encode(string text) { - var textByte = System.Text.Encoding.UTF8.GetBytes(text); - return System.Convert.ToBase64String(textByte); - } - - /// - /// Dynamically cast the object into target type - /// Ref: http://stackoverflow.com/questions/4925718/c-dynamic-runtime-cast - /// - /// Object to be casted - /// Target type - public static dynamic ConvertType(dynamic source, Type dest) { - return Convert.ChangeType(source, dest); - } - - } } diff --git a/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb b/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb index e5bbf0a9ef2..870fb99f816 100644 Binary files a/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb and b/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb differ diff --git a/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb b/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb index e5bbf0a9ef2..870fb99f816 100644 Binary files a/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb and b/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb differ