diff --git a/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache
index ae864113a9c..f6dd2933331 100644
--- a/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache
+++ b/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache
@@ -214,12 +214,14 @@ namespace {{packageName}}.Client
///
/// Deserialize the JSON string into a proper object.
///
- /// HTTP body (e.g. string, JSON).
+ /// The HTTP response.
/// Object type.
- ///
/// Object representation of the JSON string.
- public object Deserialize(string content, Type type, IList headers=null)
+ public object Deserialize(IRestResponse response, Type type)
{
+ byte[] data = response.RawBytes;
+ string content = response.Content;
+ IList headers = response.Headers;
if (type == typeof(Object)) // return an object
{
return content;
@@ -227,21 +229,22 @@ namespace {{packageName}}.Client
if (type == typeof(Stream))
{
- var filePath = String.IsNullOrEmpty(Configuration.TempFolderPath)
- ? Path.GetTempPath()
- : Configuration.TempFolderPath;
-
- var fileName = filePath + Guid.NewGuid();
if (headers != null)
{
+ var filePath = String.IsNullOrEmpty(Configuration.TempFolderPath)
+ ? Path.GetTempPath()
+ : Configuration.TempFolderPath;
var regex = new Regex(@"Content-Disposition:.*filename=['""]?([^'""\s]+)['""]?$");
var match = regex.Match(headers.ToString());
if (match.Success)
- fileName = filePath + match.Value.Replace("\"", "").Replace("'", "");
+ {
+ string fileName = filePath + match.Value.Replace("\"", "").Replace("'", "");
+ File.WriteAllBytes(fileName, data);
+ return new FileStream(fileName, FileMode.Open);
+ }
}
- File.WriteAllText(fileName, content);
- 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
diff --git a/modules/swagger-codegen/src/main/resources/csharp/api.mustache b/modules/swagger-codegen/src/main/resources/csharp/api.mustache
index f54f42d2eca..89594091dfb 100644
--- a/modules/swagger-codegen/src/main/resources/csharp/api.mustache
+++ b/modules/swagger-codegen/src/main/resources/csharp/api.mustache
@@ -144,7 +144,7 @@ namespace {{packageName}}.Api
else if (((int)response.StatusCode) == 0)
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}}
}
///
@@ -197,7 +197,7 @@ 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}}
+ {{#returnType}}return ({{{returnType}}}) ApiClient.Deserialize(response, typeof({{{returnType}}}));{{/returnType}}{{^returnType}}
return;{{/returnType}}
}
{{/operation}}