diff --git a/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache index 905931a2991..4206b3434e4 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Text.RegularExpressions; using System.IO; +using System.Web; using System.Linq; using System.Net; using System.Text; @@ -10,222 +12,222 @@ using Newtonsoft.Json; using RestSharp; using RestSharp.Extensions; -namespace {{packageName}}.Client { +namespace {{packageName}}.Client +{ /// - /// API client is mainly responible for making the HTTP call to the API backend + /// API client is mainly responible for making the HTTP call to the API backend. /// - public class ApiClient { + public class ApiClient + { + private readonly Dictionary _defaultHeaderMap = new Dictionary(); /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The base path. - public ApiClient(String basePath="{{basePath}}") { - this.BasePath = basePath; - this.RestClient = new RestClient(this.BasePath); + public ApiClient(String basePath="{{basePath}}") + { + BasePath = basePath; + RestClient = new RestClient(BasePath); } /// /// Gets or sets the base path. /// - /// The base path. public string BasePath { get; set; } /// - /// Gets or sets the RestClient + /// Gets or sets the RestClient. /// - /// The RestClient. public RestClient RestClient { get; set; } - private Dictionary DefaultHeaderMap = new Dictionary(); + /// + /// Gets the default header. + /// + public Dictionary DefaultHeader + { + get { return _defaultHeaderMap; } + } /// - /// Make the HTTP request (Sync) + /// Makes the HTTP request (Sync). /// - /// URL path - /// HTTP method - /// Query parameters - /// HTTP body (POST request) - /// Header parameters - /// Form parameters - /// File parameters - /// Authentication settings + /// URL path. + /// HTTP method. + /// Query parameters. + /// HTTP body (POST request). + /// Header parameters. + /// Form parameters. + /// File parameters. + /// Authentication settings. /// Object public Object CallApi(String path, RestSharp.Method method, Dictionary queryParams, String postBody, Dictionary headerParams, Dictionary formParams, - Dictionary fileParams, String[] authSettings) { + 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) + foreach(var defaultHeader in _defaultHeaderMap) request.AddHeader(defaultHeader.Key, defaultHeader.Value); // add header parameter, if any - foreach(KeyValuePair param in headerParams) + foreach(var param in headerParams) request.AddHeader(param.Key, param.Value); // add query parameter, if any - foreach(KeyValuePair param in queryParams) + foreach(var param in queryParams) request.AddQueryParameter(param.Key, param.Value); // add form parameter, if any - foreach(KeyValuePair param in formParams) + foreach(var param in formParams) request.AddParameter(param.Key, param.Value); // add file parameter, if any - foreach(KeyValuePair param in fileParams) + foreach(var param in fileParams) request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType); - - if (postBody != null) { - request.AddParameter("application/json", postBody, ParameterType.RequestBody); // http body (model) parameter - } + if (postBody != null) // http body (model) parameter + request.AddParameter("application/json", postBody, ParameterType.RequestBody); return (Object)RestClient.Execute(request); } /// - /// Make the HTTP request (Async) + /// Makes the asynchronous HTTP request. /// - /// URL path - /// HTTP method - /// Query parameters - /// HTTP body (POST request) - /// Header parameters - /// Form parameters - /// File parameters - /// Authentication settings - /// Task + /// URL path. + /// HTTP method. + /// Query parameters. + /// HTTP body (POST request). + /// Header parameters. + /// Form parameters. + /// File parameters. + /// Authentication settings. + /// The Task instance. public async Task CallApiAsync(String path, RestSharp.Method method, Dictionary queryParams, String postBody, - Dictionary headerParams, Dictionary formParams, Dictionary fileParams, String[] authSettings) { + 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) + foreach(var defaultHeader in _defaultHeaderMap) request.AddHeader(defaultHeader.Key, defaultHeader.Value); // add header parameter, if any - foreach(KeyValuePair param in headerParams) + foreach(var param in headerParams) request.AddHeader(param.Key, param.Value); // add query parameter, if any - foreach(KeyValuePair param in queryParams) + foreach(var param in queryParams) request.AddQueryParameter(param.Key, param.Value); // add form parameter, if any - foreach(KeyValuePair param in formParams) + foreach(var param in formParams) request.AddParameter(param.Key, param.Value); // add file parameter, if any - foreach(KeyValuePair param in fileParams) + foreach(var param in fileParams) request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType); - - - if (postBody != null) { - request.AddParameter("application/json", postBody, ParameterType.RequestBody); // http body (model) parameter - } + + if (postBody != null) // http body (model) parameter + request.AddParameter("application/json", postBody, ParameterType.RequestBody); return (Object) await RestClient.ExecuteTaskAsync(request); - } /// - /// Add default header + /// Add default header. /// - /// Header field name - /// Header field value + /// Header field name. + /// Header field value. /// - public void AddDefaultHeader(string key, string value) { - DefaultHeaderMap.Add(key, value); + public void AddDefaultHeader(string key, string value) + { + _defaultHeaderMap.Add(key, value); } /// - /// Get default header + /// Escape string (url-encoded). /// - /// Dictionary of default header - public Dictionary GetDefaultHeader() { - return DefaultHeaderMap; + /// String to be escaped. + /// Escaped string. + public string EscapeString(string str) + { + return HttpUtility.UrlEncode(str); } /// - /// escape string (url-encoded) + /// Create FileParameter based on Stream. /// - /// String to be escaped - /// Escaped string - public string EscapeString(string str) { - return str; - } - - /// - /// Create FileParameter based on Stream - /// - /// parameter name - /// Input stream - /// FileParameter + /// Parameter name. + /// Input stream. + /// FileParameter. public FileParameter ParameterToFile(string name, Stream stream) { - if (stream is FileStream) { + if (stream is FileStream) return FileParameter.Create(name, stream.ReadAsBytes(), Path.GetFileName(((FileStream)stream).Name)); - } else { + else return FileParameter.Create(name, stream.ReadAsBytes(), "no_file_name_provided"); - } } /// - /// if parameter is DateTime, output in ISO8601 format - /// if parameter is a list of string, join the list with "," - /// otherwise just return the string + /// If parameter is DateTime, output in ISO8601 format. + /// If parameter is a list of string, join the list with ",". + /// Otherwise just return the string. /// - /// The parameter (header, path, query, form) - /// Formatted string + /// The parameter (header, path, query, form). + /// Formatted string. public string ParameterToString(object obj) { - if (obj is DateTime) { + if (obj is DateTime) return ((DateTime)obj).ToString ("u"); - } else if (obj is List) { + else if (obj is List) return String.Join(",", obj as List); - } else { + else return Convert.ToString (obj); - } } /// - /// Deserialize the JSON string into a proper object + /// 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 == typeof(Object)) { // return an 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 == typeof(Object)) // return an object + { return (Object)content; - } else if (type == typeof(Stream)) { + } else if (type == typeof(Stream)) + { String fileName, filePath; - if (String.IsNullOrEmpty (Configuration.TempFolderPath)) { + if (String.IsNullOrEmpty (Configuration.TempFolderPath)) filePath = System.IO.Path.GetTempPath (); - } else { + else filePath = Configuration.TempFolderPath; - } - + Regex regex = new Regex(@"Content-Disposition:.*filename=['""]?([^'""\s]+)['""]?$"); Match match = regex.Match(headers.ToString()); - if (match.Success) { - // replace first and last " or ', if found + if (match.Success) // replace first and last " or ', if found fileName = filePath + match.Value.Replace("\"", "").Replace("'",""); - } else { + else fileName = filePath + Guid.NewGuid().ToString(); - } + File.WriteAllText (fileName, content); return new FileStream(fileName, FileMode.Open); - } else if (type.Name.StartsWith("System.Nullable`1[[System.DateTime")) { // return a datetime object + } else if (type.Name.StartsWith("System.Nullable`1[[System.DateTime")) // return a datetime object + { return DateTime.Parse(content, null, System.Globalization.DateTimeStyles.RoundtripKind); - } else if (type.Name == "String" || type.Name.StartsWith("System.Nullable")) { // return primitive + } else if (type.Name == "String" || type.Name.StartsWith("System.Nullable")) // return primitive type + { return ConvertType(content, type); } @@ -234,56 +236,61 @@ namespace {{packageName}}.Client { { return JsonConvert.DeserializeObject(content, type); } - catch (IOException e) { + catch (IOException e) + { throw new ApiException(500, e.Message); } } /// - /// Serialize an object into JSON string + /// Serialize an object into JSON string. /// - /// Object - /// JSON string - public string Serialize(object obj) { + /// Object. + /// JSON string. + public string Serialize(object obj) + { try { return obj != null ? JsonConvert.SerializeObject(obj) : null; } - catch (Exception e) { + catch (Exception e) + { throw new ApiException(500, e.Message); } } /// - /// Get the API key with prefix + /// Get the API key with prefix. /// - /// Object - /// API key with prefix + /// API key identifier (authentication scheme). + /// 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)) { + if (Configuration.ApiKeyPrefix.TryGetValue (apiKeyIdentifier, out apiKeyPrefix)) return apiKeyPrefix + " " + apiKeyValue; - } else { + else return apiKeyValue; - } } /// - /// Update parameters based on authentication + /// Update parameters based on authentication. /// - /// Query parameters - /// Header parameters - /// Authentication settings - public void UpdateParamsForAuth(Dictionary queryParams, Dictionary headerParams, string[] authSettings) { + /// 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) { + foreach (string auth in authSettings) + { // determine which one to use - switch(auth) { + switch(auth) + { {{#authMethods}} case "{{name}}": {{#isApiKey}}{{#isKeyInHeader}}headerParams["{{keyParamName}}"] = GetApiKeyWithPrefix("{{keyParamName}}");{{/isKeyInHeader}}{{#isKeyInQuery}}queryParams["{{keyParamName}}"] = GetApiKeyWithPrefix("{{keyParamName}}");{{/isKeyInQuery}}{{/isApiKey}}{{#isBasic}}headerParams["Authorization"] = "Basic " + Base64Encode(Configuration.Username + ":" + Configuration.Password);{{/isBasic}} @@ -295,24 +302,26 @@ namespace {{packageName}}.Client { break; } } - } /// - /// Encode string in base64 format + /// Encode string in base64 format. /// - /// String to be encoded - public static string Base64Encode(string text) { + /// String to be encoded. + /// Encoded string. + 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 + /// Dynamically cast the object into target type. /// Ref: http://stackoverflow.com/questions/4925718/c-dynamic-runtime-cast /// - /// Object to be casted + /// Object to be casted /// Target type + /// Casted object public static dynamic ConvertType(dynamic source, Type dest) { return Convert.ChangeType(source, dest); } diff --git a/modules/swagger-codegen/src/main/resources/csharp/Configuration.mustache b/modules/swagger-codegen/src/main/resources/csharp/Configuration.mustache index a6246c3e158..ce2f351b433 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/Configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/Configuration.mustache @@ -3,18 +3,20 @@ using System.Reflection; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Net; using System.Text; -namespace {{packageName}}.Client { +namespace {{packageName}}.Client +{ /// /// Represents a set of configuration settings /// - public class Configuration{ + public class Configuration + { /// - /// Version of the package + /// Version of the package. /// + /// Version of the package. public const string Version = "{{packageVersion}}"; /// @@ -24,25 +26,25 @@ namespace {{packageName}}.Client { public static ApiClient DefaultApiClient = new ApiClient(); /// - /// Gets or sets the username (HTTP basic authentication) + /// Gets or sets the username (HTTP basic authentication). /// /// The username. public static String Username { get; set; } /// - /// Gets or sets the password (HTTP basic authentication) + /// Gets or sets the password (HTTP basic authentication). /// /// The password. public static String Password { get; set; } /// - /// Gets or sets the API key based on the authentication name + /// Gets or sets the API key based on the authentication name. /// /// The API key. public static Dictionary ApiKey = new Dictionary(); /// - /// Gets or sets the prefix (e.g. Token) of the API key based on the authentication name + /// Gets or sets the prefix (e.g. Token) of the API key based on the authentication name. /// /// The prefix of the API key. public static Dictionary ApiKeyPrefix = new Dictionary(); @@ -50,46 +52,46 @@ namespace {{packageName}}.Client { private static string _tempFolderPath = Path.GetTempPath(); /// - /// Gets or sets the temporary folder path to store the files downloaded from the server + /// Gets or sets the temporary folder path to store the files downloaded from the server. /// - /// Folder path - public static String TempFolderPath { - get { - return _tempFolderPath; - } + /// Folder path. + public static String TempFolderPath + { + get { return _tempFolderPath; } - set { - if (String.IsNullOrEmpty(value)) { + set + { + if (String.IsNullOrEmpty(value)) + { _tempFolderPath = value; return; } // create the directory if it does not exist - if (!Directory.Exists(value)) { + if (!Directory.Exists(value)) Directory.CreateDirectory(value); - } // check if the path contains directory separator at the end - if (value[value.Length - 1] == Path.DirectorySeparatorChar) { + if (value[value.Length - 1] == Path.DirectorySeparatorChar) _tempFolderPath = value; - } else { + else _tempFolderPath = value + Path.DirectorySeparatorChar; - } } } /// - /// Return a string contain essential information for debugging + /// Returns a string with essential information for debugging. /// - /// Folder path - public static String ToDebugReport() { + /// Debugging Report + public static String ToDebugReport() + { String report = "C# SDK ({{invokerPackage}}) Debug Report:\n"; report += " OS: " + Environment.OSVersion + "\n"; report += " .NET Framework Version: " + Assembly .GetExecutingAssembly() .GetReferencedAssemblies() .Where(x => x.Name == "System.Core").First().Version.ToString() + "\n"; - report += " Swagger Spec Version: {{version}}\n"; + report += " Version of the API: {{version}}\n"; report += " SDK Package Version: {{packageVersion}}\n"; return report; diff --git a/modules/swagger-codegen/src/main/resources/csharp/api.mustache b/modules/swagger-codegen/src/main/resources/csharp/api.mustache index 78d2a2598a9..d7483489d28 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/api.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/api.mustache @@ -7,9 +7,11 @@ using {{packageName}}.Client; {{#hasImport}}using {{packageName}}.Model; {{/hasImport}} -namespace {{packageName}}.Api { +namespace {{packageName}}.Api +{ {{#operations}} - public interface I{{classname}} { + public interface I{{classname}} + { {{#operation}} /// /// {{summary}} {{notes}} @@ -30,19 +32,19 @@ namespace {{packageName}}.Api { /// /// Represents a collection of functions to interact with the API endpoints /// - public class {{classname}} : I{{classname}} { - + 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 + public {{classname}}(ApiClient apiClient = null) + { + if (apiClient == null) // use the default one in Configuration this.ApiClient = Configuration.DefaultApiClient; - } else { + else this.ApiClient = apiClient; - } } /// @@ -58,7 +60,8 @@ namespace {{packageName}}.Api { /// Sets the base path of the API client. /// /// The base path - public void SetBasePath(String basePath) { + public void SetBasePath(String basePath) + { this.ApiClient.BasePath = basePath; } @@ -66,14 +69,15 @@ namespace {{packageName}}.Api { /// Gets the base path of the API client. /// /// The base path - public String GetBasePath(String basePath) { + public String GetBasePath(String basePath) + { return this.ApiClient.BasePath; } /// /// Gets or sets the API client. /// - /// The API client + /// The API client. public ApiClient ApiClient {get; set;} {{#operation}} @@ -82,8 +86,8 @@ namespace {{packageName}}.Api { /// {{#allParams}}/// {{description}} {{/allParams}}/// {{#returnType}}{{{returnType}}}{{/returnType}} - public {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { - + public {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) + { {{#allParams}}{{#required}} // verify the required parameter '{{paramName}}' is set if ({{paramName}} == null) throw new ApiException(400, "Missing required parameter '{{paramName}}' when calling {{nickname}}"); @@ -115,11 +119,10 @@ namespace {{packageName}}.Api { // make the HTTP request IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.{{httpMethod}}, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.Content, response.Content); - } else if (((int)response.StatusCode) == 0) { + else if (((int)response.StatusCode) == 0) throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.ErrorMessage, response.ErrorMessage); - } {{#returnType}}return ({{{returnType}}}) ApiClient.Deserialize(response.Content, typeof({{{returnType}}}), response.Headers);{{/returnType}}{{^returnType}}return;{{/returnType}} } @@ -129,7 +132,8 @@ namespace {{packageName}}.Api { /// {{#allParams}}/// {{description}} {{/allParams}}/// {{#returnType}}{{{returnType}}}{{/returnType}} - {{#returnType}}public async Task<{{{returnType}}}>{{/returnType}}{{^returnType}}public async Task{{/returnType}} {{nickname}}Async ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { + {{#returnType}}public async Task<{{{returnType}}}>{{/returnType}}{{^returnType}}public async Task{{/returnType}} {{nickname}}Async ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) + { {{#allParams}}{{#required}}// verify the required parameter '{{paramName}}' is set if ({{paramName}} == null) throw new ApiException(400, "Missing required parameter '{{paramName}}' when calling {{nickname}}"); {{/required}}{{/allParams}} @@ -159,13 +163,13 @@ namespace {{packageName}}.Api { // make the HTTP request IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.{{httpMethod}}, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.Content, response.Content); - } + {{#returnType}}return ({{{returnType}}}) ApiClient.Deserialize(response.Content, typeof({{{returnType}}}), response.Headers);{{/returnType}}{{^returnType}} return;{{/returnType}} } {{/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 685d575a67b..5c670b2a36e 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 @@ -6,9 +6,11 @@ using RestSharp; using IO.Swagger.Client; using IO.Swagger.Model; -namespace IO.Swagger.Api { +namespace IO.Swagger.Api +{ - public interface IPetApi { + public interface IPetApi + { /// /// Update an existing pet @@ -137,19 +139,19 @@ namespace IO.Swagger.Api { /// /// Represents a collection of functions to interact with the API endpoints /// - public class PetApi : IPetApi { - + 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 + public PetApi(ApiClient apiClient = null) + { + if (apiClient == null) // use the default one in Configuration this.ApiClient = Configuration.DefaultApiClient; - } else { + else this.ApiClient = apiClient; - } } /// @@ -165,7 +167,8 @@ namespace IO.Swagger.Api { /// Sets the base path of the API client. /// /// The base path - public void SetBasePath(String basePath) { + public void SetBasePath(String basePath) + { this.ApiClient.BasePath = basePath; } @@ -173,14 +176,15 @@ namespace IO.Swagger.Api { /// Gets the base path of the API client. /// /// The base path - public String GetBasePath(String basePath) { + public String GetBasePath(String basePath) + { return this.ApiClient.BasePath; } /// /// Gets or sets the API client. /// - /// The API client + /// The API client. public ApiClient ApiClient {get; set;} @@ -189,8 +193,8 @@ namespace IO.Swagger.Api { /// /// Pet object that needs to be added to the store /// - public void UpdatePet (Pet body) { - + public void UpdatePet (Pet body) + { var path = "/pet"; @@ -215,11 +219,10 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling UpdatePet: " + response.Content, response.Content); - } else if (((int)response.StatusCode) == 0) { + else if (((int)response.StatusCode) == 0) throw new ApiException ((int)response.StatusCode, "Error calling UpdatePet: " + response.ErrorMessage, response.ErrorMessage); - } return; } @@ -229,7 +232,8 @@ namespace IO.Swagger.Api { /// /// Pet object that needs to be added to the store /// - public async Task UpdatePetAsync (Pet body) { + public async Task UpdatePetAsync (Pet body) + { var path = "/pet"; @@ -253,9 +257,9 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling UpdatePet: " + response.Content, response.Content); - } + return; } @@ -265,8 +269,8 @@ namespace IO.Swagger.Api { /// /// Pet object that needs to be added to the store /// - public void AddPet (Pet body) { - + public void AddPet (Pet body) + { var path = "/pet"; @@ -291,11 +295,10 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling AddPet: " + response.Content, response.Content); - } else if (((int)response.StatusCode) == 0) { + else if (((int)response.StatusCode) == 0) throw new ApiException ((int)response.StatusCode, "Error calling AddPet: " + response.ErrorMessage, response.ErrorMessage); - } return; } @@ -305,7 +308,8 @@ namespace IO.Swagger.Api { /// /// Pet object that needs to be added to the store /// - public async Task AddPetAsync (Pet body) { + public async Task AddPetAsync (Pet body) + { var path = "/pet"; @@ -329,9 +333,9 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling AddPet: " + response.Content, response.Content); - } + return; } @@ -341,8 +345,8 @@ namespace IO.Swagger.Api { /// /// Status values that need to be considered for filter /// List - public List FindPetsByStatus (List status) { - + public List FindPetsByStatus (List status) + { var path = "/pet/findByStatus"; @@ -367,11 +371,10 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByStatus: " + response.Content, response.Content); - } else if (((int)response.StatusCode) == 0) { + else if (((int)response.StatusCode) == 0) throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByStatus: " + response.ErrorMessage, response.ErrorMessage); - } return (List) ApiClient.Deserialize(response.Content, typeof(List), response.Headers); } @@ -381,7 +384,8 @@ namespace IO.Swagger.Api { /// /// Status values that need to be considered for filter /// List - public async Task> FindPetsByStatusAsync (List status) { + public async Task> FindPetsByStatusAsync (List status) + { var path = "/pet/findByStatus"; @@ -405,9 +409,9 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByStatus: " + response.Content, response.Content); - } + return (List) ApiClient.Deserialize(response.Content, typeof(List), response.Headers); } @@ -416,8 +420,8 @@ namespace IO.Swagger.Api { /// /// Tags to filter by /// List - public List FindPetsByTags (List tags) { - + public List FindPetsByTags (List tags) + { var path = "/pet/findByTags"; @@ -442,11 +446,10 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByTags: " + response.Content, response.Content); - } else if (((int)response.StatusCode) == 0) { + else if (((int)response.StatusCode) == 0) throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByTags: " + response.ErrorMessage, response.ErrorMessage); - } return (List) ApiClient.Deserialize(response.Content, typeof(List), response.Headers); } @@ -456,7 +459,8 @@ namespace IO.Swagger.Api { /// /// Tags to filter by /// List - public async Task> FindPetsByTagsAsync (List tags) { + public async Task> FindPetsByTagsAsync (List tags) + { var path = "/pet/findByTags"; @@ -480,9 +484,9 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByTags: " + response.Content, response.Content); - } + return (List) ApiClient.Deserialize(response.Content, typeof(List), response.Headers); } @@ -491,8 +495,8 @@ namespace IO.Swagger.Api { /// /// ID of pet that needs to be fetched /// Pet - public Pet GetPetById (long? petId) { - + public Pet GetPetById (long? petId) + { // verify the required parameter 'petId' is set if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling GetPetById"); @@ -520,11 +524,10 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling GetPetById: " + response.Content, response.Content); - } else if (((int)response.StatusCode) == 0) { + else if (((int)response.StatusCode) == 0) throw new ApiException ((int)response.StatusCode, "Error calling GetPetById: " + response.ErrorMessage, response.ErrorMessage); - } return (Pet) ApiClient.Deserialize(response.Content, typeof(Pet), response.Headers); } @@ -534,7 +537,8 @@ namespace IO.Swagger.Api { /// /// ID of pet that needs to be fetched /// Pet - public async Task GetPetByIdAsync (long? petId) { + 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"); @@ -560,9 +564,9 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling GetPetById: " + response.Content, response.Content); - } + return (Pet) ApiClient.Deserialize(response.Content, typeof(Pet), response.Headers); } @@ -573,8 +577,8 @@ namespace IO.Swagger.Api { /// Updated name of the pet /// Updated status of the pet /// - public void UpdatePetWithForm (string petId, string name, string status) { - + public void UpdatePetWithForm (string petId, string name, string status) + { // verify the required parameter 'petId' is set if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling UpdatePetWithForm"); @@ -604,11 +608,10 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling UpdatePetWithForm: " + response.Content, response.Content); - } else if (((int)response.StatusCode) == 0) { + else if (((int)response.StatusCode) == 0) throw new ApiException ((int)response.StatusCode, "Error calling UpdatePetWithForm: " + response.ErrorMessage, response.ErrorMessage); - } return; } @@ -620,7 +623,8 @@ namespace IO.Swagger.Api { /// Updated name of the pet /// Updated status of the pet /// - public async Task UpdatePetWithFormAsync (string petId, string name, string status) { + public async Task UpdatePetWithFormAsync (string petId, string name, string status) + { // verify the required parameter 'petId' is set if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling UpdatePetWithForm"); @@ -648,9 +652,9 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling UpdatePetWithForm: " + response.Content, response.Content); - } + return; } @@ -661,8 +665,8 @@ namespace IO.Swagger.Api { /// /// Pet id to delete /// - public void DeletePet (string apiKey, long? petId) { - + public void DeletePet (string apiKey, long? petId) + { // verify the required parameter 'petId' is set if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling DeletePet"); @@ -691,11 +695,10 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling DeletePet: " + response.Content, response.Content); - } else if (((int)response.StatusCode) == 0) { + else if (((int)response.StatusCode) == 0) throw new ApiException ((int)response.StatusCode, "Error calling DeletePet: " + response.ErrorMessage, response.ErrorMessage); - } return; } @@ -706,7 +709,8 @@ namespace IO.Swagger.Api { /// /// Pet id to delete /// - public async Task DeletePetAsync (string apiKey, long? petId) { + public async Task DeletePetAsync (string apiKey, long? petId) + { // verify the required parameter 'petId' is set if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling DeletePet"); @@ -733,9 +737,9 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling DeletePet: " + response.Content, response.Content); - } + return; } @@ -747,8 +751,8 @@ namespace IO.Swagger.Api { /// Additional data to pass to server /// file to upload /// - public void UploadFile (long? petId, string additionalMetadata, Stream file) { - + public void UploadFile (long? petId, string additionalMetadata, Stream file) + { // verify the required parameter 'petId' is set if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling UploadFile"); @@ -778,11 +782,10 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling UploadFile: " + response.Content, response.Content); - } else if (((int)response.StatusCode) == 0) { + else if (((int)response.StatusCode) == 0) throw new ApiException ((int)response.StatusCode, "Error calling UploadFile: " + response.ErrorMessage, response.ErrorMessage); - } return; } @@ -794,7 +797,8 @@ namespace IO.Swagger.Api { /// Additional data to pass to server /// file to upload /// - public async Task UploadFileAsync (long? petId, string additionalMetadata, Stream file) { + public async Task UploadFileAsync (long? petId, string additionalMetadata, Stream file) + { // verify the required parameter 'petId' is set if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling UploadFile"); @@ -822,13 +826,13 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling UploadFile: " + response.Content, response.Content); - } + return; } - } + } } 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 6c337870706..8bb9056d1f7 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 @@ -6,9 +6,11 @@ using RestSharp; using IO.Swagger.Client; using IO.Swagger.Model; -namespace IO.Swagger.Api { +namespace IO.Swagger.Api +{ - public interface IStoreApi { + public interface IStoreApi + { /// /// Returns pet inventories by status Returns a map of status codes to quantities @@ -69,19 +71,19 @@ namespace IO.Swagger.Api { /// /// Represents a collection of functions to interact with the API endpoints /// - public class StoreApi : IStoreApi { - + 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 + public StoreApi(ApiClient apiClient = null) + { + if (apiClient == null) // use the default one in Configuration this.ApiClient = Configuration.DefaultApiClient; - } else { + else this.ApiClient = apiClient; - } } /// @@ -97,7 +99,8 @@ namespace IO.Swagger.Api { /// Sets the base path of the API client. /// /// The base path - public void SetBasePath(String basePath) { + public void SetBasePath(String basePath) + { this.ApiClient.BasePath = basePath; } @@ -105,14 +108,15 @@ namespace IO.Swagger.Api { /// Gets the base path of the API client. /// /// The base path - public String GetBasePath(String basePath) { + public String GetBasePath(String basePath) + { return this.ApiClient.BasePath; } /// /// Gets or sets the API client. /// - /// The API client + /// The API client. public ApiClient ApiClient {get; set;} @@ -120,8 +124,8 @@ namespace IO.Swagger.Api { /// Returns pet inventories by status Returns a map of status codes to quantities /// /// Dictionary - public Dictionary GetInventory () { - + public Dictionary GetInventory () + { var path = "/store/inventory"; @@ -145,11 +149,10 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling GetInventory: " + response.Content, response.Content); - } else if (((int)response.StatusCode) == 0) { + else if (((int)response.StatusCode) == 0) throw new ApiException ((int)response.StatusCode, "Error calling GetInventory: " + response.ErrorMessage, response.ErrorMessage); - } return (Dictionary) ApiClient.Deserialize(response.Content, typeof(Dictionary), response.Headers); } @@ -158,7 +161,8 @@ namespace IO.Swagger.Api { /// Returns pet inventories by status Returns a map of status codes to quantities /// /// Dictionary - public async Task> GetInventoryAsync () { + public async Task> GetInventoryAsync () + { var path = "/store/inventory"; @@ -181,9 +185,9 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling GetInventory: " + response.Content, response.Content); - } + return (Dictionary) ApiClient.Deserialize(response.Content, typeof(Dictionary), response.Headers); } @@ -192,8 +196,8 @@ namespace IO.Swagger.Api { /// /// order placed for purchasing the pet /// Order - public Order PlaceOrder (Order body) { - + public Order PlaceOrder (Order body) + { var path = "/store/order"; @@ -218,11 +222,10 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling PlaceOrder: " + response.Content, response.Content); - } else if (((int)response.StatusCode) == 0) { + else if (((int)response.StatusCode) == 0) throw new ApiException ((int)response.StatusCode, "Error calling PlaceOrder: " + response.ErrorMessage, response.ErrorMessage); - } return (Order) ApiClient.Deserialize(response.Content, typeof(Order), response.Headers); } @@ -232,7 +235,8 @@ namespace IO.Swagger.Api { /// /// order placed for purchasing the pet /// Order - public async Task PlaceOrderAsync (Order body) { + public async Task PlaceOrderAsync (Order body) + { var path = "/store/order"; @@ -256,9 +260,9 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling PlaceOrder: " + response.Content, response.Content); - } + return (Order) ApiClient.Deserialize(response.Content, typeof(Order), response.Headers); } @@ -267,8 +271,8 @@ namespace IO.Swagger.Api { /// /// ID of pet that needs to be fetched /// Order - public Order GetOrderById (string orderId) { - + public Order GetOrderById (string orderId) + { // verify the required parameter 'orderId' is set if (orderId == null) throw new ApiException(400, "Missing required parameter 'orderId' when calling GetOrderById"); @@ -296,11 +300,10 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling GetOrderById: " + response.Content, response.Content); - } else if (((int)response.StatusCode) == 0) { + else if (((int)response.StatusCode) == 0) throw new ApiException ((int)response.StatusCode, "Error calling GetOrderById: " + response.ErrorMessage, response.ErrorMessage); - } return (Order) ApiClient.Deserialize(response.Content, typeof(Order), response.Headers); } @@ -310,7 +313,8 @@ namespace IO.Swagger.Api { /// /// ID of pet that needs to be fetched /// Order - public async Task GetOrderByIdAsync (string orderId) { + 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"); @@ -336,9 +340,9 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling GetOrderById: " + response.Content, response.Content); - } + return (Order) ApiClient.Deserialize(response.Content, typeof(Order), response.Headers); } @@ -347,8 +351,8 @@ namespace IO.Swagger.Api { /// /// ID of the order that needs to be deleted /// - public void DeleteOrder (string orderId) { - + public void DeleteOrder (string orderId) + { // verify the required parameter 'orderId' is set if (orderId == null) throw new ApiException(400, "Missing required parameter 'orderId' when calling DeleteOrder"); @@ -376,11 +380,10 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling DeleteOrder: " + response.Content, response.Content); - } else if (((int)response.StatusCode) == 0) { + else if (((int)response.StatusCode) == 0) throw new ApiException ((int)response.StatusCode, "Error calling DeleteOrder: " + response.ErrorMessage, response.ErrorMessage); - } return; } @@ -390,7 +393,8 @@ namespace IO.Swagger.Api { /// /// ID of the order that needs to be deleted /// - public async Task DeleteOrderAsync (string orderId) { + public async Task DeleteOrderAsync (string orderId) + { // verify the required parameter 'orderId' is set if (orderId == null) throw new ApiException(400, "Missing required parameter 'orderId' when calling DeleteOrder"); @@ -416,13 +420,13 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling DeleteOrder: " + response.Content, response.Content); - } + return; } - } + } } 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 04c2c4e2dbb..934786eff3d 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 @@ -6,9 +6,11 @@ using RestSharp; using IO.Swagger.Client; using IO.Swagger.Model; -namespace IO.Swagger.Api { +namespace IO.Swagger.Api +{ - public interface IUserApi { + public interface IUserApi + { /// /// Create user This can only be done by the logged in user. @@ -129,19 +131,19 @@ namespace IO.Swagger.Api { /// /// Represents a collection of functions to interact with the API endpoints /// - public class UserApi : IUserApi { - + 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 + public UserApi(ApiClient apiClient = null) + { + if (apiClient == null) // use the default one in Configuration this.ApiClient = Configuration.DefaultApiClient; - } else { + else this.ApiClient = apiClient; - } } /// @@ -157,7 +159,8 @@ namespace IO.Swagger.Api { /// Sets the base path of the API client. /// /// The base path - public void SetBasePath(String basePath) { + public void SetBasePath(String basePath) + { this.ApiClient.BasePath = basePath; } @@ -165,14 +168,15 @@ namespace IO.Swagger.Api { /// Gets the base path of the API client. /// /// The base path - public String GetBasePath(String basePath) { + public String GetBasePath(String basePath) + { return this.ApiClient.BasePath; } /// /// Gets or sets the API client. /// - /// The API client + /// The API client. public ApiClient ApiClient {get; set;} @@ -181,8 +185,8 @@ namespace IO.Swagger.Api { /// /// Created user object /// - public void CreateUser (User body) { - + public void CreateUser (User body) + { var path = "/user"; @@ -207,11 +211,10 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling CreateUser: " + response.Content, response.Content); - } else if (((int)response.StatusCode) == 0) { + else if (((int)response.StatusCode) == 0) throw new ApiException ((int)response.StatusCode, "Error calling CreateUser: " + response.ErrorMessage, response.ErrorMessage); - } return; } @@ -221,7 +224,8 @@ namespace IO.Swagger.Api { /// /// Created user object /// - public async Task CreateUserAsync (User body) { + public async Task CreateUserAsync (User body) + { var path = "/user"; @@ -245,9 +249,9 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling CreateUser: " + response.Content, response.Content); - } + return; } @@ -257,8 +261,8 @@ namespace IO.Swagger.Api { /// /// List of user object /// - public void CreateUsersWithArrayInput (List body) { - + public void CreateUsersWithArrayInput (List body) + { var path = "/user/createWithArray"; @@ -283,11 +287,10 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithArrayInput: " + response.Content, response.Content); - } else if (((int)response.StatusCode) == 0) { + else if (((int)response.StatusCode) == 0) throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithArrayInput: " + response.ErrorMessage, response.ErrorMessage); - } return; } @@ -297,7 +300,8 @@ namespace IO.Swagger.Api { /// /// List of user object /// - public async Task CreateUsersWithArrayInputAsync (List body) { + public async Task CreateUsersWithArrayInputAsync (List body) + { var path = "/user/createWithArray"; @@ -321,9 +325,9 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithArrayInput: " + response.Content, response.Content); - } + return; } @@ -333,8 +337,8 @@ namespace IO.Swagger.Api { /// /// List of user object /// - public void CreateUsersWithListInput (List body) { - + public void CreateUsersWithListInput (List body) + { var path = "/user/createWithList"; @@ -359,11 +363,10 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithListInput: " + response.Content, response.Content); - } else if (((int)response.StatusCode) == 0) { + else if (((int)response.StatusCode) == 0) throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithListInput: " + response.ErrorMessage, response.ErrorMessage); - } return; } @@ -373,7 +376,8 @@ namespace IO.Swagger.Api { /// /// List of user object /// - public async Task CreateUsersWithListInputAsync (List body) { + public async Task CreateUsersWithListInputAsync (List body) + { var path = "/user/createWithList"; @@ -397,9 +401,9 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling CreateUsersWithListInput: " + response.Content, response.Content); - } + return; } @@ -410,8 +414,8 @@ namespace IO.Swagger.Api { /// The user name for login /// The password for login in clear text /// string - public string LoginUser (string username, string password) { - + public string LoginUser (string username, string password) + { var path = "/user/login"; @@ -437,11 +441,10 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling LoginUser: " + response.Content, response.Content); - } else if (((int)response.StatusCode) == 0) { + else if (((int)response.StatusCode) == 0) throw new ApiException ((int)response.StatusCode, "Error calling LoginUser: " + response.ErrorMessage, response.ErrorMessage); - } return (string) ApiClient.Deserialize(response.Content, typeof(string), response.Headers); } @@ -452,7 +455,8 @@ namespace IO.Swagger.Api { /// The user name for login /// The password for login in clear text /// string - public async Task LoginUserAsync (string username, string password) { + public async Task LoginUserAsync (string username, string password) + { var path = "/user/login"; @@ -477,9 +481,9 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling LoginUser: " + response.Content, response.Content); - } + return (string) ApiClient.Deserialize(response.Content, typeof(string), response.Headers); } @@ -487,8 +491,8 @@ namespace IO.Swagger.Api { /// Logs out current logged in user session /// /// - public void LogoutUser () { - + public void LogoutUser () + { var path = "/user/logout"; @@ -512,11 +516,10 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling LogoutUser: " + response.Content, response.Content); - } else if (((int)response.StatusCode) == 0) { + else if (((int)response.StatusCode) == 0) throw new ApiException ((int)response.StatusCode, "Error calling LogoutUser: " + response.ErrorMessage, response.ErrorMessage); - } return; } @@ -525,7 +528,8 @@ namespace IO.Swagger.Api { /// Logs out current logged in user session /// /// - public async Task LogoutUserAsync () { + public async Task LogoutUserAsync () + { var path = "/user/logout"; @@ -548,9 +552,9 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling LogoutUser: " + response.Content, response.Content); - } + return; } @@ -560,8 +564,8 @@ namespace IO.Swagger.Api { /// /// The name that needs to be fetched. Use user1 for testing. /// User - public User GetUserByName (string username) { - + public User GetUserByName (string username) + { // verify the required parameter 'username' is set if (username == null) throw new ApiException(400, "Missing required parameter 'username' when calling GetUserByName"); @@ -589,11 +593,10 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling GetUserByName: " + response.Content, response.Content); - } else if (((int)response.StatusCode) == 0) { + else if (((int)response.StatusCode) == 0) throw new ApiException ((int)response.StatusCode, "Error calling GetUserByName: " + response.ErrorMessage, response.ErrorMessage); - } return (User) ApiClient.Deserialize(response.Content, typeof(User), response.Headers); } @@ -603,7 +606,8 @@ namespace IO.Swagger.Api { /// /// The name that needs to be fetched. Use user1 for testing. /// User - public async Task GetUserByNameAsync (string username) { + 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"); @@ -629,9 +633,9 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling GetUserByName: " + response.Content, response.Content); - } + return (User) ApiClient.Deserialize(response.Content, typeof(User), response.Headers); } @@ -641,8 +645,8 @@ namespace IO.Swagger.Api { /// name that need to be deleted /// Updated user object /// - public void UpdateUser (string username, User body) { - + public void UpdateUser (string username, User body) + { // verify the required parameter 'username' is set if (username == null) throw new ApiException(400, "Missing required parameter 'username' when calling UpdateUser"); @@ -671,11 +675,10 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling UpdateUser: " + response.Content, response.Content); - } else if (((int)response.StatusCode) == 0) { + else if (((int)response.StatusCode) == 0) throw new ApiException ((int)response.StatusCode, "Error calling UpdateUser: " + response.ErrorMessage, response.ErrorMessage); - } return; } @@ -686,7 +689,8 @@ namespace IO.Swagger.Api { /// name that need to be deleted /// Updated user object /// - public async Task UpdateUserAsync (string username, User body) { + public async Task UpdateUserAsync (string username, User body) + { // verify the required parameter 'username' is set if (username == null) throw new ApiException(400, "Missing required parameter 'username' when calling UpdateUser"); @@ -713,9 +717,9 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling UpdateUser: " + response.Content, response.Content); - } + return; } @@ -725,8 +729,8 @@ namespace IO.Swagger.Api { /// /// The name that needs to be deleted /// - public void DeleteUser (string username) { - + public void DeleteUser (string username) + { // verify the required parameter 'username' is set if (username == null) throw new ApiException(400, "Missing required parameter 'username' when calling DeleteUser"); @@ -754,11 +758,10 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling DeleteUser: " + response.Content, response.Content); - } else if (((int)response.StatusCode) == 0) { + else if (((int)response.StatusCode) == 0) throw new ApiException ((int)response.StatusCode, "Error calling DeleteUser: " + response.ErrorMessage, response.ErrorMessage); - } return; } @@ -768,7 +771,8 @@ namespace IO.Swagger.Api { /// /// The name that needs to be deleted /// - public async Task DeleteUserAsync (string username) { + public async Task DeleteUserAsync (string username) + { // verify the required parameter 'username' is set if (username == null) throw new ApiException(400, "Missing required parameter 'username' when calling DeleteUser"); @@ -794,13 +798,13 @@ namespace IO.Swagger.Api { // make the HTTP request IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings); - if (((int)response.StatusCode) >= 400) { + if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling DeleteUser: " + response.Content, response.Content); - } + return; } - } + } } 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 1fd6a02213e..1b6198e3e7f 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 @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Text.RegularExpressions; using System.IO; +using System.Web; using System.Linq; using System.Net; using System.Text; @@ -10,222 +12,222 @@ using Newtonsoft.Json; using RestSharp; using RestSharp.Extensions; -namespace IO.Swagger.Client { +namespace IO.Swagger.Client +{ /// - /// API client is mainly responible for making the HTTP call to the API backend + /// API client is mainly responible for making the HTTP call to the API backend. /// - public class ApiClient { + public class ApiClient + { + private readonly Dictionary _defaultHeaderMap = new Dictionary(); /// - /// Initializes a new instance of the class. + /// 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); + public ApiClient(String basePath="http://petstore.swagger.io/v2") + { + BasePath = basePath; + RestClient = new RestClient(BasePath); } /// /// Gets or sets the base path. /// - /// The base path. public string BasePath { get; set; } /// - /// Gets or sets the RestClient + /// Gets or sets the RestClient. /// - /// The RestClient. public RestClient RestClient { get; set; } - private Dictionary DefaultHeaderMap = new Dictionary(); + /// + /// Gets the default header. + /// + public Dictionary DefaultHeader + { + get { return _defaultHeaderMap; } + } /// - /// Make the HTTP request (Sync) + /// Makes the HTTP request (Sync). /// - /// URL path - /// HTTP method - /// Query parameters - /// HTTP body (POST request) - /// Header parameters - /// Form parameters - /// File parameters - /// Authentication settings + /// URL path. + /// HTTP method. + /// Query parameters. + /// HTTP body (POST request). + /// Header parameters. + /// Form parameters. + /// File parameters. + /// Authentication settings. /// Object public Object CallApi(String path, RestSharp.Method method, Dictionary queryParams, String postBody, Dictionary headerParams, Dictionary formParams, - Dictionary fileParams, String[] authSettings) { + 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) + foreach(var defaultHeader in _defaultHeaderMap) request.AddHeader(defaultHeader.Key, defaultHeader.Value); // add header parameter, if any - foreach(KeyValuePair param in headerParams) + foreach(var param in headerParams) request.AddHeader(param.Key, param.Value); // add query parameter, if any - foreach(KeyValuePair param in queryParams) + foreach(var param in queryParams) request.AddQueryParameter(param.Key, param.Value); // add form parameter, if any - foreach(KeyValuePair param in formParams) + foreach(var param in formParams) request.AddParameter(param.Key, param.Value); // add file parameter, if any - foreach(KeyValuePair param in fileParams) + foreach(var param in fileParams) request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType); - - if (postBody != null) { - request.AddParameter("application/json", postBody, ParameterType.RequestBody); // http body (model) parameter - } + if (postBody != null) // http body (model) parameter + request.AddParameter("application/json", postBody, ParameterType.RequestBody); return (Object)RestClient.Execute(request); } /// - /// Make the HTTP request (Async) + /// Makes the asynchronous HTTP request. /// - /// URL path - /// HTTP method - /// Query parameters - /// HTTP body (POST request) - /// Header parameters - /// Form parameters - /// File parameters - /// Authentication settings - /// Task + /// URL path. + /// HTTP method. + /// Query parameters. + /// HTTP body (POST request). + /// Header parameters. + /// Form parameters. + /// File parameters. + /// Authentication settings. + /// The Task instance. public async Task CallApiAsync(String path, RestSharp.Method method, Dictionary queryParams, String postBody, - Dictionary headerParams, Dictionary formParams, Dictionary fileParams, String[] authSettings) { + 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) + foreach(var defaultHeader in _defaultHeaderMap) request.AddHeader(defaultHeader.Key, defaultHeader.Value); // add header parameter, if any - foreach(KeyValuePair param in headerParams) + foreach(var param in headerParams) request.AddHeader(param.Key, param.Value); // add query parameter, if any - foreach(KeyValuePair param in queryParams) + foreach(var param in queryParams) request.AddQueryParameter(param.Key, param.Value); // add form parameter, if any - foreach(KeyValuePair param in formParams) + foreach(var param in formParams) request.AddParameter(param.Key, param.Value); // add file parameter, if any - foreach(KeyValuePair param in fileParams) + foreach(var param in fileParams) request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType); - - - if (postBody != null) { - request.AddParameter("application/json", postBody, ParameterType.RequestBody); // http body (model) parameter - } + + if (postBody != null) // http body (model) parameter + request.AddParameter("application/json", postBody, ParameterType.RequestBody); return (Object) await RestClient.ExecuteTaskAsync(request); - } /// - /// Add default header + /// Add default header. /// - /// Header field name - /// Header field value + /// Header field name. + /// Header field value. /// - public void AddDefaultHeader(string key, string value) { - DefaultHeaderMap.Add(key, value); + public void AddDefaultHeader(string key, string value) + { + _defaultHeaderMap.Add(key, value); } /// - /// Get default header + /// Escape string (url-encoded). /// - /// Dictionary of default header - public Dictionary GetDefaultHeader() { - return DefaultHeaderMap; + /// String to be escaped. + /// Escaped string. + public string EscapeString(string str) + { + return HttpUtility.UrlEncode(str); } /// - /// escape string (url-encoded) + /// Create FileParameter based on Stream. /// - /// String to be escaped - /// Escaped string - public string EscapeString(string str) { - return str; - } - - /// - /// Create FileParameter based on Stream - /// - /// parameter name - /// Input stream - /// FileParameter + /// Parameter name. + /// Input stream. + /// FileParameter. public FileParameter ParameterToFile(string name, Stream stream) { - if (stream is FileStream) { + if (stream is FileStream) return FileParameter.Create(name, stream.ReadAsBytes(), Path.GetFileName(((FileStream)stream).Name)); - } else { + else return FileParameter.Create(name, stream.ReadAsBytes(), "no_file_name_provided"); - } } /// - /// if parameter is DateTime, output in ISO8601 format - /// if parameter is a list of string, join the list with "," - /// otherwise just return the string + /// If parameter is DateTime, output in ISO8601 format. + /// If parameter is a list of string, join the list with ",". + /// Otherwise just return the string. /// - /// The parameter (header, path, query, form) - /// Formatted string + /// The parameter (header, path, query, form). + /// Formatted string. public string ParameterToString(object obj) { - if (obj is DateTime) { + if (obj is DateTime) return ((DateTime)obj).ToString ("u"); - } else if (obj is List) { + else if (obj is List) return String.Join(",", obj as List); - } else { + else return Convert.ToString (obj); - } } /// - /// Deserialize the JSON string into a proper object + /// 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 == typeof(Object)) { // return an 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 == typeof(Object)) // return an object + { return (Object)content; - } else if (type == typeof(Stream)) { + } else if (type == typeof(Stream)) + { String fileName, filePath; - if (String.IsNullOrEmpty (Configuration.TempFolderPath)) { + if (String.IsNullOrEmpty (Configuration.TempFolderPath)) filePath = System.IO.Path.GetTempPath (); - } else { + else filePath = Configuration.TempFolderPath; - } - + Regex regex = new Regex(@"Content-Disposition:.*filename=['""]?([^'""\s]+)['""]?$"); Match match = regex.Match(headers.ToString()); - if (match.Success) { - // replace first and last " or ', if found + if (match.Success) // replace first and last " or ', if found fileName = filePath + match.Value.Replace("\"", "").Replace("'",""); - } else { + else fileName = filePath + Guid.NewGuid().ToString(); - } + File.WriteAllText (fileName, content); return new FileStream(fileName, FileMode.Open); - } else if (type.Name.StartsWith("System.Nullable`1[[System.DateTime")) { // return a datetime object + } else if (type.Name.StartsWith("System.Nullable`1[[System.DateTime")) // return a datetime object + { return DateTime.Parse(content, null, System.Globalization.DateTimeStyles.RoundtripKind); - } else if (type.Name == "String" || type.Name.StartsWith("System.Nullable")) { // return primitive + } else if (type.Name == "String" || type.Name.StartsWith("System.Nullable")) // return primitive type + { return ConvertType(content, type); } @@ -234,56 +236,61 @@ namespace IO.Swagger.Client { { return JsonConvert.DeserializeObject(content, type); } - catch (IOException e) { + catch (IOException e) + { throw new ApiException(500, e.Message); } } /// - /// Serialize an object into JSON string + /// Serialize an object into JSON string. /// - /// Object - /// JSON string - public string Serialize(object obj) { + /// Object. + /// JSON string. + public string Serialize(object obj) + { try { return obj != null ? JsonConvert.SerializeObject(obj) : null; } - catch (Exception e) { + catch (Exception e) + { throw new ApiException(500, e.Message); } } /// - /// Get the API key with prefix + /// Get the API key with prefix. /// - /// Object - /// API key with prefix + /// API key identifier (authentication scheme). + /// 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)) { + if (Configuration.ApiKeyPrefix.TryGetValue (apiKeyIdentifier, out apiKeyPrefix)) return apiKeyPrefix + " " + apiKeyValue; - } else { + else return apiKeyValue; - } } /// - /// Update parameters based on authentication + /// Update parameters based on authentication. /// - /// Query parameters - /// Header parameters - /// Authentication settings - public void UpdateParamsForAuth(Dictionary queryParams, Dictionary headerParams, string[] authSettings) { + /// 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) { + foreach (string auth in authSettings) + { // determine which one to use - switch(auth) { + switch(auth) + { case "api_key": headerParams["api_key"] = GetApiKeyWithPrefix("api_key"); @@ -300,24 +307,26 @@ namespace IO.Swagger.Client { break; } } - } /// - /// Encode string in base64 format + /// Encode string in base64 format. /// - /// String to be encoded - public static string Base64Encode(string text) { + /// String to be encoded. + /// Encoded string. + 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 + /// Dynamically cast the object into target type. /// Ref: http://stackoverflow.com/questions/4925718/c-dynamic-runtime-cast /// - /// Object to be casted + /// Object to be casted /// Target type + /// Casted object public static dynamic ConvertType(dynamic source, Type dest) { return Convert.ChangeType(source, dest); } diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/Configuration.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/Configuration.cs index 56ce39eadbe..b875606e6c9 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/Configuration.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/Configuration.cs @@ -3,18 +3,20 @@ using System.Reflection; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Net; using System.Text; -namespace IO.Swagger.Client { +namespace IO.Swagger.Client +{ /// /// Represents a set of configuration settings /// - public class Configuration{ + public class Configuration + { /// - /// Version of the package + /// Version of the package. /// + /// Version of the package. public const string Version = "1.0.0"; /// @@ -24,25 +26,25 @@ namespace IO.Swagger.Client { public static ApiClient DefaultApiClient = new ApiClient(); /// - /// Gets or sets the username (HTTP basic authentication) + /// Gets or sets the username (HTTP basic authentication). /// /// The username. public static String Username { get; set; } /// - /// Gets or sets the password (HTTP basic authentication) + /// Gets or sets the password (HTTP basic authentication). /// /// The password. public static String Password { get; set; } /// - /// Gets or sets the API key based on the authentication name + /// Gets or sets the API key based on the authentication name. /// /// The API key. public static Dictionary ApiKey = new Dictionary(); /// - /// Gets or sets the prefix (e.g. Token) of the API key based on the authentication name + /// Gets or sets the prefix (e.g. Token) of the API key based on the authentication name. /// /// The prefix of the API key. public static Dictionary ApiKeyPrefix = new Dictionary(); @@ -50,46 +52,46 @@ namespace IO.Swagger.Client { private static string _tempFolderPath = Path.GetTempPath(); /// - /// Gets or sets the temporary folder path to store the files downloaded from the server + /// Gets or sets the temporary folder path to store the files downloaded from the server. /// - /// Folder path - public static String TempFolderPath { - get { - return _tempFolderPath; - } + /// Folder path. + public static String TempFolderPath + { + get { return _tempFolderPath; } - set { - if (String.IsNullOrEmpty(value)) { + set + { + if (String.IsNullOrEmpty(value)) + { _tempFolderPath = value; return; } // create the directory if it does not exist - if (!Directory.Exists(value)) { + if (!Directory.Exists(value)) Directory.CreateDirectory(value); - } // check if the path contains directory separator at the end - if (value[value.Length - 1] == Path.DirectorySeparatorChar) { + if (value[value.Length - 1] == Path.DirectorySeparatorChar) _tempFolderPath = value; - } else { + else _tempFolderPath = value + Path.DirectorySeparatorChar; - } } } /// - /// Return a string contain essential information for debugging + /// Returns a string with essential information for debugging. /// - /// Folder path - public static String ToDebugReport() { + /// Debugging Report + public static String ToDebugReport() + { String report = "C# SDK () Debug Report:\n"; report += " OS: " + Environment.OSVersion + "\n"; report += " .NET Framework Version: " + Assembly .GetExecutingAssembly() .GetReferencedAssemblies() .Where(x => x.Name == "System.Core").First().Version.ToString() + "\n"; - report += " Swagger Spec Version: 1.0.0\n"; + report += " Version of the API: 1.0.0\n"; report += " SDK Package Version: 1.0.0\n"; return report; diff --git a/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.csproj b/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.csproj index 373b3ee3779..670402c0cd2 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.csproj +++ b/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.csproj @@ -40,6 +40,7 @@ packages\NUnit.2.6.4\lib\nunit.framework.dll + diff --git a/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs b/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs index 5a5f6ebb92c..6dc436a4642 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs +++ b/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs @@ -2,7 +2,7 @@ - + diff --git a/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll b/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll index 378be56e081..a120d21961c 100755 Binary files a/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll and b/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll differ 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 6e9caa87e2b..fc4d75c3a45 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 b/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll index 378be56e081..a120d21961c 100755 Binary files a/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll and b/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll 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 6e9caa87e2b..fc4d75c3a45 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