forked from loafle/openapi-generator-original
- add downloadImage to Petstore
- fixed equal instead of ':' after Content-Disposition - added definition of file (swagger-maven-plugin generates them)
This commit is contained in:
@@ -232,7 +232,7 @@ namespace {{packageName}}.Client
|
||||
var filePath = String.IsNullOrEmpty(Configuration.TempFolderPath)
|
||||
? Path.GetTempPath()
|
||||
: Configuration.TempFolderPath;
|
||||
var regex = new Regex(@"Content-Disposition:.*filename=['""]?([^'""\s]+)['""]?$");
|
||||
var regex = new Regex(@"Content-Disposition=.*filename=['""]?([^'""\s]+)['""]?$");
|
||||
foreach (var header in headers)
|
||||
{
|
||||
var match = regex.Match(header.ToString());
|
||||
|
||||
@@ -402,6 +402,23 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"/pet/{petId}/downloadImage" : {
|
||||
"get" : {
|
||||
"tags" : [ "pet" ],
|
||||
"summary" : "downloads an image",
|
||||
"description" : "",
|
||||
"operationId" : "downloadFile",
|
||||
"produces" : [ "application/octet-stream" ],
|
||||
"responses" : {
|
||||
"200" : {
|
||||
"description" : "successful operation",
|
||||
"schema" : {
|
||||
"$ref" : "#/definitions/File"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/store/inventory": {
|
||||
"get": {
|
||||
"tags": [
|
||||
@@ -972,6 +989,65 @@
|
||||
"xml": {
|
||||
"name": "Order"
|
||||
}
|
||||
},
|
||||
"definitions" : {
|
||||
"File": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"path": {
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"canonicalPath": {
|
||||
"type": "string"
|
||||
},
|
||||
"parent": {
|
||||
"type": "string"
|
||||
},
|
||||
"absolute": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"absoluteFile": {
|
||||
"$ref": "#/definitions/File"
|
||||
},
|
||||
"absolutePath": {
|
||||
"type": "string"
|
||||
},
|
||||
"canonicalFile": {
|
||||
"$ref": "#/definitions/File"
|
||||
},
|
||||
"freeSpace": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"parentFile": {
|
||||
"$ref": "#/definitions/File"
|
||||
},
|
||||
"totalSpace": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"usableSpace": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"directory": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"file": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"hidden": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using RestSharp;
|
||||
using IO.Swagger.Client;
|
||||
using IO.Swagger.Model;
|
||||
|
||||
|
||||
namespace IO.Swagger.Api
|
||||
{
|
||||
|
||||
@@ -307,6 +308,42 @@ namespace IO.Swagger.Api
|
||||
/// <returns>Task of ApiResponse</returns>
|
||||
System.Threading.Tasks.Task<ApiResponse<Object>> DeletePetAsyncWithHttpInfo (long? petId, string apiKey = null);
|
||||
|
||||
/// <summary>
|
||||
/// downloads an image
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
/// <returns>Stream</returns>
|
||||
Stream DownloadFile ();
|
||||
|
||||
/// <summary>
|
||||
/// downloads an image
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
/// <returns>ApiResponse of Stream</returns>
|
||||
ApiResponse<Stream> DownloadFileWithHttpInfo ();
|
||||
|
||||
/// <summary>
|
||||
/// downloads an image
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
/// <returns>Task of Stream</returns>
|
||||
System.Threading.Tasks.Task<Stream> DownloadFileAsync ();
|
||||
|
||||
/// <summary>
|
||||
/// downloads an image
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
/// <returns>Task of ApiResponse (Stream)</returns>
|
||||
System.Threading.Tasks.Task<ApiResponse<Stream>> DownloadFileAsyncWithHttpInfo ();
|
||||
|
||||
/// <summary>
|
||||
/// uploads an image
|
||||
/// </summary>
|
||||
@@ -1487,6 +1524,131 @@ namespace IO.Swagger.Api
|
||||
null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// downloads an image
|
||||
/// </summary>
|
||||
/// <returns>Stream</returns>
|
||||
public Stream DownloadFile ()
|
||||
{
|
||||
ApiResponse<Stream> response = DownloadFileWithHttpInfo();
|
||||
return response.Data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// downloads an image
|
||||
/// </summary>
|
||||
/// <returns>ApiResponse of Stream</returns>
|
||||
public ApiResponse< Stream > DownloadFileWithHttpInfo ()
|
||||
{
|
||||
|
||||
|
||||
var path_ = "/pet/{petId}/downloadImage";
|
||||
|
||||
var pathParams = new Dictionary<String, String>();
|
||||
var queryParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>(Configuration.DefaultHeader);
|
||||
var formParams = new Dictionary<String, String>();
|
||||
var fileParams = new Dictionary<String, FileParameter>();
|
||||
String postBody = null;
|
||||
|
||||
// to determine the Accept header
|
||||
String[] http_header_accepts = new String[] {
|
||||
"application/octet-stream"
|
||||
};
|
||||
String http_header_accept = Configuration.ApiClient.SelectHeaderAccept(http_header_accepts);
|
||||
if (http_header_accept != null)
|
||||
headerParams.Add("Accept", Configuration.ApiClient.SelectHeaderAccept(http_header_accepts));
|
||||
|
||||
// set "format" to json by default
|
||||
// e.g. /pet/{petId}.{format} becomes /pet/{petId}.json
|
||||
pathParams.Add("format", "json");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = (IRestResponse) Configuration.ApiClient.CallApi(path_, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, pathParams);
|
||||
|
||||
int statusCode = (int) response.StatusCode;
|
||||
|
||||
if (statusCode >= 400)
|
||||
throw new ApiException (statusCode, "Error calling DownloadFile: " + response.Content, response.Content);
|
||||
else if (statusCode == 0)
|
||||
throw new ApiException (statusCode, "Error calling DownloadFile: " + response.ErrorMessage, response.ErrorMessage);
|
||||
|
||||
return new ApiResponse<Stream>(statusCode,
|
||||
response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
|
||||
(Stream) Configuration.ApiClient.Deserialize(response, typeof(Stream)));
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// downloads an image
|
||||
/// </summary>
|
||||
/// <returns>Task of Stream</returns>
|
||||
public async System.Threading.Tasks.Task<Stream> DownloadFileAsync ()
|
||||
{
|
||||
ApiResponse<Stream> response = await DownloadFileAsyncWithHttpInfo();
|
||||
return response.Data;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// downloads an image
|
||||
/// </summary>
|
||||
/// <returns>Task of ApiResponse (Stream)</returns>
|
||||
public async System.Threading.Tasks.Task<ApiResponse<Stream>> DownloadFileAsyncWithHttpInfo ()
|
||||
{
|
||||
|
||||
|
||||
var path_ = "/pet/{petId}/downloadImage";
|
||||
|
||||
var pathParams = new Dictionary<String, String>();
|
||||
var queryParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>();
|
||||
var formParams = new Dictionary<String, String>();
|
||||
var fileParams = new Dictionary<String, FileParameter>();
|
||||
String postBody = null;
|
||||
|
||||
// to determine the Accept header
|
||||
String[] http_header_accepts = new String[] {
|
||||
"application/octet-stream"
|
||||
};
|
||||
String http_header_accept = Configuration.ApiClient.SelectHeaderAccept(http_header_accepts);
|
||||
if (http_header_accept != null)
|
||||
headerParams.Add("Accept", Configuration.ApiClient.SelectHeaderAccept(http_header_accepts));
|
||||
|
||||
// set "format" to json by default
|
||||
// e.g. /pet/{petId}.{format} becomes /pet/{petId}.json
|
||||
pathParams.Add("format", "json");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, pathParams);
|
||||
|
||||
int statusCode = (int) response.StatusCode;
|
||||
|
||||
if (statusCode >= 400)
|
||||
throw new ApiException (statusCode, "Error calling DownloadFile: " + response.Content, response.Content);
|
||||
else if (statusCode == 0)
|
||||
throw new ApiException (statusCode, "Error calling DownloadFile: " + response.ErrorMessage, response.ErrorMessage);
|
||||
|
||||
return new ApiResponse<Stream>(statusCode,
|
||||
response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
|
||||
(Stream) Configuration.ApiClient.Deserialize(response, typeof(Stream)));
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// uploads an image
|
||||
/// </summary>
|
||||
|
||||
@@ -6,6 +6,7 @@ using RestSharp;
|
||||
using IO.Swagger.Client;
|
||||
using IO.Swagger.Model;
|
||||
|
||||
|
||||
namespace IO.Swagger.Api
|
||||
{
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ using RestSharp;
|
||||
using IO.Swagger.Client;
|
||||
using IO.Swagger.Model;
|
||||
|
||||
|
||||
namespace IO.Swagger.Api
|
||||
{
|
||||
|
||||
|
||||
@@ -196,13 +196,14 @@ namespace IO.Swagger.Client
|
||||
return ((DateTime)obj).ToString (Configuration.DateTimeFormat);
|
||||
else if (obj is IList)
|
||||
{
|
||||
string flattenString = "";
|
||||
string separator = ",";
|
||||
var flattenedString = new StringBuilder();
|
||||
foreach (var param in (IList)obj)
|
||||
{
|
||||
flattenString += param.ToString() + separator;
|
||||
if (flattenedString.Length > 0)
|
||||
flattenedString.Append(",");
|
||||
flattenedString.Append(param);
|
||||
}
|
||||
return flattenString.Remove(flattenString.Length - 1);;
|
||||
return flattenedString.ToString();
|
||||
}
|
||||
else
|
||||
return Convert.ToString (obj);
|
||||
@@ -231,13 +232,16 @@ namespace IO.Swagger.Client
|
||||
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)
|
||||
var regex = new Regex(@"Content-Disposition=.*filename=['""]?([^'""\s]+)['""]?$");
|
||||
foreach (var header in headers)
|
||||
{
|
||||
string fileName = filePath + match.Value.Replace("\"", "").Replace("'", "");
|
||||
File.WriteAllBytes(fileName, data);
|
||||
return new FileStream(fileName, FileMode.Open);
|
||||
var match = regex.Match(header.ToString());
|
||||
if (match.Success)
|
||||
{
|
||||
string fileName = filePath + match.Groups[1].Value.Replace("\"", "").Replace("'", "");
|
||||
File.WriteAllBytes(fileName, data);
|
||||
return new FileStream(fileName, FileMode.Open);
|
||||
}
|
||||
}
|
||||
}
|
||||
var stream = new MemoryStream(data);
|
||||
|
||||
@@ -24,15 +24,15 @@ namespace IO.Swagger.Client
|
||||
/// <param name="apiKeyPrefix">Dictionary of API key prefix</param>
|
||||
/// <param name="tempFolderPath">Temp folder path</param>
|
||||
/// <param name="dateTimeFormat">DateTime format string</param>
|
||||
public Configuration(ApiClient apiClient = null,
|
||||
Dictionary<String, String> defaultHeader = null,
|
||||
string username = null,
|
||||
string password = null,
|
||||
string accessToken = null,
|
||||
Dictionary<String, String> apiKey = null,
|
||||
Dictionary<String, String> apiKeyPrefix = null,
|
||||
string tempFolderPath = null,
|
||||
string dateTimeFormat = null
|
||||
public Configuration(ApiClient apiClient,
|
||||
Dictionary<String, String> defaultHeader,
|
||||
string username,
|
||||
string password,
|
||||
string accessToken,
|
||||
Dictionary<String, String> apiKey,
|
||||
Dictionary<String, String> apiKeyPrefix,
|
||||
string tempFolderPath,
|
||||
string dateTimeFormat
|
||||
)
|
||||
{
|
||||
if (apiClient == null)
|
||||
@@ -43,11 +43,8 @@ namespace IO.Swagger.Client
|
||||
Username = username;
|
||||
Password = password;
|
||||
AccessToken = accessToken;
|
||||
|
||||
if (apiKey != null)
|
||||
ApiKey = apiKey;
|
||||
if (apiKeyPrefix != null)
|
||||
ApiKeyPrefix = apiKeyPrefix;
|
||||
ApiKey = apiKey;
|
||||
ApiKeyPrefix = apiKeyPrefix;
|
||||
|
||||
TempFolderPath = tempFolderPath;
|
||||
DateTimeFormat = dateTimeFormat;
|
||||
@@ -58,7 +55,7 @@ namespace IO.Swagger.Client
|
||||
/// Initializes a new instance of the Configuration class.
|
||||
/// </summary>
|
||||
/// <param name="apiClient">Api client.</param>
|
||||
public Configuration(ApiClient apiClient)
|
||||
public Configuration(ApiClient apiClient=null)
|
||||
{
|
||||
if (apiClient == null)
|
||||
ApiClient = ApiClient.Default;
|
||||
|
||||
@@ -7,6 +7,8 @@ using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
|
||||
|
||||
namespace IO.Swagger.Model
|
||||
{
|
||||
|
||||
@@ -122,4 +124,6 @@ namespace IO.Swagger.Model
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
|
||||
|
||||
namespace IO.Swagger.Model
|
||||
{
|
||||
|
||||
@@ -187,4 +189,6 @@ namespace IO.Swagger.Model
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
|
||||
|
||||
namespace IO.Swagger.Model
|
||||
{
|
||||
|
||||
@@ -187,4 +189,6 @@ namespace IO.Swagger.Model
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
|
||||
|
||||
namespace IO.Swagger.Model
|
||||
{
|
||||
|
||||
@@ -122,4 +124,6 @@ namespace IO.Swagger.Model
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
|
||||
|
||||
namespace IO.Swagger.Model
|
||||
{
|
||||
|
||||
@@ -219,4 +221,6 @@ namespace IO.Swagger.Model
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user