diff --git a/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache index 87d55ab3f6e8..bac6fd02a697 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache @@ -198,10 +198,12 @@ namespace {{packageName}}.Client { if (obj is DateTime) return ((DateTime)obj).ToString ("u"); - else if (obj is IList) { + else if (obj is IList) + { string flattenString = ""; string separator = ","; - foreach (var param in (IList)obj) { + foreach (var param in (IList)obj) + { flattenString += param.ToString() + separator; } return flattenString.Remove(flattenString.Length - 1);; @@ -318,11 +320,29 @@ namespace {{packageName}}.Client { {{#authMethods}} case "{{name}}": - {{#isApiKey}}{{#isKeyInHeader}}headerParams["{{keyParamName}}"] = GetApiKeyWithPrefix("{{keyParamName}}");{{/isKeyInHeader}}{{#isKeyInQuery}}queryParams["{{keyParamName}}"] = GetApiKeyWithPrefix("{{keyParamName}}");{{/isKeyInQuery}}{{/isApiKey}}{{#isBasic}}headerParams["Authorization"] = "Basic " + Base64Encode(Configuration.Username + ":" + Configuration.Password);{{/isBasic}}{{#isOAuth}}headerParams["Authorization"] = "Bearer " + Configuration.AccessToken;{{/isOAuth}} + {{#isApiKey}}{{#isKeyInHeader}} + var apiKeyValue = GetApiKeyWithPrefix("{{keyParamName}}"); + if (!String.IsNullOrEmpty(apiKeyValue)) + { + headerParams["{{keyParamName}}"] = apiKeyValue; + }{{/isKeyInHeader}}{{#isKeyInQuery}} + var apiKeyValue = GetApiKeyWithPrefix("{{keyParamName}}"); + if (!String.IsNullOrEmpty(apiKeyValue)) + { + queryParams["{{keyParamName}}"] = apiKeyValue; + }{{/isKeyInQuery}}{{/isApiKey}}{{#isBasic}} + if (!String.IsNullOrEmpty(Configuration.Username) || !String.IsNullOrEmpty(Configuration.Password)) + { + headerParams["Authorization"] = "Basic " + Base64Encode(Configuration.Username + ":" + Configuration.Password); + }{{/isBasic}}{{#isOAuth}} + if (!String.IsNullOrEmpty(Configuration.AccessToken)) + { + headerParams["Authorization"] = "Bearer " + Configuration.AccessToken; + }{{/isOAuth}} break; {{/authMethods}} default: - //TODO show warning about security definition not found + //show warning about security definition not found break; } } @@ -335,11 +355,14 @@ namespace {{packageName}}.Client /// /// The accepts array to select from. /// The Accept header to use. - public String SelectHeaderAccept(String[] accepts) { + public String SelectHeaderAccept(String[] accepts) + { if (accepts.Length == 0) return null; + if (accepts.Contains("application/json", StringComparer.OrdinalIgnoreCase)) return "application/json"; + return String.Join(",", accepts); } @@ -350,8 +373,7 @@ namespace {{packageName}}.Client /// Encoded string. public static string Base64Encode(string text) { - var textByte = System.Text.Encoding.UTF8.GetBytes(text); - return System.Convert.ToBase64String(textByte); + return System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(text)); } /// @@ -361,7 +383,8 @@ namespace {{packageName}}.Client /// Object to be casted /// Target type /// Casted object - public static dynamic ConvertType(dynamic source, Type dest) { + 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/ApiClient.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/ApiClient.cs index 36217fde02da..a4f9276c8828 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 @@ -198,10 +198,12 @@ namespace IO.Swagger.Client { if (obj is DateTime) return ((DateTime)obj).ToString ("u"); - else if (obj is IList) { + else if (obj is IList) + { string flattenString = ""; string separator = ","; - foreach (var param in (IList)obj) { + foreach (var param in (IList)obj) + { flattenString += param.ToString() + separator; } return flattenString.Remove(flattenString.Length - 1);; @@ -318,15 +320,24 @@ namespace IO.Swagger.Client { case "api_key": - headerParams["api_key"] = GetApiKeyWithPrefix("api_key"); + + var apiKeyValue = GetApiKeyWithPrefix("api_key"); + if (!String.IsNullOrEmpty(apiKeyValue)) + { + headerParams["api_key"] = apiKeyValue; + } break; case "petstore_auth": - headerParams["Authorization"] = "Bearer " + Configuration.AccessToken; + + if (!String.IsNullOrEmpty(Configuration.AccessToken)) + { + headerParams["Authorization"] = "Bearer " + Configuration.AccessToken; + } break; default: - //TODO show warning about security definition not found + //show warning about security definition not found break; } } @@ -339,11 +350,14 @@ namespace IO.Swagger.Client /// /// The accepts array to select from. /// The Accept header to use. - public String SelectHeaderAccept(String[] accepts) { + public String SelectHeaderAccept(String[] accepts) + { if (accepts.Length == 0) return null; + if (accepts.Contains("application/json", StringComparer.OrdinalIgnoreCase)) return "application/json"; + return String.Join(",", accepts); } @@ -354,8 +368,7 @@ namespace IO.Swagger.Client /// Encoded string. public static string Base64Encode(string text) { - var textByte = System.Text.Encoding.UTF8.GetBytes(text); - return System.Convert.ToBase64String(textByte); + return System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(text)); } /// @@ -365,7 +378,8 @@ namespace IO.Swagger.Client /// Object to be casted /// Target type /// Casted object - public static dynamic ConvertType(dynamic source, Type dest) { + public static dynamic ConvertType(dynamic source, Type dest) + { return Convert.ChangeType(source, dest); } diff --git a/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs b/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs index 05585bff932a..0a2248522b99 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs +++ b/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs @@ -4,23 +4,6 @@ - - - - - - - - - - - - - - - - - diff --git a/samples/client/petstore/csharp/SwaggerClientTest/TestPet.cs b/samples/client/petstore/csharp/SwaggerClientTest/TestPet.cs index 0227a2d9113b..19a14c592f4d 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/TestPet.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/TestPet.cs @@ -49,7 +49,9 @@ namespace SwaggerClient.TestPet petApi.DeletePet(petId, "test key"); } - + /// + /// Test GetPetByIdAsync + /// [Test ()] public void TestGetPetByIdAsync () { @@ -74,6 +76,9 @@ namespace SwaggerClient.TestPet } + /// + /// Test GetPetById + /// [Test ()] public void TestGetPetById () { @@ -97,6 +102,9 @@ namespace SwaggerClient.TestPet } + /// + /// Test UpdatePetWithForm + /// [Test ()] public void TestUpdatePetWithForm () { @@ -115,6 +123,9 @@ namespace SwaggerClient.TestPet Assert.AreEqual (56, response.Category.Id); } + /// + /// Test UploadFile + /// [Test ()] public void TestUploadFile () { @@ -129,7 +140,9 @@ namespace SwaggerClient.TestPet } - + /// + /// Test FindPetByStatus + /// [Test ()] public void TestFindPetByStatus () { @@ -145,6 +158,9 @@ namespace SwaggerClient.TestPet } + /// + /// Test Equal + /// [Test ()] public void TestEqual() { diff --git a/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll b/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll index 924934c46233..cb328f9bb076 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 d0d7f1b3ccf0..638f1d93d46e 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.csproj.FilesWrittenAbsolute.txt b/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.csproj.FilesWrittenAbsolute.txt index b46eed9f9d61..67be9ad1f148 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.csproj.FilesWrittenAbsolute.txt +++ b/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.csproj.FilesWrittenAbsolute.txt @@ -1,8 +1,16 @@ +/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs +/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb +/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll +/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll +/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb +/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Newtonsoft.Json.dll +/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll +/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/RestSharp.dll /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs -/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb -/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Newtonsoft.Json.dll /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/RestSharp.dll +/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb +/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll diff --git a/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll b/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll index 924934c46233..cb328f9bb076 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 d0d7f1b3ccf0..638f1d93d46e 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