forked from loafle/openapi-generator-original
Merge pull request #1414 from dgreenbean/feature/csharp_binary_files
Raw Binary for File Output
This commit is contained in:
commit
5964f7b841
@ -214,34 +214,37 @@ namespace {{packageName}}.Client
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deserialize the JSON string into a proper object.
|
/// Deserialize the JSON string into a proper object.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="content">HTTP body (e.g. string, JSON).</param>
|
/// <param name="response">The HTTP response.</param>
|
||||||
/// <param name="type">Object type.</param>
|
/// <param name="type">Object type.</param>
|
||||||
/// <param name="headers"></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(IRestResponse response, Type type)
|
||||||
{
|
{
|
||||||
|
byte[] data = response.RawBytes;
|
||||||
|
string content = response.Content;
|
||||||
|
IList<Parameter> headers = response.Headers;
|
||||||
if (type == typeof(Object)) // return an object
|
if (type == typeof(Object)) // return an object
|
||||||
{
|
{
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == typeof(Stream))
|
if (type == typeof(Stream))
|
||||||
|
{
|
||||||
|
if (headers != null)
|
||||||
{
|
{
|
||||||
var filePath = String.IsNullOrEmpty(Configuration.TempFolderPath)
|
var filePath = String.IsNullOrEmpty(Configuration.TempFolderPath)
|
||||||
? Path.GetTempPath()
|
? Path.GetTempPath()
|
||||||
: Configuration.TempFolderPath;
|
: Configuration.TempFolderPath;
|
||||||
|
|
||||||
var fileName = filePath + Guid.NewGuid();
|
|
||||||
if (headers != null)
|
|
||||||
{
|
|
||||||
var regex = new Regex(@"Content-Disposition:.*filename=['""]?([^'""\s]+)['""]?$");
|
var regex = new Regex(@"Content-Disposition:.*filename=['""]?([^'""\s]+)['""]?$");
|
||||||
var match = regex.Match(headers.ToString());
|
var match = regex.Match(headers.ToString());
|
||||||
if (match.Success)
|
if (match.Success)
|
||||||
fileName = filePath + match.Value.Replace("\"", "").Replace("'", "");
|
{
|
||||||
}
|
string fileName = filePath + match.Value.Replace("\"", "").Replace("'", "");
|
||||||
File.WriteAllText(fileName, content);
|
File.WriteAllBytes(fileName, data);
|
||||||
return new FileStream(fileName, FileMode.Open);
|
return new FileStream(fileName, FileMode.Open);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var stream = new MemoryStream(data);
|
||||||
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type.Name.StartsWith("System.Nullable`1[[System.DateTime")) // return a datetime object
|
if (type.Name.StartsWith("System.Nullable`1[[System.DateTime")) // return a datetime object
|
||||||
|
@ -144,7 +144,7 @@ namespace {{packageName}}.Api
|
|||||||
else if (((int)response.StatusCode) == 0)
|
else if (((int)response.StatusCode) == 0)
|
||||||
throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.ErrorMessage, response.ErrorMessage);
|
throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.ErrorMessage, response.ErrorMessage);
|
||||||
|
|
||||||
{{#returnType}}return ({{{returnType}}}) ApiClient.Deserialize(response.Content, typeof({{{returnType}}}), response.Headers);{{/returnType}}{{^returnType}}return;{{/returnType}}
|
{{#returnType}}return ({{{returnType}}}) ApiClient.Deserialize(response, typeof({{{returnType}}}));{{/returnType}}{{^returnType}}return;{{/returnType}}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -197,7 +197,7 @@ namespace {{packageName}}.Api
|
|||||||
if (((int)response.StatusCode) >= 400)
|
if (((int)response.StatusCode) >= 400)
|
||||||
throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.Content, response.Content);
|
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}}
|
{{#returnType}}return ({{{returnType}}}) ApiClient.Deserialize(response, typeof({{{returnType}}}));{{/returnType}}{{^returnType}}
|
||||||
return;{{/returnType}}
|
return;{{/returnType}}
|
||||||
}
|
}
|
||||||
{{/operation}}
|
{{/operation}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user