diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpNetCoreClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpNetCoreClientCodegen.java
index ff90d1e30e2..356c6a895b0 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpNetCoreClientCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpNetCoreClientCodegen.java
@@ -681,6 +681,11 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
binRelativePath += "vendor";
additionalProperties.put("binRelativePath", binRelativePath);
+ if(HTTPCLIENT.equals(getLibrary())) {
+ supportingFiles.add(new SupportingFile("FileParameter.mustache", clientPackageDir, "FileParameter.cs"));
+ typeMapping.put("file", "FileParameter");
+ }
+
supportingFiles.add(new SupportingFile("IApiAccessor.mustache", clientPackageDir, "IApiAccessor.cs"));
supportingFiles.add(new SupportingFile("Configuration.mustache", clientPackageDir, "Configuration.cs"));
supportingFiles.add(new SupportingFile("ApiClient.mustache", clientPackageDir, "ApiClient.cs"));
diff --git a/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/httpclient/ApiClient.mustache b/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/httpclient/ApiClient.mustache
index 5477cb0cc73..3703a8521d0 100644
--- a/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/httpclient/ApiClient.mustache
+++ b/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/httpclient/ApiClient.mustache
@@ -278,12 +278,10 @@ namespace {{packageName}}.Client
{
foreach (var fileParam in options.FileParameters)
{
- var fileStream = fileParam.Value as FileStream;
- var fileStreamName = fileStream != null ? System.IO.Path.GetFileName(fileStream.Name) : null;
- var content = new StreamContent(fileParam.Value);
+ var content = new StreamContent(fileParam.Value.Content);
content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
multipartContent.Add(content, fileParam.Key,
- fileStreamName ?? "no_file_name_provided");
+ fileParam.Value.Name);
}
}
return multipartContent;
@@ -370,11 +368,11 @@ namespace {{packageName}}.Client
{
if (options.Data != null)
{
- if (options.Data is Stream s)
+ if (options.Data is FileParameter fp)
{
contentType = contentType ?? "application/octet-stream";
- var streamContent = new StreamContent(s);
+ var streamContent = new StreamContent(fp.Content);
streamContent.Headers.ContentType = new MediaTypeHeaderValue(contentType);
request.Content = streamContent;
}
diff --git a/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/httpclient/FileParameter.mustache b/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/httpclient/FileParameter.mustache
new file mode 100644
index 00000000000..3fa243ed54f
--- /dev/null
+++ b/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/httpclient/FileParameter.mustache
@@ -0,0 +1,54 @@
+{{>partial_header}}
+
+using System.IO;
+
+namespace {{packageName}}.Client
+{
+
+ ///
+ /// Represents a File passed to the API as a Parameter, allows using different backends for files
+ ///
+ public class FileParameter
+ {
+ ///
+ /// The filename
+ ///
+ public string Name { get; set; } = "no_name_provided";
+
+ ///
+ /// The content of the file
+ ///
+ public Stream Content { get; set; }
+
+ ///
+ /// Construct a FileParameter just from the contents, will extract the filename from a filestream
+ ///
+ /// The file content
+ public FileParameter(Stream content)
+ {
+ if (content is FileStream fs)
+ {
+ Name = fs.Name;
+ }
+ Content = content;
+ }
+
+ ///
+ /// Construct a FileParameter from name and content
+ ///
+ /// The filename
+ /// The file content
+ public FileParameter(string filename, Stream content)
+ {
+ Name = filename;
+ Content = content;
+ }
+
+ ///
+ /// Implicit conversion of stream to file parameter. Useful for backwards compatibility.
+ ///
+ /// Stream to convert
+ /// FileParameter
+ public static implicit operator FileParameter(Stream s) => new FileParameter(s);
+ }
+}
\ No newline at end of file
diff --git a/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/httpclient/RequestOptions.mustache b/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/httpclient/RequestOptions.mustache
new file mode 100644
index 00000000000..b0137d97997
--- /dev/null
+++ b/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/httpclient/RequestOptions.mustache
@@ -0,0 +1,66 @@
+{{>partial_header}}
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Net;
+
+namespace {{packageName}}.Client
+{
+ ///
+ /// A container for generalized request inputs. This type allows consumers to extend the request functionality
+ /// by abstracting away from the default (built-in) request framework (e.g. RestSharp).
+ ///
+ public class RequestOptions
+ {
+ ///
+ /// Parameters to be bound to path parts of the Request's URL
+ ///
+ public Dictionary PathParameters { get; set; }
+
+ ///
+ /// Query parameters to be applied to the request.
+ /// Keys may have 1 or more values associated.
+ ///
+ public Multimap QueryParameters { get; set; }
+
+ ///
+ /// Header parameters to be applied to to the request.
+ /// Keys may have 1 or more values associated.
+ ///
+ public Multimap HeaderParameters { get; set; }
+
+ ///
+ /// Form parameters to be sent along with the request.
+ ///
+ public Dictionary FormParameters { get; set; }
+
+ ///
+ /// File parameters to be sent along with the request.
+ ///
+ public Dictionary FileParameters { get; set; }
+
+ ///
+ /// Cookies to be sent along with the request.
+ ///
+ public List Cookies { get; set; }
+
+ ///
+ /// Any data associated with a request body.
+ ///
+ public Object Data { get; set; }
+
+ ///
+ /// Constructs a new instance of
+ ///
+ public RequestOptions()
+ {
+ PathParameters = new Dictionary();
+ QueryParameters = new Multimap();
+ HeaderParameters = new Multimap();
+ FormParameters = new Dictionary();
+ FileParameters = new Dictionary();
+ Cookies = new List();
+ }
+ }
+}
\ No newline at end of file
diff --git a/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/httpclient/model.mustache b/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/httpclient/model.mustache
new file mode 100644
index 00000000000..0de1e05e514
--- /dev/null
+++ b/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/httpclient/model.mustache
@@ -0,0 +1,48 @@
+{{>partial_header}}
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.IO;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Text.RegularExpressions;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Converters;
+using Newtonsoft.Json.Linq;
+{{#models}}
+{{#model}}
+{{#discriminator}}
+using JsonSubTypes;
+{{/discriminator}}
+{{/model}}
+{{/models}}
+{{#validatable}}
+using System.ComponentModel.DataAnnotations;
+{{/validatable}}
+using FileParameter = {{packageName}}.Client.FileParameter;
+using OpenAPIDateConverter = {{packageName}}.Client.OpenAPIDateConverter;
+{{#useCompareNetObjects}}
+using OpenAPIClientUtils = {{packageName}}.Client.ClientUtils;
+{{/useCompareNetObjects}}
+{{#models}}
+{{#model}}
+{{#oneOf}}
+{{#-first}}
+using System.Reflection;
+{{/-first}}
+{{/oneOf}}
+{{#aneOf}}
+{{#-first}}
+using System.Reflection;
+{{/-first}}
+{{/aneOf}}
+
+namespace {{packageName}}.{{modelPackage}}
+{
+{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{#oneOf}}{{#-first}}{{>modelOneOf}}{{/-first}}{{/oneOf}}{{#anyOf}}{{#-first}}{{>modelAnyOf}}{{/-first}}{{/anyOf}}{{^oneOf}}{{^anyOf}}{{>modelGeneric}}{{/anyOf}}{{/oneOf}}{{/isEnum}}
+{{/model}}
+{{/models}}
+}
diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/.openapi-generator/FILES b/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/.openapi-generator/FILES
index e6b9861f332..d317e612051 100644
--- a/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/.openapi-generator/FILES
+++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/.openapi-generator/FILES
@@ -97,6 +97,7 @@ src/Org.OpenAPITools/Client/ApiResponse.cs
src/Org.OpenAPITools/Client/ClientUtils.cs
src/Org.OpenAPITools/Client/Configuration.cs
src/Org.OpenAPITools/Client/ExceptionFactory.cs
+src/Org.OpenAPITools/Client/FileParameter.cs
src/Org.OpenAPITools/Client/GlobalConfiguration.cs
src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
src/Org.OpenAPITools/Client/IApiAccessor.cs
diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/docs/FakeApi.md b/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/docs/FakeApi.md
index 947fbb114ef..c5a0b767f3d 100644
--- a/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/docs/FakeApi.md
+++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/docs/FakeApi.md
@@ -678,7 +678,7 @@ No authorization required
# **TestEndpointParameters**
-> void TestEndpointParameters (decimal number, double _double, string patternWithoutDelimiter, byte[] _byte, int? integer = null, int? int32 = null, long? int64 = null, float? _float = null, string _string = null, System.IO.Stream binary = null, DateTime? date = null, DateTime? dateTime = null, string password = null, string callback = null)
+> void TestEndpointParameters (decimal number, double _double, string patternWithoutDelimiter, byte[] _byte, int? integer = null, int? int32 = null, long? int64 = null, float? _float = null, string _string = null, FileParameter binary = null, DateTime? date = null, DateTime? dateTime = null, string password = null, string callback = null)
Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
@@ -718,7 +718,7 @@ namespace Example
var int64 = 789; // long? | None (optional)
var _float = 3.4F; // float? | None (optional)
var _string = _string_example; // string | None (optional)
- var binary = BINARY_DATA_HERE; // System.IO.Stream | None (optional)
+ var binary = BINARY_DATA_HERE; // FileParameter | None (optional)
var date = 2013-10-20; // DateTime? | None (optional)
var dateTime = 2013-10-20T19:20:30+01:00; // DateTime? | None (optional) (default to "2010-02-01T10:20:10.111110+01:00")
var password = password_example; // string | None (optional)
@@ -753,7 +753,7 @@ Name | Type | Description | Notes
**int64** | **long?**| None | [optional]
**_float** | **float?**| None | [optional]
**_string** | **string**| None | [optional]
- **binary** | **System.IO.Stream****System.IO.Stream**| None | [optional]
+ **binary** | **FileParameter****FileParameter**| None | [optional]
**date** | **DateTime?**| None | [optional]
**dateTime** | **DateTime?**| None | [optional] [default to "2010-02-01T10:20:10.111110+01:00"]
**password** | **string**| None | [optional]
diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/docs/FormatTest.md b/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/docs/FormatTest.md
index 39a70be7ad4..505dbad52df 100644
--- a/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/docs/FormatTest.md
+++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/docs/FormatTest.md
@@ -13,7 +13,7 @@ Name | Type | Description | Notes
**Decimal** | **decimal** | | [optional]
**String** | **string** | | [optional]
**Byte** | **byte[]** | |
-**Binary** | **System.IO.Stream** | | [optional]
+**Binary** | [**FileParameter**](FileParameter.md) | | [optional]
**Date** | **DateTime** | |
**DateTime** | **DateTime** | | [optional]
**Uuid** | **Guid** | | [optional]
diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/docs/PetApi.md b/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/docs/PetApi.md
index 9f4ec108d05..02d0e8e111a 100644
--- a/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/docs/PetApi.md
+++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/docs/PetApi.md
@@ -565,7 +565,7 @@ void (empty response body)
# **UploadFile**
-> ApiResponse UploadFile (long petId, string additionalMetadata = null, System.IO.Stream file = null)
+> ApiResponse UploadFile (long petId, string additionalMetadata = null, FileParameter file = null)
uploads an image
@@ -595,7 +595,7 @@ namespace Example
var apiInstance = new PetApi(httpClient, config, httpClientHandler);
var petId = 789; // long | ID of pet to update
var additionalMetadata = additionalMetadata_example; // string | Additional data to pass to server (optional)
- var file = BINARY_DATA_HERE; // System.IO.Stream | file to upload (optional)
+ var file = BINARY_DATA_HERE; // FileParameter | file to upload (optional)
try
{
@@ -620,7 +620,7 @@ Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**petId** | **long**| ID of pet to update |
**additionalMetadata** | **string**| Additional data to pass to server | [optional]
- **file** | **System.IO.Stream****System.IO.Stream**| file to upload | [optional]
+ **file** | **FileParameter****FileParameter**| file to upload | [optional]
### Return type
@@ -645,7 +645,7 @@ Name | Type | Description | Notes
# **UploadFileWithRequiredFile**
-> ApiResponse UploadFileWithRequiredFile (long petId, System.IO.Stream requiredFile, string additionalMetadata = null)
+> ApiResponse UploadFileWithRequiredFile (long petId, FileParameter requiredFile, string additionalMetadata = null)
uploads an image (required)
@@ -674,7 +674,7 @@ namespace Example
HttpClientHandler httpClientHandler = new HttpClientHandler();
var apiInstance = new PetApi(httpClient, config, httpClientHandler);
var petId = 789; // long | ID of pet to update
- var requiredFile = BINARY_DATA_HERE; // System.IO.Stream | file to upload
+ var requiredFile = BINARY_DATA_HERE; // FileParameter | file to upload
var additionalMetadata = additionalMetadata_example; // string | Additional data to pass to server (optional)
try
@@ -699,7 +699,7 @@ namespace Example
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**petId** | **long**| ID of pet to update |
- **requiredFile** | **System.IO.Stream****System.IO.Stream**| file to upload |
+ **requiredFile** | **FileParameter****FileParameter**| file to upload |
**additionalMetadata** | **string**| Additional data to pass to server | [optional]
### Return type
diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Api/FakeApi.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Api/FakeApi.cs
index 66f86c619fc..5631e484c0c 100644
--- a/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Api/FakeApi.cs
+++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Api/FakeApi.cs
@@ -227,7 +227,7 @@ namespace Org.OpenAPITools.Api
/// None (optional)
/// None (optional)
///
- void TestEndpointParameters(decimal number, double _double, string patternWithoutDelimiter, byte[] _byte, int? integer = default(int?), int? int32 = default(int?), long? int64 = default(long?), float? _float = default(float?), string _string = default(string), System.IO.Stream binary = default(System.IO.Stream), DateTime? date = default(DateTime?), DateTime? dateTime = default(DateTime?), string password = default(string), string callback = default(string));
+ void TestEndpointParameters(decimal number, double _double, string patternWithoutDelimiter, byte[] _byte, int? integer = default(int?), int? int32 = default(int?), long? int64 = default(long?), float? _float = default(float?), string _string = default(string), FileParameter binary = default(FileParameter), DateTime? date = default(DateTime?), DateTime? dateTime = default(DateTime?), string password = default(string), string callback = default(string));
///
/// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
@@ -251,7 +251,7 @@ namespace Org.OpenAPITools.Api
/// None (optional)
/// None (optional)
/// ApiResponse of Object(void)
- ApiResponse