forked from loafle/openapi-generator-original
[C#][netcore] fix binary response (#8593)
* fix binary response * update test file hash
This commit is contained in:
parent
a5ac2ee1a3
commit
b7ee885805
@ -1,6 +1,6 @@
|
||||
---
|
||||
# csharp-netcore test files and image for upload
|
||||
- filename: "samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools.Test/Api/PetApiTests.cs"
|
||||
sha256: b74ef9eefa4b41fd3233e083fe2355babf25a77f9073d28e1aa81ae2e0a5f1d0
|
||||
sha256: aceebba316148a2a803a15ef4e13bbd0b0a1b8d15006cd88adb9b39a620ee451
|
||||
- filename: "samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools.Test/linux-logo.png"
|
||||
sha256: 0a67c32728197e942b13bdda064b73793f12f5c795f1e5cf35a3adf69c973230
|
||||
|
@ -472,6 +472,19 @@ namespace {{packageName}}.Client
|
||||
response = client.Execute<T>(req);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof({{{packageName}}}.{{modelPackage}}.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
T instance = (T)Activator.CreateInstance(typeof(T));
|
||||
MethodInfo method = typeof(T).GetMethod("FromJson");
|
||||
method.Invoke(instance, new object[] { response.Content });
|
||||
response.Data = instance;
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
|
||||
InterceptResponse(req, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
@ -583,6 +596,10 @@ namespace {{packageName}}.Client
|
||||
method.Invoke(instance, new object[] { response.Content });
|
||||
response.Data = instance;
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
|
||||
InterceptResponse(req, response);
|
||||
|
||||
|
@ -477,6 +477,19 @@ namespace Org.OpenAPITools.Client
|
||||
response = client.Execute<T>(req);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
T instance = (T)Activator.CreateInstance(typeof(T));
|
||||
MethodInfo method = typeof(T).GetMethod("FromJson");
|
||||
method.Invoke(instance, new object[] { response.Content });
|
||||
response.Data = instance;
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
|
||||
InterceptResponse(req, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
@ -587,6 +600,10 @@ namespace Org.OpenAPITools.Client
|
||||
method.Invoke(instance, new object[] { response.Content });
|
||||
response.Data = instance;
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
|
||||
InterceptResponse(req, response);
|
||||
|
||||
|
@ -477,6 +477,19 @@ namespace Org.OpenAPITools.Client
|
||||
response = client.Execute<T>(req);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
T instance = (T)Activator.CreateInstance(typeof(T));
|
||||
MethodInfo method = typeof(T).GetMethod("FromJson");
|
||||
method.Invoke(instance, new object[] { response.Content });
|
||||
response.Data = instance;
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
|
||||
InterceptResponse(req, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
@ -587,6 +600,10 @@ namespace Org.OpenAPITools.Client
|
||||
method.Invoke(instance, new object[] { response.Content });
|
||||
response.Data = instance;
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
|
||||
InterceptResponse(req, response);
|
||||
|
||||
|
@ -199,6 +199,19 @@ namespace Org.OpenAPITools.Test
|
||||
Assert.Equal("sample category name2", response.Category.Name);
|
||||
}
|
||||
|
||||
/* a simple test for binary response. no longer in use.
|
||||
[Fact]
|
||||
public void TestGetByIdBinaryResponse()
|
||||
{
|
||||
PetApi petApi = new PetApi(c1);
|
||||
Stream response = petApi.GetPetByIdBinaryResponse(petId);
|
||||
Assert.IsType<System.IO.MemoryStream>(response);
|
||||
StreamReader reader = new StreamReader(response);
|
||||
// the following will fail for sure
|
||||
//Assert.Equal("someting", reader.ReadToEnd());
|
||||
}
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// Test GetPetByIdWithHttpInfoAsync
|
||||
/// </summary>
|
||||
|
@ -476,6 +476,19 @@ namespace Org.OpenAPITools.Client
|
||||
response = client.Execute<T>(req);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
T instance = (T)Activator.CreateInstance(typeof(T));
|
||||
MethodInfo method = typeof(T).GetMethod("FromJson");
|
||||
method.Invoke(instance, new object[] { response.Content });
|
||||
response.Data = instance;
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
|
||||
InterceptResponse(req, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
@ -586,6 +599,10 @@ namespace Org.OpenAPITools.Client
|
||||
method.Invoke(instance, new object[] { response.Content });
|
||||
response.Data = instance;
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
|
||||
InterceptResponse(req, response);
|
||||
|
||||
|
@ -477,6 +477,19 @@ namespace Org.OpenAPITools.Client
|
||||
response = client.Execute<T>(req);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
T instance = (T)Activator.CreateInstance(typeof(T));
|
||||
MethodInfo method = typeof(T).GetMethod("FromJson");
|
||||
method.Invoke(instance, new object[] { response.Content });
|
||||
response.Data = instance;
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
|
||||
InterceptResponse(req, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
@ -587,6 +600,10 @@ namespace Org.OpenAPITools.Client
|
||||
method.Invoke(instance, new object[] { response.Content });
|
||||
response.Data = instance;
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
|
||||
InterceptResponse(req, response);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user