forked from loafle/openapi-generator-original
revert file to String, add test case for upload file
This commit is contained in:
parent
f290de95dd
commit
2e76b56f30
@ -37,6 +37,7 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"String",
|
||||
"string",
|
||||
"bool?",
|
||||
"double?",
|
||||
@ -68,7 +69,7 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
typeMapping.put("number", "double?");
|
||||
typeMapping.put("datetime", "DateTime?");
|
||||
typeMapping.put("date", "DateTime?");
|
||||
typeMapping.put("file", "FileStream");
|
||||
typeMapping.put("file", "String");
|
||||
typeMapping.put("array", "List");
|
||||
typeMapping.put("list", "List");
|
||||
typeMapping.put("map", "Dictionary");
|
||||
|
@ -120,8 +120,6 @@ 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<string>) {
|
||||
return String.Join(",", obj as List<string>);
|
||||
} else {
|
||||
@ -138,7 +136,7 @@ namespace {{packageName}}.Client {
|
||||
public object Deserialize(string content, Type type, IList<Parameter> headers=null) {
|
||||
if (type.GetType() == typeof(Object)) { // return an object
|
||||
return (Object)content;
|
||||
} else if (type.Name == "FileStream") { // return a file
|
||||
} else if (type.Name == "FileStream") { // return a file (full path)
|
||||
// e.g. Content-Disposition: attachment; filename=checkimage.jpp
|
||||
String fileName;
|
||||
String filePath;
|
||||
@ -157,7 +155,7 @@ namespace {{packageName}}.Client {
|
||||
fileName = filePath + Guid.NewGuid().ToString();
|
||||
}
|
||||
System.IO.File.WriteAllText (fileName, content);
|
||||
return File.Open (fileName, FileMode.Open);
|
||||
return fileName;
|
||||
} else if (type.Name.StartsWith("System.Nullable`1[[System.DateTime")) { // return a datetime object
|
||||
return DateTime.Parse(content, null, System.Globalization.DateTimeStyles.RoundtripKind);
|
||||
} else if (type.Name == "String" || type.Name.StartsWith("System.Nullable")) { // return primitive
|
||||
|
@ -121,8 +121,11 @@ namespace {{packageName}}.Api {
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.Content, response.Content);
|
||||
}
|
||||
{{#returnType}}return ({{{returnType}}}) ApiClient.Deserialize(response.Content, typeof({{{returnType}}}), response.Headers);{{/returnType}}{{^returnType}}
|
||||
return;{{/returnType}}
|
||||
|
||||
{{#returnType}} // if return type is "String" (not "string"), it implies a Filestream and should return the file path
|
||||
String returnTypeString = "{{{returnType}}}";
|
||||
Type returnType = returnTypeString == "String" ? typeof(FileStream) : typeof({{{returnType}}});
|
||||
return ({{{returnType}}}) ApiClient.Deserialize(response.Content, returnType, response.Headers);{{/returnType}}{{^returnType}}return;{{/returnType}}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -122,7 +122,7 @@ namespace IO.Swagger.Api {
|
||||
/// <param name="additionalMetadata">Additional data to pass to server</param>
|
||||
/// <param name="file">file to upload</param>
|
||||
/// <returns></returns>
|
||||
void UploadFile (long? petId, string additionalMetadata, FileStream file);
|
||||
void UploadFile (long? petId, string additionalMetadata, String file);
|
||||
|
||||
/// <summary>
|
||||
/// uploads an image
|
||||
@ -131,7 +131,7 @@ namespace IO.Swagger.Api {
|
||||
/// <param name="additionalMetadata">Additional data to pass to server</param>
|
||||
/// <param name="file">file to upload</param>
|
||||
/// <returns></returns>
|
||||
Task UploadFileAsync (long? petId, string additionalMetadata, FileStream file);
|
||||
Task UploadFileAsync (long? petId, string additionalMetadata, String file);
|
||||
|
||||
}
|
||||
|
||||
@ -370,7 +370,11 @@ namespace IO.Swagger.Api {
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByStatus: " + response.Content, response.Content);
|
||||
}
|
||||
return (List<Pet>) ApiClient.Deserialize(response.Content, typeof(List<Pet>), response.Headers);
|
||||
|
||||
// if return type is "String" (not "string"), it implies a Filestream and should return the file path
|
||||
String returnTypeString = "List<Pet>";
|
||||
Type returnType = returnTypeString == "String" ? typeof(FileStream) : typeof(List<Pet>);
|
||||
return (List<Pet>) ApiClient.Deserialize(response.Content, returnType, response.Headers);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -443,7 +447,11 @@ namespace IO.Swagger.Api {
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling FindPetsByTags: " + response.Content, response.Content);
|
||||
}
|
||||
return (List<Pet>) ApiClient.Deserialize(response.Content, typeof(List<Pet>), response.Headers);
|
||||
|
||||
// if return type is "String" (not "string"), it implies a Filestream and should return the file path
|
||||
String returnTypeString = "List<Pet>";
|
||||
Type returnType = returnTypeString == "String" ? typeof(FileStream) : typeof(List<Pet>);
|
||||
return (List<Pet>) ApiClient.Deserialize(response.Content, returnType, response.Headers);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -519,7 +527,11 @@ namespace IO.Swagger.Api {
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling GetPetById: " + response.Content, response.Content);
|
||||
}
|
||||
return (Pet) ApiClient.Deserialize(response.Content, typeof(Pet), response.Headers);
|
||||
|
||||
// if return type is "String" (not "string"), it implies a Filestream and should return the file path
|
||||
String returnTypeString = "Pet";
|
||||
Type returnType = returnTypeString == "String" ? typeof(FileStream) : typeof(Pet);
|
||||
return (Pet) ApiClient.Deserialize(response.Content, returnType, response.Headers);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -742,7 +754,7 @@ namespace IO.Swagger.Api {
|
||||
/// <param name="additionalMetadata">Additional data to pass to server</param>
|
||||
/// <param name="file">file to upload</param>
|
||||
/// <returns></returns>
|
||||
public void UploadFile (long? petId, string additionalMetadata, FileStream file) {
|
||||
public void UploadFile (long? petId, string additionalMetadata, String file) {
|
||||
|
||||
|
||||
// verify the required parameter 'petId' is set
|
||||
@ -787,7 +799,7 @@ namespace IO.Swagger.Api {
|
||||
/// <param name="additionalMetadata">Additional data to pass to server</param>
|
||||
/// <param name="file">file to upload</param>
|
||||
/// <returns></returns>
|
||||
public async Task UploadFileAsync (long? petId, string additionalMetadata, FileStream file) {
|
||||
public async Task UploadFileAsync (long? petId, string additionalMetadata, String file) {
|
||||
|
||||
|
||||
// verify the required parameter 'petId' is set
|
||||
|
@ -150,7 +150,11 @@ namespace IO.Swagger.Api {
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling GetInventory: " + response.Content, response.Content);
|
||||
}
|
||||
return (Dictionary<String, int?>) ApiClient.Deserialize(response.Content, typeof(Dictionary<String, int?>), response.Headers);
|
||||
|
||||
// if return type is "String" (not "string"), it implies a Filestream and should return the file path
|
||||
String returnTypeString = "Dictionary<String, int?>";
|
||||
Type returnType = returnTypeString == "String" ? typeof(FileStream) : typeof(Dictionary<String, int?>);
|
||||
return (Dictionary<String, int?>) ApiClient.Deserialize(response.Content, returnType, response.Headers);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -221,7 +225,11 @@ namespace IO.Swagger.Api {
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling PlaceOrder: " + response.Content, response.Content);
|
||||
}
|
||||
return (Order) ApiClient.Deserialize(response.Content, typeof(Order), response.Headers);
|
||||
|
||||
// if return type is "String" (not "string"), it implies a Filestream and should return the file path
|
||||
String returnTypeString = "Order";
|
||||
Type returnType = returnTypeString == "String" ? typeof(FileStream) : typeof(Order);
|
||||
return (Order) ApiClient.Deserialize(response.Content, returnType, response.Headers);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -297,7 +305,11 @@ namespace IO.Swagger.Api {
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling GetOrderById: " + response.Content, response.Content);
|
||||
}
|
||||
return (Order) ApiClient.Deserialize(response.Content, typeof(Order), response.Headers);
|
||||
|
||||
// if return type is "String" (not "string"), it implies a Filestream and should return the file path
|
||||
String returnTypeString = "Order";
|
||||
Type returnType = returnTypeString == "String" ? typeof(FileStream) : typeof(Order);
|
||||
return (Order) ApiClient.Deserialize(response.Content, returnType, response.Headers);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -439,7 +439,11 @@ namespace IO.Swagger.Api {
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling LoginUser: " + response.Content, response.Content);
|
||||
}
|
||||
return (string) ApiClient.Deserialize(response.Content, typeof(string), response.Headers);
|
||||
|
||||
// if return type is "String" (not "string"), it implies a Filestream and should return the file path
|
||||
String returnTypeString = "string";
|
||||
Type returnType = returnTypeString == "String" ? typeof(FileStream) : typeof(string);
|
||||
return (string) ApiClient.Deserialize(response.Content, returnType, response.Headers);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -588,7 +592,11 @@ namespace IO.Swagger.Api {
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling GetUserByName: " + response.Content, response.Content);
|
||||
}
|
||||
return (User) ApiClient.Deserialize(response.Content, typeof(User), response.Headers);
|
||||
|
||||
// if return type is "String" (not "string"), it implies a Filestream and should return the file path
|
||||
String returnTypeString = "User";
|
||||
Type returnType = returnTypeString == "String" ? typeof(FileStream) : typeof(User);
|
||||
return (User) ApiClient.Deserialize(response.Content, returnType, response.Headers);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -120,8 +120,6 @@ 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<string>) {
|
||||
return String.Join(",", obj as List<string>);
|
||||
} else {
|
||||
@ -138,7 +136,7 @@ namespace IO.Swagger.Client {
|
||||
public object Deserialize(string content, Type type, IList<Parameter> headers=null) {
|
||||
if (type.GetType() == typeof(Object)) { // return an object
|
||||
return (Object)content;
|
||||
} else if (type.Name == "FileStream") { // return a file
|
||||
} else if (type.Name == "FileStream") { // return a file (full path)
|
||||
// e.g. Content-Disposition: attachment; filename=checkimage.jpp
|
||||
String fileName;
|
||||
String filePath;
|
||||
@ -157,7 +155,7 @@ namespace IO.Swagger.Client {
|
||||
fileName = filePath + Guid.NewGuid().ToString();
|
||||
}
|
||||
System.IO.File.WriteAllText (fileName, content);
|
||||
return File.Open (fileName, FileMode.Open);
|
||||
return fileName;
|
||||
} else if (type.Name.StartsWith("System.Nullable`1[[System.DateTime")) { // return a datetime object
|
||||
return DateTime.Parse(content, null, System.Globalization.DateTimeStyles.RoundtripKind);
|
||||
} else if (type.Name == "String" || type.Name.StartsWith("System.Nullable")) { // return primitive
|
||||
|
@ -1,10 +1,9 @@
|
||||
<Properties StartupItem="SwaggerClientTest.csproj">
|
||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/ApiClient.cs">
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="TestPet.cs">
|
||||
<Files>
|
||||
<File FileName="TestPet.cs" Line="6" Column="25" />
|
||||
<File FileName="Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Category.cs" Line="1" Column="1" />
|
||||
<File FileName="Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/PetApi.cs" Line="1" Column="1" />
|
||||
<File FileName="TestPet.cs" Line="123" Column="3" />
|
||||
<File FileName="Lib/SwaggerClient/src/main/csharp/IO/Swagger/Api/PetApi.cs" Line="18" Column="25" />
|
||||
<File FileName="Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/ApiClient.cs" Line="1" Column="1" />
|
||||
</Files>
|
||||
</MonoDevelop.Ide.Workbench>
|
||||
|
@ -1,5 +1,6 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using IO.Swagger.Api;
|
||||
using IO.Swagger.Model;
|
||||
@ -48,6 +49,30 @@ namespace SwaggerClient.TestPet
|
||||
}
|
||||
|
||||
|
||||
[Test ()]
|
||||
public void TestGetPetByIdAsync ()
|
||||
{
|
||||
PetApi petApi = new PetApi ();
|
||||
var task = petApi.GetPetByIdAsync (petId);
|
||||
Pet response = task.Result;
|
||||
Assert.IsInstanceOf<Pet> (response, "Response is a Pet");
|
||||
|
||||
Assert.AreEqual ("Csharp test", response.Name);
|
||||
Assert.AreEqual ("available", response.Status);
|
||||
|
||||
Assert.IsInstanceOf<List<Tag>> (response.Tags, "Response.Tags is a Array");
|
||||
Assert.AreEqual (petId, response.Tags [0].Id);
|
||||
Assert.AreEqual ("sample tag name1", response.Tags [0].Name);
|
||||
|
||||
Assert.IsInstanceOf<List<String>> (response.PhotoUrls, "Response.PhotoUrls is a Array");
|
||||
Assert.AreEqual ("sample photoUrls", response.PhotoUrls [0]);
|
||||
|
||||
Assert.IsInstanceOf<Category> (response.Category, "Response.Category is a Category");
|
||||
Assert.AreEqual (56, response.Category.Id);
|
||||
Assert.AreEqual ("sample category name2", response.Category.Name);
|
||||
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void TestGetPetById ()
|
||||
{
|
||||
@ -89,6 +114,15 @@ namespace SwaggerClient.TestPet
|
||||
Assert.AreEqual (56, response.Category.Id);
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void TestUploadFile ()
|
||||
{
|
||||
PetApi petApi = new PetApi ();
|
||||
//NOTE: please provide a valid file (full path)
|
||||
petApi.UploadFile(petId, "new form name", "/var/tmp/small.gif");
|
||||
}
|
||||
|
||||
|
||||
[Test ()]
|
||||
public void TestFindPetByStatus ()
|
||||
{
|
||||
|
Binary file not shown.
Binary file not shown.
@ -1,8 +1,8 @@
|
||||
/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/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
|
||||
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb
|
||||
/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
|
||||
|
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user