diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java index 33ea13b5e31..4f7ad02b95d 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java @@ -68,7 +68,7 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig typeMapping.put("number", "double?"); typeMapping.put("datetime", "DateTime?"); typeMapping.put("date", "DateTime?"); - typeMapping.put("file", "string"); // path to file + typeMapping.put("file", "FileStream"); typeMapping.put("array", "List"); typeMapping.put("list", "List"); typeMapping.put("map", "Dictionary"); diff --git a/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache index c6f57bd4a37..5c1fb8d9125 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Text.RegularExpressions; using System.IO; using System.Linq; using System.Net; @@ -19,21 +20,21 @@ namespace {{packageName}}.Client { /// /// The base path. public ApiClient(String basePath="{{basePath}}") { - this.basePath = basePath; - this.restClient = new RestClient(this.basePath); + this.BasePath = basePath; + this.RestClient = new RestClient(this.BasePath); } /// /// Gets or sets the base path. /// /// The base path. - public string basePath { get; set; } + public string BasePath { get; set; } /// /// Gets or sets the RestClient /// /// The RestClient. - public RestClient restClient { get; set; } + public RestClient RestClient { get; set; } private Dictionary defaultHeaderMap = new Dictionary(); @@ -77,7 +78,7 @@ namespace {{packageName}}.Client { request.AddParameter("application/json", PostBody, ParameterType.RequestBody); // http body (model) parameter } - return (Object) await restClient.ExecuteTaskAsync(request); + return (Object) await RestClient.ExecuteTaskAsync(request); } @@ -119,10 +120,12 @@ namespace {{packageName}}.Client { { if (obj is DateTime) { return ((DateTime)obj).ToString ("u"); + } else if (obj is FileStream) { + return ((FileStream)obj).Name; } else if (obj is List) { return String.Join(",", obj as List); } else { - return Convert.ToString (obj); + return Convert.ToString (obj); } } @@ -132,16 +135,38 @@ namespace {{packageName}}.Client { /// JSON string /// Object type /// Object representation of the JSON string - public object Deserialize(string content, Type type) { - if (type.GetType() == typeof(Object)) - return (Object)content; + public object Deserialize(string content, Type type, IList headers=null) { + if (type.GetType() == typeof(Object)) { + return (Object)content; + } else if (type.Name == "FileStream") { + // e.g. Content-Disposition: attachment; filename=checkimage.jpp + String fileName; + String 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(); + } + System.IO.File.WriteAllText (fileName, content); + return File.Open (fileName, FileMode.Open); + } + try { return JsonConvert.DeserializeObject(content, type); } catch (IOException e) { - throw new ApiException(500, e.Message); + throw new ApiException(500, e.Message); } } @@ -165,12 +190,12 @@ namespace {{packageName}}.Client { /// /// Object /// API key with prefix - public string GetApiKeyWithPrefix (string apiKey) + public string GetApiKeyWithPrefix (string apiKeyIdentifier) { var apiKeyValue = ""; - Configuration.apiKey.TryGetValue (apiKey, out apiKeyValue); + Configuration.ApiKey.TryGetValue (apiKeyIdentifier, out apiKeyValue); var apiKeyPrefix = ""; - if (Configuration.apiKeyPrefix.TryGetValue (apiKey, out apiKeyPrefix)) { + if (Configuration.ApiKeyPrefix.TryGetValue (apiKeyIdentifier, out apiKeyPrefix)) { return apiKeyPrefix + " " + apiKeyValue; } else { return apiKeyValue; @@ -192,7 +217,7 @@ namespace {{packageName}}.Client { 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}} + {{#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}} diff --git a/modules/swagger-codegen/src/main/resources/csharp/Configuration.mustache b/modules/swagger-codegen/src/main/resources/csharp/Configuration.mustache index 485d97058ce..8611d2c18b4 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/Configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/Configuration.mustache @@ -1,4 +1,5 @@ using System; +using System.Reflection; using System.Collections.Generic; using System.IO; using System.Linq; @@ -17,35 +18,81 @@ namespace {{packageName}}.Client { public const string Version = "{{packageVersion}}"; /// - /// Gets or sets the API client. This is the default API client for making HTTP calls. + /// Gets or sets the default API client for making HTTP calls. /// /// The API client. - public static ApiClient apiClient = new ApiClient(); + public static ApiClient DefaultApiClient = new ApiClient(); /// /// Gets or sets the username (HTTP basic authentication) /// /// The username. - public static String username { get; set; } + public static String Username { get; set; } /// /// Gets or sets the password (HTTP basic authentication) /// /// The password. - public static String password { get; set; } + public static String Password { get; set; } /// /// Gets or sets the API key based on the authentication name /// /// The API key. - public static Dictionary apiKey = new Dictionary(); + public static Dictionary ApiKey = new Dictionary(); /// /// 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(); + public static Dictionary ApiKeyPrefix = new Dictionary(); + private static string _tempFolderPath = Path.GetTempPath(); + /// + /// Gets or sets the temporary folder path to store the files downloaded from the server + /// + /// Folder path + public static String TempFolderPath { + get { + return _tempFolderPath; + } + + set { + if (!String.IsNullOrEmpty(value)) { + _tempFolderPath = value; + return; + } + + // create the directory if it does not exist + if (!Directory.Exists(value)) { + Directory.CreateDirectory(value); + } + + // check if the path contains directory separator at the end + if (value[value.Length - 1] == Path.DirectorySeparatorChar) { + _tempFolderPath = value; + } else { + _tempFolderPath = value + Path.DirectorySeparatorChar; + } + } + } + + /// + /// Return a string contain essential information for debugging + /// + /// Folder path + 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 += " SDK Package Version: {{version}}\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 652d15a30b3..1ae7afbf39a 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/api.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/api.mustache @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Collections.Generic; using System.Threading.Tasks; using RestSharp; @@ -15,15 +16,15 @@ namespace {{packageName}}.Api { /// /// {{summary}} {{notes}} /// - {{#allParams}}/// {{description}}{{/allParams}} - /// {{#returnType}}{{{returnType}}}{{/returnType}} + {{#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}} + {{#allParams}}/// {{description}} + {{/allParams}}/// {{#returnType}}{{{returnType}}}{{/returnType}} {{#returnType}}Task<{{{returnType}}}>{{/returnType}}{{^returnType}}Task{{/returnType}} {{nickname}}Async ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); {{/operation}} } @@ -40,9 +41,9 @@ namespace {{packageName}}.Api { /// public {{classname}}(ApiClient apiClient = null) { if (apiClient == null) { // use the default one in Configuration - this.apiClient = Configuration.apiClient; + this.ApiClient = Configuration.DefaultApiClient; } else { - this.apiClient = apiClient; + this.ApiClient = apiClient; } } @@ -52,7 +53,7 @@ namespace {{packageName}}.Api { /// public {{classname}}(String basePath) { - this.apiClient = new ApiClient(basePath); + this.ApiClient = new ApiClient(basePath); } /// @@ -60,7 +61,7 @@ namespace {{packageName}}.Api { /// /// The base path public void SetBasePath(String basePath) { - this.apiClient.basePath = basePath; + this.ApiClient.BasePath = basePath; } /// @@ -68,22 +69,22 @@ namespace {{packageName}}.Api { /// /// The base path public String GetBasePath(String basePath) { - return this.apiClient.basePath; + return this.ApiClient.BasePath; } /// /// Gets or sets the API client. /// /// The API client - public ApiClient apiClient {get; set;} + public ApiClient ApiClient {get; set;} {{#operation}} /// /// {{summary}} {{notes}} /// - {{#allParams}}/// {{description}}{{/allParams}} - /// {{#returnType}}{{{returnType}}}{{/returnType}} + {{#allParams}}/// {{description}} + {{/allParams}}/// {{#returnType}}{{{returnType}}}{{/returnType}} public {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { {{#allParams}}{{#required}} @@ -93,7 +94,7 @@ namespace {{packageName}}.Api { var path = "{{path}}"; path = path.Replace("{format}", "json"); - {{#pathParams}}path = path.Replace("{" + "{{baseName}}" + "}", apiClient.ParameterToString({{{paramName}}})); + {{#pathParams}}path = path.Replace("{" + "{{baseName}}" + "}", ApiClient.ParameterToString({{{paramName}}})); {{/pathParams}} var queryParams = new Dictionary(); @@ -102,33 +103,33 @@ namespace {{packageName}}.Api { var fileParams = new Dictionary(); String postBody = null; - {{#queryParams}} if ({{paramName}} != null) queryParams.Add("{{baseName}}", apiClient.ParameterToString({{paramName}})); // query parameter + {{#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}} if ({{paramName}} != null) headerParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // header parameter {{/headerParams}} - {{#formParams}}if ({{paramName}} != null) {{#isFile}}fileParams.Add("{{baseName}}", {{paramName}});{{/isFile}}{{^isFile}}formParams.Add("{{baseName}}", apiClient.ParameterToString({{paramName}})); // form parameter{{/isFile}} + {{#formParams}}if ({{paramName}} != null) {{#isFile}}fileParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}}));{{/isFile}}{{^isFile}}formParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // form parameter{{/isFile}} {{/formParams}} - {{#bodyParam}}postBody = apiClient.Serialize({{paramName}}); // http body (model) parameter + {{#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); + 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}}}));{{/returnType}}{{^returnType}} + {{#returnType}}return ({{{returnType}}}) ApiClient.Deserialize(response.Content, typeof({{{returnType}}}));{{/returnType}}{{^returnType}} return;{{/returnType}} } - - /// + + /// /// {{summary}} {{notes}} /// - {{#allParams}}/// {{description}}{{/allParams}} - /// {{#returnType}}{{{returnType}}}{{/returnType}} + {{#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}} @@ -138,7 +139,7 @@ namespace {{packageName}}.Api { var path = "{{path}}"; path = path.Replace("{format}", "json"); - {{#pathParams}}path = path.Replace("{" + "{{baseName}}" + "}", apiClient.ParameterToString({{{paramName}}})); + {{#pathParams}}path = path.Replace("{" + "{{baseName}}" + "}", ApiClient.ParameterToString({{{paramName}}})); {{/pathParams}} var queryParams = new Dictionary(); @@ -147,24 +148,24 @@ namespace {{packageName}}.Api { var fileParams = new Dictionary(); String postBody = null; - {{#queryParams}} if ({{paramName}} != null) queryParams.Add("{{baseName}}", apiClient.ParameterToString({{paramName}})); // query parameter + {{#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}} if ({{paramName}} != null) headerParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // header parameter {{/headerParams}} - {{#formParams}}if ({{paramName}} != null) {{#isFile}}fileParams.Add("{{baseName}}", {{paramName}});{{/isFile}}{{^isFile}}formParams.Add("{{baseName}}", apiClient.ParameterToString({{paramName}})); // form parameter{{/isFile}} + {{#formParams}}if ({{paramName}} != null) {{#isFile}}fileParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}}));{{/isFile}}{{^isFile}}formParams.Add("{{baseName}}", ApiClient.ParameterToString({{paramName}})); // form parameter{{/isFile}} {{/formParams}} - {{#bodyParam}}postBody = apiClient.Serialize({{paramName}}); // http body (model) parameter + {{#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); + 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}}}));{{/returnType}}{{^returnType}} + {{#returnType}}return ({{{returnType}}}) ApiClient.Deserialize(response.Content, typeof({{{returnType}}}));{{/returnType}}{{^returnType}} return;{{/returnType}} } {{/operation}} 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 5fdb38f2da9..f41cb46baa1 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 @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Collections.Generic; using System.Threading.Tasks; using RestSharp; @@ -83,44 +84,54 @@ namespace IO.Swagger.Api { /// /// 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 + /// 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 + /// 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 + /// + /// Pet id to delete /// void DeletePet (string ApiKey, long? PetId); /// /// Deletes a pet /// - /// /// Pet id to delete + /// + /// 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 + /// ID of pet to update + /// Additional data to pass to server + /// file to upload /// - void UploadFile (long? PetId, string AdditionalMetadata, string File); + void UploadFile (long? PetId, string AdditionalMetadata, FileStream File); /// /// uploads an image /// - /// ID of pet to update/// Additional data to pass to server/// file to upload + /// ID of pet to update + /// Additional data to pass to server + /// file to upload /// - Task UploadFileAsync (long? PetId, string AdditionalMetadata, string File); + Task UploadFileAsync (long? PetId, string AdditionalMetadata, FileStream File); } @@ -136,9 +147,9 @@ namespace IO.Swagger.Api { /// public PetApi(ApiClient apiClient = null) { if (apiClient == null) { // use the default one in Configuration - this.apiClient = Configuration.apiClient; + this.ApiClient = Configuration.DefaultApiClient; } else { - this.apiClient = apiClient; + this.ApiClient = apiClient; } } @@ -148,7 +159,7 @@ namespace IO.Swagger.Api { /// public PetApi(String basePath) { - this.apiClient = new ApiClient(basePath); + this.ApiClient = new ApiClient(basePath); } /// @@ -156,7 +167,7 @@ namespace IO.Swagger.Api { /// /// The base path public void SetBasePath(String basePath) { - this.apiClient.basePath = basePath; + this.ApiClient.BasePath = basePath; } /// @@ -164,14 +175,14 @@ namespace IO.Swagger.Api { /// /// The base path public String GetBasePath(String basePath) { - return this.apiClient.basePath; + return this.ApiClient.BasePath; } /// /// Gets or sets the API client. /// /// The API client - public ApiClient apiClient {get; set;} + public ApiClient ApiClient {get; set;} @@ -197,14 +208,14 @@ namespace IO.Swagger.Api { - postBody = apiClient.Serialize(Body); // http body (model) parameter + postBody = ApiClient.Serialize(Body); // http body (model) parameter // authentication setting, if any String[] authSettings = new String[] { "petstore_auth" }; // make the HTTP request - IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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); @@ -212,8 +223,8 @@ namespace IO.Swagger.Api { return; } - - /// + + /// /// Update an existing pet /// /// Pet object that needs to be added to the store @@ -235,14 +246,14 @@ namespace IO.Swagger.Api { - postBody = apiClient.Serialize(Body); // http body (model) parameter + postBody = ApiClient.Serialize(Body); // http body (model) parameter // authentication setting, if any String[] authSettings = new String[] { "petstore_auth" }; // make the HTTP request - IRestResponse response = (IRestResponse) await apiClient.CallApiAsync(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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); } @@ -272,14 +283,14 @@ namespace IO.Swagger.Api { - postBody = apiClient.Serialize(Body); // http body (model) parameter + postBody = ApiClient.Serialize(Body); // http body (model) parameter // authentication setting, if any String[] authSettings = new String[] { "petstore_auth" }; // make the HTTP request - IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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); @@ -287,8 +298,8 @@ namespace IO.Swagger.Api { return; } - - /// + + /// /// Add a new pet to the store /// /// Pet object that needs to be added to the store @@ -310,14 +321,14 @@ namespace IO.Swagger.Api { - postBody = apiClient.Serialize(Body); // http body (model) parameter + postBody = ApiClient.Serialize(Body); // http body (model) parameter // authentication setting, if any String[] authSettings = new String[] { "petstore_auth" }; // make the HTTP request - IRestResponse response = (IRestResponse) await apiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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); } @@ -344,7 +355,7 @@ namespace IO.Swagger.Api { var fileParams = new Dictionary(); String postBody = null; - if (Status != null) queryParams.Add("status", apiClient.ParameterToString(Status)); // query parameter + if (Status != null) queryParams.Add("status", ApiClient.ParameterToString(Status)); // query parameter @@ -354,15 +365,15 @@ namespace IO.Swagger.Api { String[] authSettings = new String[] { "petstore_auth" }; // make the HTTP request - IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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)); + return (List) ApiClient.Deserialize(response.Content, typeof(List)); } - - /// + + /// /// Finds Pets by status Multiple status values can be provided with comma seperated strings /// /// Status values that need to be considered for filter @@ -381,7 +392,7 @@ namespace IO.Swagger.Api { var fileParams = new Dictionary(); String postBody = null; - if (Status != null) queryParams.Add("status", apiClient.ParameterToString(Status)); // query parameter + if (Status != null) queryParams.Add("status", ApiClient.ParameterToString(Status)); // query parameter @@ -391,11 +402,11 @@ namespace IO.Swagger.Api { 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); + 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)); + return (List) ApiClient.Deserialize(response.Content, typeof(List)); } /// @@ -417,7 +428,7 @@ namespace IO.Swagger.Api { var fileParams = new Dictionary(); String postBody = null; - if (Tags != null) queryParams.Add("tags", apiClient.ParameterToString(Tags)); // query parameter + if (Tags != null) queryParams.Add("tags", ApiClient.ParameterToString(Tags)); // query parameter @@ -427,15 +438,15 @@ namespace IO.Swagger.Api { String[] authSettings = new String[] { "petstore_auth" }; // make the HTTP request - IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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)); + return (List) ApiClient.Deserialize(response.Content, typeof(List)); } - - /// + + /// /// Finds Pets by tags Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. /// /// Tags to filter by @@ -454,7 +465,7 @@ namespace IO.Swagger.Api { var fileParams = new Dictionary(); String postBody = null; - if (Tags != null) queryParams.Add("tags", apiClient.ParameterToString(Tags)); // query parameter + if (Tags != null) queryParams.Add("tags", ApiClient.ParameterToString(Tags)); // query parameter @@ -464,11 +475,11 @@ namespace IO.Swagger.Api { 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); + 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)); + return (List) ApiClient.Deserialize(response.Content, typeof(List)); } /// @@ -485,7 +496,7 @@ namespace IO.Swagger.Api { var path = "/pet/{petId}"; path = path.Replace("{format}", "json"); - path = path.Replace("{" + "petId" + "}", apiClient.ParameterToString(PetId)); + path = path.Replace("{" + "petId" + "}", ApiClient.ParameterToString(PetId)); var queryParams = new Dictionary(); @@ -503,15 +514,15 @@ namespace IO.Swagger.Api { 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); + 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)); + return (Pet) ApiClient.Deserialize(response.Content, typeof(Pet)); } - - /// + + /// /// 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 @@ -525,7 +536,7 @@ namespace IO.Swagger.Api { var path = "/pet/{petId}"; path = path.Replace("{format}", "json"); - path = path.Replace("{" + "petId" + "}", apiClient.ParameterToString(PetId)); + path = path.Replace("{" + "petId" + "}", ApiClient.ParameterToString(PetId)); var queryParams = new Dictionary(); @@ -543,17 +554,19 @@ namespace IO.Swagger.Api { 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); + 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)); + return (Pet) ApiClient.Deserialize(response.Content, typeof(Pet)); } /// /// 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 + /// 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) { @@ -564,7 +577,7 @@ namespace IO.Swagger.Api { var path = "/pet/{petId}"; path = path.Replace("{format}", "json"); - path = path.Replace("{" + "petId" + "}", apiClient.ParameterToString(PetId)); + path = path.Replace("{" + "petId" + "}", ApiClient.ParameterToString(PetId)); var queryParams = new Dictionary(); @@ -575,8 +588,8 @@ namespace IO.Swagger.Api { - if (Name != null) formParams.Add("name", apiClient.ParameterToString(Name)); // form parameter - if (Status != null) formParams.Add("status", apiClient.ParameterToString(Status)); // form parameter + if (Name != null) formParams.Add("name", ApiClient.ParameterToString(Name)); // form parameter + if (Status != null) formParams.Add("status", ApiClient.ParameterToString(Status)); // form parameter @@ -584,7 +597,7 @@ namespace IO.Swagger.Api { String[] authSettings = new String[] { "petstore_auth" }; // make the HTTP request - IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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); @@ -592,11 +605,13 @@ namespace IO.Swagger.Api { 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 + /// 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) { @@ -607,7 +622,7 @@ namespace IO.Swagger.Api { var path = "/pet/{petId}"; path = path.Replace("{format}", "json"); - path = path.Replace("{" + "petId" + "}", apiClient.ParameterToString(PetId)); + path = path.Replace("{" + "petId" + "}", ApiClient.ParameterToString(PetId)); var queryParams = new Dictionary(); @@ -618,8 +633,8 @@ namespace IO.Swagger.Api { - if (Name != null) formParams.Add("name", apiClient.ParameterToString(Name)); // form parameter - if (Status != null) formParams.Add("status", apiClient.ParameterToString(Status)); // form parameter + if (Name != null) formParams.Add("name", ApiClient.ParameterToString(Name)); // form parameter + if (Status != null) formParams.Add("status", ApiClient.ParameterToString(Status)); // form parameter @@ -627,7 +642,7 @@ namespace IO.Swagger.Api { 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); + 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); } @@ -638,7 +653,8 @@ namespace IO.Swagger.Api { /// /// Deletes a pet /// - /// /// Pet id to delete + /// + /// Pet id to delete /// public void DeletePet (string ApiKey, long? PetId) { @@ -649,7 +665,7 @@ namespace IO.Swagger.Api { var path = "/pet/{petId}"; path = path.Replace("{format}", "json"); - path = path.Replace("{" + "petId" + "}", apiClient.ParameterToString(PetId)); + path = path.Replace("{" + "petId" + "}", ApiClient.ParameterToString(PetId)); var queryParams = new Dictionary(); @@ -659,7 +675,7 @@ namespace IO.Swagger.Api { String postBody = null; - if (ApiKey != null) headerParams.Add("api_key", apiClient.ParameterToString(ApiKey)); // header parameter + if (ApiKey != null) headerParams.Add("api_key", ApiClient.ParameterToString(ApiKey)); // header parameter @@ -668,7 +684,7 @@ namespace IO.Swagger.Api { String[] authSettings = new String[] { "petstore_auth" }; // make the HTTP request - IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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); @@ -676,11 +692,12 @@ namespace IO.Swagger.Api { return; } - - /// + + /// /// Deletes a pet /// - /// /// Pet id to delete + /// + /// Pet id to delete /// public async Task DeletePetAsync (string ApiKey, long? PetId) { @@ -691,7 +708,7 @@ namespace IO.Swagger.Api { var path = "/pet/{petId}"; path = path.Replace("{format}", "json"); - path = path.Replace("{" + "petId" + "}", apiClient.ParameterToString(PetId)); + path = path.Replace("{" + "petId" + "}", ApiClient.ParameterToString(PetId)); var queryParams = new Dictionary(); @@ -701,7 +718,7 @@ namespace IO.Swagger.Api { String postBody = null; - if (ApiKey != null) headerParams.Add("api_key", apiClient.ParameterToString(ApiKey)); // header parameter + if (ApiKey != null) headerParams.Add("api_key", ApiClient.ParameterToString(ApiKey)); // header parameter @@ -710,7 +727,7 @@ namespace IO.Swagger.Api { 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); + 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); } @@ -721,9 +738,11 @@ namespace IO.Swagger.Api { /// /// uploads an image /// - /// ID of pet to update/// Additional data to pass to server/// file to upload + /// ID of pet to update + /// Additional data to pass to server + /// file to upload /// - public void UploadFile (long? PetId, string AdditionalMetadata, string File) { + public void UploadFile (long? PetId, string AdditionalMetadata, FileStream File) { // verify the required parameter 'PetId' is set @@ -732,7 +751,7 @@ namespace IO.Swagger.Api { var path = "/pet/{petId}/uploadImage"; path = path.Replace("{format}", "json"); - path = path.Replace("{" + "petId" + "}", apiClient.ParameterToString(PetId)); + path = path.Replace("{" + "petId" + "}", ApiClient.ParameterToString(PetId)); var queryParams = new Dictionary(); @@ -743,8 +762,8 @@ namespace IO.Swagger.Api { - if (AdditionalMetadata != null) formParams.Add("additionalMetadata", apiClient.ParameterToString(AdditionalMetadata)); // form parameter - if (File != null) fileParams.Add("file", File); + if (AdditionalMetadata != null) formParams.Add("additionalMetadata", ApiClient.ParameterToString(AdditionalMetadata)); // form parameter + if (File != null) fileParams.Add("file", ApiClient.ParameterToString(File)); @@ -752,7 +771,7 @@ namespace IO.Swagger.Api { String[] authSettings = new String[] { "petstore_auth" }; // make the HTTP request - IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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); @@ -760,13 +779,15 @@ namespace IO.Swagger.Api { return; } - - /// + + /// /// uploads an image /// - /// ID of pet to update/// Additional data to pass to server/// file to upload + /// ID of pet to update + /// Additional data to pass to server + /// file to upload /// - public async Task UploadFileAsync (long? PetId, string AdditionalMetadata, string File) { + public async Task UploadFileAsync (long? PetId, string AdditionalMetadata, FileStream File) { // verify the required parameter 'PetId' is set @@ -775,7 +796,7 @@ namespace IO.Swagger.Api { var path = "/pet/{petId}/uploadImage"; path = path.Replace("{format}", "json"); - path = path.Replace("{" + "petId" + "}", apiClient.ParameterToString(PetId)); + path = path.Replace("{" + "petId" + "}", ApiClient.ParameterToString(PetId)); var queryParams = new Dictionary(); @@ -786,8 +807,8 @@ namespace IO.Swagger.Api { - if (AdditionalMetadata != null) formParams.Add("additionalMetadata", apiClient.ParameterToString(AdditionalMetadata)); // form parameter - if (File != null) fileParams.Add("file", File); + if (AdditionalMetadata != null) formParams.Add("additionalMetadata", ApiClient.ParameterToString(AdditionalMetadata)); // form parameter + if (File != null) fileParams.Add("file", ApiClient.ParameterToString(File)); @@ -795,7 +816,7 @@ namespace IO.Swagger.Api { 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); + 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); } 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 739c9d30be3..b728accf45e 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 @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Collections.Generic; using System.Threading.Tasks; using RestSharp; @@ -13,14 +14,12 @@ namespace IO.Swagger.Api { /// /// 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 (); @@ -80,9 +79,9 @@ namespace IO.Swagger.Api { /// public StoreApi(ApiClient apiClient = null) { if (apiClient == null) { // use the default one in Configuration - this.apiClient = Configuration.apiClient; + this.ApiClient = Configuration.DefaultApiClient; } else { - this.apiClient = apiClient; + this.ApiClient = apiClient; } } @@ -92,7 +91,7 @@ namespace IO.Swagger.Api { /// public StoreApi(String basePath) { - this.apiClient = new ApiClient(basePath); + this.ApiClient = new ApiClient(basePath); } /// @@ -100,7 +99,7 @@ namespace IO.Swagger.Api { /// /// The base path public void SetBasePath(String basePath) { - this.apiClient.basePath = basePath; + this.ApiClient.BasePath = basePath; } /// @@ -108,21 +107,20 @@ namespace IO.Swagger.Api { /// /// The base path public String GetBasePath(String basePath) { - return this.apiClient.basePath; + return this.ApiClient.BasePath; } /// /// Gets or sets the API client. /// /// The API client - public ApiClient apiClient {get; set;} + public ApiClient ApiClient {get; set;} /// /// Returns pet inventories by status Returns a map of status codes to quantities /// - /// Dictionary public Dictionary GetInventory () { @@ -147,18 +145,17 @@ namespace IO.Swagger.Api { String[] authSettings = new String[] { "api_key" }; // make the HTTP request - IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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)); + return (Dictionary) ApiClient.Deserialize(response.Content, typeof(Dictionary)); } - - /// + + /// /// Returns pet inventories by status Returns a map of status codes to quantities /// - /// Dictionary public async Task> GetInventoryAsync () { @@ -183,11 +180,11 @@ namespace IO.Swagger.Api { 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); + 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)); + return (Dictionary) ApiClient.Deserialize(response.Content, typeof(Dictionary)); } /// @@ -212,22 +209,22 @@ namespace IO.Swagger.Api { - postBody = apiClient.Serialize(Body); // http body (model) parameter + postBody = ApiClient.Serialize(Body); // http body (model) parameter // authentication setting, if any String[] authSettings = new String[] { }; // make the HTTP request - IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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)); + return (Order) ApiClient.Deserialize(response.Content, typeof(Order)); } - - /// + + /// /// Place an order for a pet /// /// order placed for purchasing the pet @@ -249,18 +246,18 @@ namespace IO.Swagger.Api { - postBody = apiClient.Serialize(Body); // http body (model) parameter + postBody = ApiClient.Serialize(Body); // http body (model) parameter // authentication setting, if any String[] authSettings = new String[] { }; // make the HTTP request - IRestResponse response = (IRestResponse) await apiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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)); + return (Order) ApiClient.Deserialize(response.Content, typeof(Order)); } /// @@ -277,7 +274,7 @@ namespace IO.Swagger.Api { var path = "/store/order/{orderId}"; path = path.Replace("{format}", "json"); - path = path.Replace("{" + "orderId" + "}", apiClient.ParameterToString(OrderId)); + path = path.Replace("{" + "orderId" + "}", ApiClient.ParameterToString(OrderId)); var queryParams = new Dictionary(); @@ -295,15 +292,15 @@ namespace IO.Swagger.Api { String[] authSettings = new String[] { }; // make the HTTP request - IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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)); + return (Order) ApiClient.Deserialize(response.Content, typeof(Order)); } - - /// + + /// /// 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 @@ -317,7 +314,7 @@ namespace IO.Swagger.Api { var path = "/store/order/{orderId}"; path = path.Replace("{format}", "json"); - path = path.Replace("{" + "orderId" + "}", apiClient.ParameterToString(OrderId)); + path = path.Replace("{" + "orderId" + "}", ApiClient.ParameterToString(OrderId)); var queryParams = new Dictionary(); @@ -335,11 +332,11 @@ namespace IO.Swagger.Api { String[] authSettings = new String[] { }; // make the HTTP request - IRestResponse response = (IRestResponse) await apiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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)); + return (Order) ApiClient.Deserialize(response.Content, typeof(Order)); } /// @@ -356,7 +353,7 @@ namespace IO.Swagger.Api { var path = "/store/order/{orderId}"; path = path.Replace("{format}", "json"); - path = path.Replace("{" + "orderId" + "}", apiClient.ParameterToString(OrderId)); + path = path.Replace("{" + "orderId" + "}", ApiClient.ParameterToString(OrderId)); var queryParams = new Dictionary(); @@ -374,7 +371,7 @@ namespace IO.Swagger.Api { String[] authSettings = new String[] { }; // make the HTTP request - IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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); @@ -382,8 +379,8 @@ namespace IO.Swagger.Api { 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 @@ -397,7 +394,7 @@ namespace IO.Swagger.Api { var path = "/store/order/{orderId}"; path = path.Replace("{format}", "json"); - path = path.Replace("{" + "orderId" + "}", apiClient.ParameterToString(OrderId)); + path = path.Replace("{" + "orderId" + "}", ApiClient.ParameterToString(OrderId)); var queryParams = new Dictionary(); @@ -415,7 +412,7 @@ namespace IO.Swagger.Api { String[] authSettings = new String[] { }; // make the HTTP request - IRestResponse response = (IRestResponse) await apiClient.CallApiAsync(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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); } 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 ffee3f5fdd2..beda2ebe362 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 @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Collections.Generic; using System.Threading.Tasks; using RestSharp; @@ -55,28 +56,28 @@ namespace IO.Swagger.Api { /// /// Logs user into the system /// - /// The user name for login/// The password for login in clear text + /// 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 + /// 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 (); @@ -97,14 +98,16 @@ namespace IO.Swagger.Api { /// /// Updated user This can only be done by the logged in user. /// - /// name that need to be deleted/// Updated user object + /// 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 + /// name that need to be deleted + /// Updated user object /// Task UpdateUserAsync (string Username, User Body); @@ -136,9 +139,9 @@ namespace IO.Swagger.Api { /// public UserApi(ApiClient apiClient = null) { if (apiClient == null) { // use the default one in Configuration - this.apiClient = Configuration.apiClient; + this.ApiClient = Configuration.DefaultApiClient; } else { - this.apiClient = apiClient; + this.ApiClient = apiClient; } } @@ -148,7 +151,7 @@ namespace IO.Swagger.Api { /// public UserApi(String basePath) { - this.apiClient = new ApiClient(basePath); + this.ApiClient = new ApiClient(basePath); } /// @@ -156,7 +159,7 @@ namespace IO.Swagger.Api { /// /// The base path public void SetBasePath(String basePath) { - this.apiClient.basePath = basePath; + this.ApiClient.BasePath = basePath; } /// @@ -164,14 +167,14 @@ namespace IO.Swagger.Api { /// /// The base path public String GetBasePath(String basePath) { - return this.apiClient.basePath; + return this.ApiClient.BasePath; } /// /// Gets or sets the API client. /// /// The API client - public ApiClient apiClient {get; set;} + public ApiClient ApiClient {get; set;} @@ -197,14 +200,14 @@ namespace IO.Swagger.Api { - postBody = apiClient.Serialize(Body); // http body (model) parameter + postBody = ApiClient.Serialize(Body); // http body (model) parameter // authentication setting, if any String[] authSettings = new String[] { }; // make the HTTP request - IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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); @@ -212,8 +215,8 @@ namespace IO.Swagger.Api { return; } - - /// + + /// /// Create user This can only be done by the logged in user. /// /// Created user object @@ -235,14 +238,14 @@ namespace IO.Swagger.Api { - postBody = apiClient.Serialize(Body); // http body (model) parameter + postBody = ApiClient.Serialize(Body); // http body (model) parameter // authentication setting, if any String[] authSettings = new String[] { }; // make the HTTP request - IRestResponse response = (IRestResponse) await apiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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); } @@ -272,14 +275,14 @@ namespace IO.Swagger.Api { - postBody = apiClient.Serialize(Body); // http body (model) parameter + postBody = ApiClient.Serialize(Body); // http body (model) parameter // authentication setting, if any String[] authSettings = new String[] { }; // make the HTTP request - IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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); @@ -287,8 +290,8 @@ namespace IO.Swagger.Api { return; } - - /// + + /// /// Creates list of users with given input array /// /// List of user object @@ -310,14 +313,14 @@ namespace IO.Swagger.Api { - postBody = apiClient.Serialize(Body); // http body (model) parameter + postBody = ApiClient.Serialize(Body); // http body (model) parameter // authentication setting, if any String[] authSettings = new String[] { }; // make the HTTP request - IRestResponse response = (IRestResponse) await apiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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); } @@ -347,14 +350,14 @@ namespace IO.Swagger.Api { - postBody = apiClient.Serialize(Body); // http body (model) parameter + postBody = ApiClient.Serialize(Body); // http body (model) parameter // authentication setting, if any String[] authSettings = new String[] { }; // make the HTTP request - IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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); @@ -362,8 +365,8 @@ namespace IO.Swagger.Api { return; } - - /// + + /// /// Creates list of users with given input array /// /// List of user object @@ -385,14 +388,14 @@ namespace IO.Swagger.Api { - postBody = apiClient.Serialize(Body); // http body (model) parameter + postBody = ApiClient.Serialize(Body); // http body (model) parameter // authentication setting, if any String[] authSettings = new String[] { }; // make the HTTP request - IRestResponse response = (IRestResponse) await apiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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); } @@ -403,7 +406,8 @@ namespace IO.Swagger.Api { /// /// Logs user into the system /// - /// The user name for login/// The password for login in clear text + /// The user name for login + /// The password for login in clear text /// string public string LoginUser (string Username, string Password) { @@ -419,8 +423,8 @@ namespace IO.Swagger.Api { 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 + if (Username != null) queryParams.Add("username", ApiClient.ParameterToString(Username)); // query parameter + if (Password != null) queryParams.Add("password", ApiClient.ParameterToString(Password)); // query parameter @@ -430,18 +434,19 @@ namespace IO.Swagger.Api { String[] authSettings = new String[] { }; // make the HTTP request - IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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)); + return (string) ApiClient.Deserialize(response.Content, typeof(string)); } - - /// + + /// /// Logs user into the system /// - /// The user name for login/// The password for login in clear text + /// The user name for login + /// The password for login in clear text /// string public async Task LoginUserAsync (string Username, string Password) { @@ -457,8 +462,8 @@ namespace IO.Swagger.Api { 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 + if (Username != null) queryParams.Add("username", ApiClient.ParameterToString(Username)); // query parameter + if (Password != null) queryParams.Add("password", ApiClient.ParameterToString(Password)); // query parameter @@ -468,17 +473,16 @@ namespace IO.Swagger.Api { String[] authSettings = new String[] { }; // make the HTTP request - IRestResponse response = (IRestResponse) await apiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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)); + return (string) ApiClient.Deserialize(response.Content, typeof(string)); } /// /// Logs out current logged in user session /// - /// public void LogoutUser () { @@ -503,7 +507,7 @@ namespace IO.Swagger.Api { String[] authSettings = new String[] { }; // make the HTTP request - IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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); @@ -511,11 +515,10 @@ namespace IO.Swagger.Api { return; } - - /// + + /// /// Logs out current logged in user session /// - /// public async Task LogoutUserAsync () { @@ -540,7 +543,7 @@ namespace IO.Swagger.Api { String[] authSettings = new String[] { }; // make the HTTP request - IRestResponse response = (IRestResponse) await apiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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); } @@ -562,7 +565,7 @@ namespace IO.Swagger.Api { var path = "/user/{username}"; path = path.Replace("{format}", "json"); - path = path.Replace("{" + "username" + "}", apiClient.ParameterToString(Username)); + path = path.Replace("{" + "username" + "}", ApiClient.ParameterToString(Username)); var queryParams = new Dictionary(); @@ -580,15 +583,15 @@ namespace IO.Swagger.Api { String[] authSettings = new String[] { }; // make the HTTP request - IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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)); + return (User) ApiClient.Deserialize(response.Content, typeof(User)); } - - /// + + /// /// Get user by user name /// /// The name that needs to be fetched. Use user1 for testing. @@ -602,7 +605,7 @@ namespace IO.Swagger.Api { var path = "/user/{username}"; path = path.Replace("{format}", "json"); - path = path.Replace("{" + "username" + "}", apiClient.ParameterToString(Username)); + path = path.Replace("{" + "username" + "}", ApiClient.ParameterToString(Username)); var queryParams = new Dictionary(); @@ -620,17 +623,18 @@ namespace IO.Swagger.Api { String[] authSettings = new String[] { }; // make the HTTP request - IRestResponse response = (IRestResponse) await apiClient.CallApiAsync(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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)); + return (User) ApiClient.Deserialize(response.Content, typeof(User)); } /// /// Updated user This can only be done by the logged in user. /// - /// name that need to be deleted/// Updated user object + /// name that need to be deleted + /// Updated user object /// public void UpdateUser (string Username, User Body) { @@ -641,7 +645,7 @@ namespace IO.Swagger.Api { var path = "/user/{username}"; path = path.Replace("{format}", "json"); - path = path.Replace("{" + "username" + "}", apiClient.ParameterToString(Username)); + path = path.Replace("{" + "username" + "}", ApiClient.ParameterToString(Username)); var queryParams = new Dictionary(); @@ -653,14 +657,14 @@ namespace IO.Swagger.Api { - postBody = apiClient.Serialize(Body); // http body (model) parameter + postBody = ApiClient.Serialize(Body); // http body (model) parameter // authentication setting, if any String[] authSettings = new String[] { }; // make the HTTP request - IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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); @@ -668,11 +672,12 @@ namespace IO.Swagger.Api { return; } - - /// + + /// /// Updated user This can only be done by the logged in user. /// - /// name that need to be deleted/// Updated user object + /// name that need to be deleted + /// Updated user object /// public async Task UpdateUserAsync (string Username, User Body) { @@ -683,7 +688,7 @@ namespace IO.Swagger.Api { var path = "/user/{username}"; path = path.Replace("{format}", "json"); - path = path.Replace("{" + "username" + "}", apiClient.ParameterToString(Username)); + path = path.Replace("{" + "username" + "}", ApiClient.ParameterToString(Username)); var queryParams = new Dictionary(); @@ -695,14 +700,14 @@ namespace IO.Swagger.Api { - postBody = apiClient.Serialize(Body); // http body (model) parameter + postBody = ApiClient.Serialize(Body); // http body (model) parameter // authentication setting, if any String[] authSettings = new String[] { }; // make the HTTP request - IRestResponse response = (IRestResponse) await apiClient.CallApiAsync(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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); } @@ -724,7 +729,7 @@ namespace IO.Swagger.Api { var path = "/user/{username}"; path = path.Replace("{format}", "json"); - path = path.Replace("{" + "username" + "}", apiClient.ParameterToString(Username)); + path = path.Replace("{" + "username" + "}", ApiClient.ParameterToString(Username)); var queryParams = new Dictionary(); @@ -742,7 +747,7 @@ namespace IO.Swagger.Api { String[] authSettings = new String[] { }; // make the HTTP request - IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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); @@ -750,8 +755,8 @@ namespace IO.Swagger.Api { return; } - - /// + + /// /// Delete user This can only be done by the logged in user. /// /// The name that needs to be deleted @@ -765,7 +770,7 @@ namespace IO.Swagger.Api { var path = "/user/{username}"; path = path.Replace("{format}", "json"); - path = path.Replace("{" + "username" + "}", apiClient.ParameterToString(Username)); + path = path.Replace("{" + "username" + "}", ApiClient.ParameterToString(Username)); var queryParams = new Dictionary(); @@ -783,7 +788,7 @@ namespace IO.Swagger.Api { String[] authSettings = new String[] { }; // make the HTTP request - IRestResponse response = (IRestResponse) await apiClient.CallApiAsync(path, Method.DELETE, queryParams, postBody, headerParams, formParams, fileParams, authSettings); + 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); } 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 b001a38845c..321e9bc2a36 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,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Text.RegularExpressions; using System.IO; using System.Linq; using System.Net; @@ -19,21 +20,21 @@ namespace IO.Swagger.Client { /// /// The base path. public ApiClient(String basePath="http://petstore.swagger.io/v2") { - this.basePath = basePath; - this.restClient = new RestClient(this.basePath); + this.BasePath = basePath; + this.RestClient = new RestClient(this.BasePath); } /// /// Gets or sets the base path. /// /// The base path. - public string basePath { get; set; } + public string BasePath { get; set; } /// /// Gets or sets the RestClient /// /// The RestClient. - public RestClient restClient { get; set; } + public RestClient RestClient { get; set; } private Dictionary defaultHeaderMap = new Dictionary(); @@ -77,7 +78,7 @@ namespace IO.Swagger.Client { request.AddParameter("application/json", PostBody, ParameterType.RequestBody); // http body (model) parameter } - return (Object) await restClient.ExecuteTaskAsync(request); + return (Object) await RestClient.ExecuteTaskAsync(request); } @@ -119,10 +120,12 @@ namespace IO.Swagger.Client { { if (obj is DateTime) { return ((DateTime)obj).ToString ("u"); + } else if (obj is FileStream) { + return ((FileStream)obj).Name; } else if (obj is List) { return String.Join(",", obj as List); } else { - return Convert.ToString (obj); + return Convert.ToString (obj); } } @@ -132,16 +135,38 @@ namespace IO.Swagger.Client { /// JSON string /// Object type /// Object representation of the JSON string - public object Deserialize(string content, Type type) { - if (type.GetType() == typeof(Object)) - return (Object)content; + public object Deserialize(string content, Type type, IList headers=null) { + if (type.GetType() == typeof(Object)) { + return (Object)content; + } else if (type.Name == "FileStream") { + // e.g. Content-Disposition: attachment; filename=checkimage.jpp + String fileName; + String 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(); + } + System.IO.File.WriteAllText (fileName, content); + return File.Open (fileName, FileMode.Open); + } + try { return JsonConvert.DeserializeObject(content, type); } catch (IOException e) { - throw new ApiException(500, e.Message); + throw new ApiException(500, e.Message); } } @@ -165,12 +190,12 @@ namespace IO.Swagger.Client { /// /// Object /// API key with prefix - public string GetApiKeyWithPrefix (string apiKey) + public string GetApiKeyWithPrefix (string apiKeyIdentifier) { var apiKeyValue = ""; - Configuration.apiKey.TryGetValue (apiKey, out apiKeyValue); + Configuration.ApiKey.TryGetValue (apiKeyIdentifier, out apiKeyValue); var apiKeyPrefix = ""; - if (Configuration.apiKeyPrefix.TryGetValue (apiKey, out apiKeyPrefix)) { + if (Configuration.ApiKeyPrefix.TryGetValue (apiKeyIdentifier, out apiKeyPrefix)) { return apiKeyPrefix + " " + apiKeyValue; } else { return apiKeyValue; 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 ab24fc1252c..5d3029e7cc3 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 @@ -1,4 +1,5 @@ using System; +using System.Reflection; using System.Collections.Generic; using System.IO; using System.Linq; @@ -17,35 +18,81 @@ namespace IO.Swagger.Client { public const string Version = "1.0.0"; /// - /// Gets or sets the API client. This is the default API client for making HTTP calls. + /// Gets or sets the default API client for making HTTP calls. /// /// The API client. - public static ApiClient apiClient = new ApiClient(); + public static ApiClient DefaultApiClient = new ApiClient(); /// /// Gets or sets the username (HTTP basic authentication) /// /// The username. - public static String username { get; set; } + public static String Username { get; set; } /// /// Gets or sets the password (HTTP basic authentication) /// /// The password. - public static String password { get; set; } + public static String Password { get; set; } /// /// Gets or sets the API key based on the authentication name /// /// The API key. - public static Dictionary apiKey = new Dictionary(); + public static Dictionary ApiKey = new Dictionary(); /// /// 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(); + public static Dictionary ApiKeyPrefix = new Dictionary(); + private static string _tempFolderPath = Path.GetTempPath(); + /// + /// Gets or sets the temporary folder path to store the files downloaded from the server + /// + /// Folder path + public static String TempFolderPath { + get { + return _tempFolderPath; + } + + set { + if (!String.IsNullOrEmpty(value)) { + _tempFolderPath = value; + return; + } + + // create the directory if it does not exist + if (!Directory.Exists(value)) { + Directory.CreateDirectory(value); + } + + // check if the path contains directory separator at the end + if (value[value.Length - 1] == Path.DirectorySeparatorChar) { + _tempFolderPath = value; + } else { + _tempFolderPath = value + Path.DirectorySeparatorChar; + } + } + } + + /// + /// Return a string contain essential information for debugging + /// + /// Folder path + 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 += " SDK Package Version: 1.0.0\n"; + + return report; + } } } diff --git a/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs b/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs index 4fa44c936ae..929ee8f320f 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs +++ b/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs @@ -1,9 +1,12 @@  - + - - + + + + + diff --git a/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll b/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll index bac89714b9c..5541f7ccaa2 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 a7a6c4d4364..6cfbe6bdc22 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 bac89714b9c..5541f7ccaa2 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 a7a6c4d4364..6cfbe6bdc22 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