diff --git a/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache index f6cbcfc61c1..905931a2991 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache @@ -8,6 +8,7 @@ using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; using RestSharp; +using RestSharp.Extensions; namespace {{packageName}}.Client { /// @@ -38,6 +39,18 @@ namespace {{packageName}}.Client { private Dictionary DefaultHeaderMap = new Dictionary(); + /// + /// Make the HTTP request (Sync) + /// + /// URL path + /// HTTP method + /// Query parameters + /// HTTP body (POST request) + /// Header parameters + /// Form parameters + /// File parameters + /// Authentication settings + /// Object public Object CallApi(String path, RestSharp.Method method, Dictionary queryParams, String postBody, Dictionary headerParams, Dictionary formParams, Dictionary fileParams, String[] authSettings) { @@ -74,7 +87,19 @@ namespace {{packageName}}.Client { return (Object)RestClient.Execute(request); } - + + /// + /// Make the HTTP request (Async) + /// + /// URL path + /// HTTP method + /// Query parameters + /// HTTP body (POST request) + /// Header parameters + /// Form parameters + /// File parameters + /// Authentication settings + /// Task public async Task CallApiAsync(String path, RestSharp.Method method, Dictionary queryParams, String postBody, Dictionary headerParams, Dictionary formParams, Dictionary fileParams, String[] authSettings) { @@ -147,9 +172,9 @@ namespace {{packageName}}.Client { public FileParameter ParameterToFile(string name, Stream stream) { if (stream is FileStream) { - return FileParameter.Create(name, StreamToByteArray(stream), Path.GetFileName(((FileStream)stream).Name)); + return FileParameter.Create(name, stream.ReadAsBytes(), Path.GetFileName(((FileStream)stream).Name)); } else { - return FileParameter.Create(name, StreamToByteArray(stream), "no_file_name_provided"); + return FileParameter.Create(name, stream.ReadAsBytes(), "no_file_name_provided"); } } @@ -178,9 +203,9 @@ namespace {{packageName}}.Client { /// Object type /// Object representation of the JSON string public object Deserialize(string content, Type type, IList headers=null) { - if (type.GetType() == typeof(Object)) { // return an object + if (type == typeof(Object)) { // return an object return (Object)content; - } else if (type.Name == "Stream") { + } else if (type == typeof(Stream)) { String fileName, filePath; if (String.IsNullOrEmpty (Configuration.TempFolderPath)) { filePath = System.IO.Path.GetTempPath (); @@ -255,7 +280,7 @@ namespace {{packageName}}.Client { public void UpdateParamsForAuth(Dictionary queryParams, Dictionary headerParams, string[] authSettings) { if (authSettings == null || authSettings.Length == 0) return; - + foreach (string auth in authSettings) { // determine which one to use switch(auth) { @@ -270,29 +295,9 @@ namespace {{packageName}}.Client { break; } } - + } - - /// - /// convert a stream to byte array (byte[]) - /// Ref: http://stackoverflow.com/questions/221925/creating-a-byte-array-from-a-stream - /// - /// input stream - /// Array of Byte - public byte[] StreamToByteArray(Stream input) - { - byte[] buffer = new byte[16*1024]; - using (MemoryStream ms = new MemoryStream()) - { - int read; - while ((read = input.Read(buffer, 0, buffer.Length)) > 0) - { - ms.Write(buffer, 0, read); - } - return ms.ToArray(); - } - } - + /// /// Encode string in base64 format /// diff --git a/modules/swagger-codegen/src/main/resources/csharp/Configuration.mustache b/modules/swagger-codegen/src/main/resources/csharp/Configuration.mustache index 81c31a9ce55..a6246c3e158 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/Configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/Configuration.mustache @@ -90,7 +90,7 @@ namespace {{packageName}}.Client { .GetReferencedAssemblies() .Where(x => x.Name == "System.Core").First().Version.ToString() + "\n"; report += " Swagger Spec Version: {{version}}\n"; - report += " SDK Package Version: {{version}}\n"; + report += " SDK Package Version: {{packageVersion}}\n"; return report; } 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 c262f242334..1fd6a02213e 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 @@ -8,6 +8,7 @@ using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; using RestSharp; +using RestSharp.Extensions; namespace IO.Swagger.Client { /// @@ -38,6 +39,18 @@ namespace IO.Swagger.Client { private Dictionary DefaultHeaderMap = new Dictionary(); + /// + /// Make the HTTP request (Sync) + /// + /// URL path + /// HTTP method + /// Query parameters + /// HTTP body (POST request) + /// Header parameters + /// Form parameters + /// File parameters + /// Authentication settings + /// Object public Object CallApi(String path, RestSharp.Method method, Dictionary queryParams, String postBody, Dictionary headerParams, Dictionary formParams, Dictionary fileParams, String[] authSettings) { @@ -74,7 +87,19 @@ namespace IO.Swagger.Client { return (Object)RestClient.Execute(request); } - + + /// + /// Make the HTTP request (Async) + /// + /// URL path + /// HTTP method + /// Query parameters + /// HTTP body (POST request) + /// Header parameters + /// Form parameters + /// File parameters + /// Authentication settings + /// Task public async Task CallApiAsync(String path, RestSharp.Method method, Dictionary queryParams, String postBody, Dictionary headerParams, Dictionary formParams, Dictionary fileParams, String[] authSettings) { @@ -147,9 +172,9 @@ namespace IO.Swagger.Client { public FileParameter ParameterToFile(string name, Stream stream) { if (stream is FileStream) { - return FileParameter.Create(name, StreamToByteArray(stream), Path.GetFileName(((FileStream)stream).Name)); + return FileParameter.Create(name, stream.ReadAsBytes(), Path.GetFileName(((FileStream)stream).Name)); } else { - return FileParameter.Create(name, StreamToByteArray(stream), "no_file_name_provided"); + return FileParameter.Create(name, stream.ReadAsBytes(), "no_file_name_provided"); } } @@ -178,9 +203,9 @@ namespace IO.Swagger.Client { /// Object type /// Object representation of the JSON string public object Deserialize(string content, Type type, IList headers=null) { - if (type.GetType() == typeof(Object)) { // return an object + if (type == typeof(Object)) { // return an object return (Object)content; - } else if (type.Name == "Stream") { + } else if (type == typeof(Stream)) { String fileName, filePath; if (String.IsNullOrEmpty (Configuration.TempFolderPath)) { filePath = System.IO.Path.GetTempPath (); @@ -255,7 +280,7 @@ namespace IO.Swagger.Client { public void UpdateParamsForAuth(Dictionary queryParams, Dictionary headerParams, string[] authSettings) { if (authSettings == null || authSettings.Length == 0) return; - + foreach (string auth in authSettings) { // determine which one to use switch(auth) { @@ -275,29 +300,9 @@ namespace IO.Swagger.Client { break; } } - + } - - /// - /// convert a stream to byte array (byte[]) - /// Ref: http://stackoverflow.com/questions/221925/creating-a-byte-array-from-a-stream - /// - /// input stream - /// Array of Byte - public byte[] StreamToByteArray(Stream input) - { - byte[] buffer = new byte[16*1024]; - using (MemoryStream ms = new MemoryStream()) - { - int read; - while ((read = input.Read(buffer, 0, buffer.Length)) > 0) - { - ms.Write(buffer, 0, read); - } - return ms.ToArray(); - } - } - + /// /// Encode string in base64 format /// diff --git a/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs b/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs index f0d348256b2..5a5f6ebb92c 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs +++ b/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs @@ -2,7 +2,7 @@ - + diff --git a/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll b/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll index 8ba6b3c14dd..378be56e081 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 3c97688db38..6e9caa87e2b 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 9afb7990f57..af9606f3079 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,7 +1,7 @@ /Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs -/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll /Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Newtonsoft.Json.dll /Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/RestSharp.dll +/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll /Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb /Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll /Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/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 8ba6b3c14dd..378be56e081 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 3c97688db38..6e9caa87e2b 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