Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,7 @@ public void addGenericHostSupportingFiles(final String clientPackageDir, final S
supportingFiles.add(new SupportingFile("JsonSerializerOptionsProvider.mustache", clientPackageDir, "JsonSerializerOptionsProvider.cs"));
supportingFiles.add(new SupportingFile("CookieContainer.mustache", clientPackageDir, "CookieContainer.cs"));
supportingFiles.add(new SupportingFile("Option.mustache", clientPackageDir, "Option.cs"));
supportingFiles.add(new SupportingFile("FileParameter.mustache", clientPackageDir, "FileParameter.cs"));

supportingFiles.add(new SupportingFile("IApi.mustache", sourceFolder + File.separator + packageName + File.separator + apiPackage(), getInterfacePrefix() + "Api.cs"));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// <auto-generated>
{{>partial_header}}

{{#nrt}}
#nullable enable

{{/nrt}}
namespace {{packageName}}.{{clientPackage}}
{
/// <summary>
/// Represents a file to be uploaded as part of a multipart/form-data request.
/// </summary>
{{>visibility}} sealed class FileParameter
{
/// <summary>
/// The file content stream.
/// </summary>
public global::System.IO.Stream Content { get; }

/// <summary>
/// The filename sent in the Content-Disposition header.
/// When null the parameter name from the spec is used as a fallback.
/// </summary>
public string{{nrt?}} FileName { get; }

/// <summary>
/// Creates a new <see cref="FileParameter"/>.
/// </summary>
/// <param name="content">The file content stream.</param>
/// <param name="fileName">Optional filename for the Content-Disposition header.</param>
public FileParameter(global::System.IO.Stream content, string{{nrt?}} fileName = null)
{
Content = content;
FileName = fileName;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{#isFile}}{{#isContainer}}List<{{packageName}}.{{clientPackage}}.FileParameter>{{>NullConditionalParameter}}{{/isContainer}}{{^isContainer}}{{packageName}}.{{clientPackage}}.FileParameter{{>NullConditionalParameter}}{{/isContainer}}{{/isFile}}{{^isFile}}{{{dataType}}}{{>NullConditionalParameter}}{{/isFile}}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{#lambda.joinWithComma}}{{#allParams}}{{#required}}{{{dataType}}}{{>NullConditionalParameter}}{{/required}}{{^required}}Option<{{{dataType}}}{{>NullConditionalParameter}}>{{/required}} {{paramName}}{{#notRequiredOrIsNullable}} = default{{/notRequiredOrIsNullable}} {{/allParams}}System.Threading.CancellationToken cancellationToken = default{{^netstandard20OrLater}}(global::System.Threading.CancellationToken){{/netstandard20OrLater}}{{/lambda.joinWithComma}}
{{#lambda.joinWithComma}}{{#allParams}}{{#required}}{{>OperationDataType}}{{/required}}{{^required}}Option<{{>OperationDataType}}>{{/required}} {{paramName}}{{#notRequiredOrIsNullable}} = default{{/notRequiredOrIsNullable}} {{/allParams}}System.Threading.CancellationToken cancellationToken = default{{^netstandard20OrLater}}(global::System.Threading.CancellationToken){{/netstandard20OrLater}}{{/lambda.joinWithComma}}
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ namespace {{packageName}}.{{apiPackage}}

{{#allParams}}
{{#-first}}
partial void Format{{operationId}}({{#allParams}}{{#isPrimitiveType}}ref {{/isPrimitiveType}}{{^required}}Option<{{/required}}{{{dataType}}}{{>NullConditionalParameter}}{{^required}}>{{/required}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}});
partial void Format{{operationId}}({{#allParams}}{{#isPrimitiveType}}ref {{/isPrimitiveType}}{{^required}}Option<{{/required}}{{>OperationDataType}}{{^required}}>{{/required}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}});

{{/-first}}
{{/allParams}}
Expand All @@ -258,7 +258,7 @@ namespace {{packageName}}.{{apiPackage}}
/// <param name="{{paramName}}"></param>
{{/vendorExtensions.x-not-nullable-reference-types}}
/// <returns></returns>
private void Validate{{operationId}}({{#vendorExtensions.x-not-nullable-reference-types}}{{^required}}Option<{{/required}}{{{dataType}}}{{>NullConditionalParameter}}{{^required}}>{{/required}} {{paramName}}{{^-last}}, {{/-last}}{{/vendorExtensions.x-not-nullable-reference-types}})
private void Validate{{operationId}}({{#vendorExtensions.x-not-nullable-reference-types}}{{^required}}Option<{{/required}}{{>OperationDataType}}{{^required}}>{{/required}} {{paramName}}{{^-last}}, {{/-last}}{{/vendorExtensions.x-not-nullable-reference-types}})
{
{{#lambda.trimTrailingWithNewLine}}
{{#vendorExtensions.x-not-nullable-reference-types}}
Expand Down Expand Up @@ -288,7 +288,7 @@ namespace {{packageName}}.{{apiPackage}}
{{#allParams}}
/// <param name="{{paramName}}"></param>
{{/allParams}}
private void After{{operationId}}DefaultImplementation({{#lambda.joinWithComma}}{{interfacePrefix}}{{operationId}}ApiResponse apiResponseLocalVar {{#allParams}}{{^required}}Option<{{/required}}{{{dataType}}}{{>NullConditionalParameter}}{{^required}}>{{/required}} {{paramName}} {{/allParams}}{{/lambda.joinWithComma}})
private void After{{operationId}}DefaultImplementation({{#lambda.joinWithComma}}{{interfacePrefix}}{{operationId}}ApiResponse apiResponseLocalVar {{#allParams}}{{^required}}Option<{{/required}}{{>OperationDataType}}{{^required}}>{{/required}} {{paramName}} {{/allParams}}{{/lambda.joinWithComma}})
{
bool suppressDefaultLog = false;
After{{operationId}}({{#lambda.joinWithComma}}ref suppressDefaultLog apiResponseLocalVar {{#allParams}}{{paramName}} {{/allParams}}{{/lambda.joinWithComma}});
Expand All @@ -303,7 +303,7 @@ namespace {{packageName}}.{{apiPackage}}
{{#allParams}}
/// <param name="{{paramName}}"></param>
{{/allParams}}
partial void After{{operationId}}({{#lambda.joinWithComma}}ref bool suppressDefaultLog {{interfacePrefix}}{{operationId}}ApiResponse apiResponseLocalVar {{#allParams}}{{^required}}Option<{{/required}}{{{dataType}}}{{>NullConditionalParameter}}{{^required}}>{{/required}} {{paramName}} {{/allParams}}{{/lambda.joinWithComma}});
partial void After{{operationId}}({{#lambda.joinWithComma}}ref bool suppressDefaultLog {{interfacePrefix}}{{operationId}}ApiResponse apiResponseLocalVar {{#allParams}}{{^required}}Option<{{/required}}{{>OperationDataType}}{{^required}}>{{/required}} {{paramName}} {{/allParams}}{{/lambda.joinWithComma}});

/// <summary>
/// Logs exceptions that occur while retrieving the server response
Expand All @@ -314,7 +314,7 @@ namespace {{packageName}}.{{apiPackage}}
{{#allParams}}
/// <param name="{{paramName}}"></param>
{{/allParams}}
private void OnError{{operationId}}DefaultImplementation({{#lambda.joinWithComma}}Exception exceptionLocalVar string pathFormatLocalVar string pathLocalVar {{#allParams}}{{^required}}Option<{{/required}}{{{dataType}}}{{>NullConditionalParameter}}{{^required}}>{{/required}} {{paramName}} {{/allParams}}{{/lambda.joinWithComma}})
private void OnError{{operationId}}DefaultImplementation({{#lambda.joinWithComma}}Exception exceptionLocalVar string pathFormatLocalVar string pathLocalVar {{#allParams}}{{^required}}Option<{{/required}}{{>OperationDataType}}{{^required}}>{{/required}} {{paramName}} {{/allParams}}{{/lambda.joinWithComma}})
{
bool suppressDefaultLogLocalVar = false;
OnError{{operationId}}({{#lambda.joinWithComma}}ref suppressDefaultLogLocalVar exceptionLocalVar pathFormatLocalVar pathLocalVar {{#allParams}}{{paramName}} {{/allParams}}{{/lambda.joinWithComma}});
Expand All @@ -332,7 +332,7 @@ namespace {{packageName}}.{{apiPackage}}
{{#allParams}}
/// <param name="{{paramName}}"></param>
{{/allParams}}
partial void OnError{{operationId}}({{#lambda.joinWithComma}}ref bool suppressDefaultLogLocalVar Exception exceptionLocalVar string pathFormatLocalVar string pathLocalVar {{#allParams}}{{^required}}Option<{{/required}}{{{dataType}}}{{>NullConditionalParameter}}{{^required}}>{{/required}} {{paramName}} {{/allParams}}{{/lambda.joinWithComma}});
partial void OnError{{operationId}}({{#lambda.joinWithComma}}ref bool suppressDefaultLogLocalVar Exception exceptionLocalVar string pathFormatLocalVar string pathLocalVar {{#allParams}}{{^required}}Option<{{/required}}{{>OperationDataType}}{{^required}}>{{/required}} {{paramName}} {{/allParams}}{{/lambda.joinWithComma}});

/// <summary>
/// {{summary}} {{notes}}
Expand Down Expand Up @@ -471,35 +471,90 @@ namespace {{packageName}}.{{apiPackage}}
{{/headerParams}}
{{#formParams}}
{{#-first}}
MultipartContent multipartContentLocalVar = new MultipartContent();
{{#isMultipart}}
MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent();

httpRequestMessageLocalVar.Content = multipartContentLocalVar;

List<KeyValuePair<string{{nrt?}}, string{{nrt?}}>> formParameterLocalVars = new List<KeyValuePair<string{{nrt?}}, string{{nrt?}}>>();
{{/isMultipart}}
List<KeyValuePair<string, string{{nrt?}}>> formParameterLocalVars = new List<KeyValuePair<string, string{{nrt?}}>>();

multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars));{{/-first}}{{^isFile}}{{#required}}

formParameterLocalVars.Add(new KeyValuePair<string{{nrt?}}, string{{nrt?}}>("{{baseName}}", ClientUtils.ParameterToString({{paramName}})));
{{/-first}}
{{^isFile}}
{{#required}}
formParameterLocalVars.Add(new KeyValuePair<string, string{{nrt?}}>("{{baseName}}", ClientUtils.ParameterToString({{paramName}})));

{{/required}}
{{^required}}
if ({{paramName}}.IsSet)
formParameterLocalVars.Add(new KeyValuePair<string{{nrt?}}, string{{nrt?}}>("{{baseName}}", ClientUtils.ParameterToString({{paramName}}.Value)));
formParameterLocalVars.Add(new KeyValuePair<string, string{{nrt?}}>("{{baseName}}", ClientUtils.ParameterToString({{paramName}}.Value)));

{{/required}}
{{/isFile}}
{{#isFile}}
{{^isMultipart}}
{{! application/x-www-form-urlencoded encodes everything as text key=value pairs and has no mechanism to carry binary data. File params require multipart/form-data.}}
{{#required}}
multipartContentLocalVar.Add(new StreamContent({{paramName}}));
throw new NotSupportedException("File parameters cannot be sent with application/x-www-form-urlencoded. Change the operation's content type to multipart/form-data.");

{{/required}}
{{^required}}
if ({{paramName}}.IsSet)
multipartContentLocalVar.Add(new StreamContent({{paramName}}.Value));
throw new NotSupportedException("File parameters cannot be sent with application/x-www-form-urlencoded. Change the operation's content type to multipart/form-data.");

{{/required}}
{{/isMultipart}}
{{#isMultipart}}
{{#required}}
{{#isContainer}}
foreach ({{packageName}}.{{clientPackage}}.FileParameter fileParameterLocalVar in {{paramName}})
{
var streamContentLocalVar = new StreamContent(fileParameterLocalVar.Content);
multipartContentLocalVar.Add(streamContentLocalVar, "{{baseName}}", fileParameterLocalVar.FileName ?? "{{baseName}}");
}

{{/isContainer}}
{{^isContainer}}
{
var streamContentLocalVar = new StreamContent({{paramName}}.Content);
multipartContentLocalVar.Add(streamContentLocalVar, "{{baseName}}", {{paramName}}.FileName ?? "{{baseName}}");
}

{{/isContainer}}
{{/required}}
{{^required}}
if ({{paramName}}.IsSet)
{
{{#isContainer}}
foreach ({{packageName}}.{{clientPackage}}.FileParameter fileParameterLocalVar in {{paramName}}.Value)
{
var streamContentLocalVar = new StreamContent(fileParameterLocalVar.Content);
multipartContentLocalVar.Add(streamContentLocalVar, "{{baseName}}", fileParameterLocalVar.FileName ?? "{{baseName}}");
}
{{/isContainer}}
{{^isContainer}}
var streamContentLocalVar = new StreamContent({{paramName}}.Value.Content);
multipartContentLocalVar.Add(streamContentLocalVar, "{{baseName}}", {{paramName}}.Value.FileName ?? "{{baseName}}");
{{/isContainer}}
}

{{/required}}
{{/isMultipart}}
{{/isFile}}
{{/formParams}}
{{#formParams}}
{{#-first}}
{{#isMultipart}}
foreach (var formParamLocalVar in formParameterLocalVars)
multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key);
{{/isMultipart}}
{{^isMultipart}}
if (formParameterLocalVars.Count > 0)
httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars);
{{/isMultipart}}

{{/-first}}
{{/formParams}}
{{#bodyParam}}
{{#required}}
httpRequestMessageLocalVar.Content = ({{paramName}}{{^required}}.Value{{/required}} as object) is System.IO.Stream stream
Expand Down Expand Up @@ -587,10 +642,12 @@ namespace {{packageName}}.{{apiPackage}}
{{#consumes}}
{{#-first}}

{{^formParams}}
string{{nrt?}} contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes);

if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null)
httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar);
{{/formParams}}

{{/-first}}
{{/consumes}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace {{packageName}}.Test.{{apiPackage}}
public async Task {{operationId}}AsyncTest()
{
{{#allParams}}
{{^required}}Client.Option<{{/required}}{{{dataType}}}{{>NullConditionalParameter}}{{^required}}>{{/required}} {{paramName}} = default{{nrt!}};
{{^required}}Client.Option<{{/required}}{{>OperationDataType}}{{^required}}>{{/required}} {{paramName}} = default{{nrt!}};
{{/allParams}}
{{#responses}}
{{#-first}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,46 @@ paths:
description: file to upload
type: string
format: binary
'/pet/{petId}/uploadImages':
post:
tags:
- pet
summary: uploads an images
description: ''
operationId: uploadFiles
parameters:
- name: petId
in: path
description: ID of pet to update
required: true
schema:
type: integer
format: int64
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/ApiResponse'
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
required: true
content:
multipart/form-data:
schema:
type: object
properties:
files:
type: array
items:
type: string
format: binary
required:
- files
/store/inventory:
get:
tags:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ src/Org.OpenAPITools/Client/DateOnlyNullableJsonConverter.cs
src/Org.OpenAPITools/Client/DateTimeJsonConverter.cs
src/Org.OpenAPITools/Client/DateTimeNullableJsonConverter.cs
src/Org.OpenAPITools/Client/ExceptionEventArgs.cs
src/Org.OpenAPITools/Client/FileParameter.cs
src/Org.OpenAPITools/Client/HostConfiguration.cs
src/Org.OpenAPITools/Client/JsonSerializerOptionsProvider.cs
src/Org.OpenAPITools/Client/Option.cs
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// <auto-generated>
/*
* OpenAPI
*
* OpenAPI
*
* The version of the OpenAPI document: 0.0.1
* Generated by: https://github.com/openapitools/openapi-generator.git
*/

#nullable enable

namespace Org.OpenAPITools.Client
{
/// <summary>
/// Represents a file to be uploaded as part of a multipart/form-data request.
/// </summary>
public sealed class FileParameter
{
/// <summary>
/// The file content stream.
/// </summary>
public global::System.IO.Stream Content { get; }

/// <summary>
/// The filename sent in the Content-Disposition header.
/// When null the parameter name from the spec is used as a fallback.
/// </summary>
public string? FileName { get; }

/// <summary>
/// Creates a new <see cref="FileParameter"/>.
/// </summary>
/// <param name="content">The file content stream.</param>
/// <param name="fileName">Optional filename for the Content-Disposition header.</param>
public FileParameter(global::System.IO.Stream content, string? fileName = null)
{
Content = content;
FileName = fileName;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ src/Org.OpenAPITools/Client/DateOnlyNullableJsonConverter.cs
src/Org.OpenAPITools/Client/DateTimeJsonConverter.cs
src/Org.OpenAPITools/Client/DateTimeNullableJsonConverter.cs
src/Org.OpenAPITools/Client/ExceptionEventArgs.cs
src/Org.OpenAPITools/Client/FileParameter.cs
src/Org.OpenAPITools/Client/HostConfiguration.cs
src/Org.OpenAPITools/Client/JsonSerializerOptionsProvider.cs
src/Org.OpenAPITools/Client/Option.cs
Expand Down
Loading
Loading