forked from loafle/openapi-generator-original
better type comparision
This commit is contained in:
parent
3b1999af4b
commit
94768d44b5
@ -8,6 +8,7 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using RestSharp;
|
using RestSharp;
|
||||||
|
using RestSharp.Extensions;
|
||||||
|
|
||||||
namespace {{packageName}}.Client {
|
namespace {{packageName}}.Client {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -38,6 +39,18 @@ namespace {{packageName}}.Client {
|
|||||||
|
|
||||||
private Dictionary<String, String> DefaultHeaderMap = new Dictionary<String, String>();
|
private Dictionary<String, String> DefaultHeaderMap = new Dictionary<String, String>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Make the HTTP request (Sync)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">URL path</param>
|
||||||
|
/// <param name="method">HTTP method</param>
|
||||||
|
/// <param name="queryParams">Query parameters</param>
|
||||||
|
/// <param name="postBody">HTTP body (POST request)</param>
|
||||||
|
/// <param name="headerParams">Header parameters</param>
|
||||||
|
/// <param name="formParams">Form parameters</param>
|
||||||
|
/// <param name="fileParams">File parameters</param>
|
||||||
|
/// <param name="authSettings">Authentication settings</param>
|
||||||
|
/// <returns>Object</returns>
|
||||||
public Object CallApi(String path, RestSharp.Method method, Dictionary<String, String> queryParams, String postBody,
|
public Object CallApi(String path, RestSharp.Method method, Dictionary<String, String> queryParams, String postBody,
|
||||||
Dictionary<String, String> headerParams, Dictionary<String, String> formParams,
|
Dictionary<String, String> headerParams, Dictionary<String, String> formParams,
|
||||||
Dictionary<String, FileParameter> fileParams, String[] authSettings) {
|
Dictionary<String, FileParameter> fileParams, String[] authSettings) {
|
||||||
@ -75,6 +88,18 @@ namespace {{packageName}}.Client {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Make the HTTP request (Async)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">URL path</param>
|
||||||
|
/// <param name="method">HTTP method</param>
|
||||||
|
/// <param name="queryParams">Query parameters</param>
|
||||||
|
/// <param name="postBody">HTTP body (POST request)</param>
|
||||||
|
/// <param name="headerParams">Header parameters</param>
|
||||||
|
/// <param name="formParams">Form parameters</param>
|
||||||
|
/// <param name="fileParams">File parameters</param>
|
||||||
|
/// <param name="authSettings">Authentication settings</param>
|
||||||
|
/// <returns>Task</returns>
|
||||||
public async Task<Object> CallApiAsync(String path, RestSharp.Method method, Dictionary<String, String> queryParams, String postBody,
|
public async Task<Object> CallApiAsync(String path, RestSharp.Method method, Dictionary<String, String> queryParams, String postBody,
|
||||||
Dictionary<String, String> headerParams, Dictionary<String, String> formParams, Dictionary<String, FileParameter> fileParams, String[] authSettings) {
|
Dictionary<String, String> headerParams, Dictionary<String, String> formParams, Dictionary<String, FileParameter> fileParams, String[] authSettings) {
|
||||||
|
|
||||||
@ -147,9 +172,9 @@ namespace {{packageName}}.Client {
|
|||||||
public FileParameter ParameterToFile(string name, Stream stream)
|
public FileParameter ParameterToFile(string name, Stream stream)
|
||||||
{
|
{
|
||||||
if (stream is FileStream) {
|
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 {
|
} 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 {
|
|||||||
/// <param name="type">Object type</param>
|
/// <param name="type">Object type</param>
|
||||||
/// <returns>Object representation of the JSON string</returns>
|
/// <returns>Object representation of the JSON string</returns>
|
||||||
public object Deserialize(string content, Type type, IList<Parameter> headers=null) {
|
public object Deserialize(string content, Type type, IList<Parameter> headers=null) {
|
||||||
if (type.GetType() == typeof(Object)) { // return an object
|
if (type == typeof(Object)) { // return an object
|
||||||
return (Object)content;
|
return (Object)content;
|
||||||
} else if (type.Name == "Stream") {
|
} else if (type == typeof(Stream)) {
|
||||||
String fileName, filePath;
|
String fileName, filePath;
|
||||||
if (String.IsNullOrEmpty (Configuration.TempFolderPath)) {
|
if (String.IsNullOrEmpty (Configuration.TempFolderPath)) {
|
||||||
filePath = System.IO.Path.GetTempPath ();
|
filePath = System.IO.Path.GetTempPath ();
|
||||||
@ -273,26 +298,6 @@ namespace {{packageName}}.Client {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// convert a stream to byte array (byte[])
|
|
||||||
/// Ref: http://stackoverflow.com/questions/221925/creating-a-byte-array-from-a-stream
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="input">input stream</param>
|
|
||||||
/// <return>Array of Byte</return>
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Encode string in base64 format
|
/// Encode string in base64 format
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -90,7 +90,7 @@ namespace {{packageName}}.Client {
|
|||||||
.GetReferencedAssemblies()
|
.GetReferencedAssemblies()
|
||||||
.Where(x => x.Name == "System.Core").First().Version.ToString() + "\n";
|
.Where(x => x.Name == "System.Core").First().Version.ToString() + "\n";
|
||||||
report += " Swagger Spec Version: {{version}}\n";
|
report += " Swagger Spec Version: {{version}}\n";
|
||||||
report += " SDK Package Version: {{version}}\n";
|
report += " SDK Package Version: {{packageVersion}}\n";
|
||||||
|
|
||||||
return report;
|
return report;
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using RestSharp;
|
using RestSharp;
|
||||||
|
using RestSharp.Extensions;
|
||||||
|
|
||||||
namespace IO.Swagger.Client {
|
namespace IO.Swagger.Client {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -38,6 +39,18 @@ namespace IO.Swagger.Client {
|
|||||||
|
|
||||||
private Dictionary<String, String> DefaultHeaderMap = new Dictionary<String, String>();
|
private Dictionary<String, String> DefaultHeaderMap = new Dictionary<String, String>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Make the HTTP request (Sync)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">URL path</param>
|
||||||
|
/// <param name="method">HTTP method</param>
|
||||||
|
/// <param name="queryParams">Query parameters</param>
|
||||||
|
/// <param name="postBody">HTTP body (POST request)</param>
|
||||||
|
/// <param name="headerParams">Header parameters</param>
|
||||||
|
/// <param name="formParams">Form parameters</param>
|
||||||
|
/// <param name="fileParams">File parameters</param>
|
||||||
|
/// <param name="authSettings">Authentication settings</param>
|
||||||
|
/// <returns>Object</returns>
|
||||||
public Object CallApi(String path, RestSharp.Method method, Dictionary<String, String> queryParams, String postBody,
|
public Object CallApi(String path, RestSharp.Method method, Dictionary<String, String> queryParams, String postBody,
|
||||||
Dictionary<String, String> headerParams, Dictionary<String, String> formParams,
|
Dictionary<String, String> headerParams, Dictionary<String, String> formParams,
|
||||||
Dictionary<String, FileParameter> fileParams, String[] authSettings) {
|
Dictionary<String, FileParameter> fileParams, String[] authSettings) {
|
||||||
@ -75,6 +88,18 @@ namespace IO.Swagger.Client {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Make the HTTP request (Async)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">URL path</param>
|
||||||
|
/// <param name="method">HTTP method</param>
|
||||||
|
/// <param name="queryParams">Query parameters</param>
|
||||||
|
/// <param name="postBody">HTTP body (POST request)</param>
|
||||||
|
/// <param name="headerParams">Header parameters</param>
|
||||||
|
/// <param name="formParams">Form parameters</param>
|
||||||
|
/// <param name="fileParams">File parameters</param>
|
||||||
|
/// <param name="authSettings">Authentication settings</param>
|
||||||
|
/// <returns>Task</returns>
|
||||||
public async Task<Object> CallApiAsync(String path, RestSharp.Method method, Dictionary<String, String> queryParams, String postBody,
|
public async Task<Object> CallApiAsync(String path, RestSharp.Method method, Dictionary<String, String> queryParams, String postBody,
|
||||||
Dictionary<String, String> headerParams, Dictionary<String, String> formParams, Dictionary<String, FileParameter> fileParams, String[] authSettings) {
|
Dictionary<String, String> headerParams, Dictionary<String, String> formParams, Dictionary<String, FileParameter> fileParams, String[] authSettings) {
|
||||||
|
|
||||||
@ -147,9 +172,9 @@ namespace IO.Swagger.Client {
|
|||||||
public FileParameter ParameterToFile(string name, Stream stream)
|
public FileParameter ParameterToFile(string name, Stream stream)
|
||||||
{
|
{
|
||||||
if (stream is FileStream) {
|
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 {
|
} 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 {
|
|||||||
/// <param name="type">Object type</param>
|
/// <param name="type">Object type</param>
|
||||||
/// <returns>Object representation of the JSON string</returns>
|
/// <returns>Object representation of the JSON string</returns>
|
||||||
public object Deserialize(string content, Type type, IList<Parameter> headers=null) {
|
public object Deserialize(string content, Type type, IList<Parameter> headers=null) {
|
||||||
if (type.GetType() == typeof(Object)) { // return an object
|
if (type == typeof(Object)) { // return an object
|
||||||
return (Object)content;
|
return (Object)content;
|
||||||
} else if (type.Name == "Stream") {
|
} else if (type == typeof(Stream)) {
|
||||||
String fileName, filePath;
|
String fileName, filePath;
|
||||||
if (String.IsNullOrEmpty (Configuration.TempFolderPath)) {
|
if (String.IsNullOrEmpty (Configuration.TempFolderPath)) {
|
||||||
filePath = System.IO.Path.GetTempPath ();
|
filePath = System.IO.Path.GetTempPath ();
|
||||||
@ -278,26 +303,6 @@ namespace IO.Swagger.Client {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// convert a stream to byte array (byte[])
|
|
||||||
/// Ref: http://stackoverflow.com/questions/221925/creating-a-byte-array-from-a-stream
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="input">input stream</param>
|
|
||||||
/// <return>Array of Byte</return>
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Encode string in base64 format
|
/// Encode string in base64 format
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
|
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
|
||||||
<MonoDevelop.Ide.Workbench ActiveDocument="TestPet.cs">
|
<MonoDevelop.Ide.Workbench ActiveDocument="TestPet.cs">
|
||||||
<Files>
|
<Files>
|
||||||
<File FileName="TestPet.cs" Line="15" Column="29" />
|
<File FileName="TestPet.cs" Line="57" Column="19" />
|
||||||
</Files>
|
</Files>
|
||||||
</MonoDevelop.Ide.Workbench>
|
</MonoDevelop.Ide.Workbench>
|
||||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||||
|
Binary file not shown.
Binary file not shown.
@ -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/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/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/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.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/bin/Debug/SwaggerClientTest.dll
|
||||||
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll
|
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll
|
||||||
|
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user