diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpClientCodegen.java index 7d9b56b846e9..e087bfda2a25 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpClientCodegen.java @@ -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")); diff --git a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/FileParameter.mustache b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/FileParameter.mustache new file mode 100644 index 000000000000..6ebbfa231fec --- /dev/null +++ b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/FileParameter.mustache @@ -0,0 +1,37 @@ +// +{{>partial_header}} + +{{#nrt}} +#nullable enable + +{{/nrt}} +namespace {{packageName}}.{{clientPackage}} +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + {{>visibility}} sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string{{nrt?}} FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string{{nrt?}} fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/OperationDataType.mustache b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/OperationDataType.mustache new file mode 100644 index 000000000000..1cd619e131f6 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/OperationDataType.mustache @@ -0,0 +1 @@ +{{#isFile}}{{#isContainer}}List<{{packageName}}.{{clientPackage}}.FileParameter>{{>NullConditionalParameter}}{{/isContainer}}{{^isContainer}}{{packageName}}.{{clientPackage}}.FileParameter{{>NullConditionalParameter}}{{/isContainer}}{{/isFile}}{{^isFile}}{{{dataType}}}{{>NullConditionalParameter}}{{/isFile}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/OperationSignature.mustache b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/OperationSignature.mustache index caa9d144c52d..1d03c47e332c 100644 --- a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/OperationSignature.mustache +++ b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/OperationSignature.mustache @@ -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}} \ No newline at end of file +{{#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}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/api.mustache b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/api.mustache index f75235833fbe..b7cb22444daa 100644 --- a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/api.mustache +++ b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/api.mustache @@ -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}} @@ -258,7 +258,7 @@ namespace {{packageName}}.{{apiPackage}} /// {{/vendorExtensions.x-not-nullable-reference-types}} /// - 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}} @@ -288,7 +288,7 @@ namespace {{packageName}}.{{apiPackage}} {{#allParams}} /// {{/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}}); @@ -303,7 +303,7 @@ namespace {{packageName}}.{{apiPackage}} {{#allParams}} /// {{/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}}); /// /// Logs exceptions that occur while retrieving the server response @@ -314,7 +314,7 @@ namespace {{packageName}}.{{apiPackage}} {{#allParams}} /// {{/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}}); @@ -332,7 +332,7 @@ namespace {{packageName}}.{{apiPackage}} {{#allParams}} /// {{/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}} {{notes}} @@ -471,35 +471,90 @@ namespace {{packageName}}.{{apiPackage}} {{/headerParams}} {{#formParams}} {{#-first}} - MultipartContent multipartContentLocalVar = new MultipartContent(); + {{#isMultipart}} + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); + {{/isMultipart}} + List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars));{{/-first}}{{^isFile}}{{#required}} - - formParameterLocalVars.Add(new KeyValuePair("{{baseName}}", ClientUtils.ParameterToString({{paramName}}))); + {{/-first}} + {{^isFile}} + {{#required}} + formParameterLocalVars.Add(new KeyValuePair("{{baseName}}", ClientUtils.ParameterToString({{paramName}}))); {{/required}} {{^required}} if ({{paramName}}.IsSet) - formParameterLocalVars.Add(new KeyValuePair("{{baseName}}", ClientUtils.ParameterToString({{paramName}}.Value))); + formParameterLocalVars.Add(new KeyValuePair("{{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 @@ -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}} diff --git a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/api_test.mustache b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/api_test.mustache index 32eb2b769f31..7e0b704c1a01 100644 --- a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/api_test.mustache +++ b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/api_test.mustache @@ -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}} diff --git a/modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml b/modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml index 1c9e901ad0dd..2edf96c9c3c3 100644 --- a/modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml @@ -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: diff --git a/samples/client/petstore/csharp/generichost/latest/ComposedEnum/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/latest/ComposedEnum/.openapi-generator/FILES index a0b893ad3a65..088165b19c1d 100644 --- a/samples/client/petstore/csharp/generichost/latest/ComposedEnum/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/latest/ComposedEnum/.openapi-generator/FILES @@ -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 diff --git a/samples/client/petstore/csharp/generichost/latest/ComposedEnum/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/latest/ComposedEnum/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..42e3a7879497 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/latest/ComposedEnum/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,42 @@ +// +/* + * 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 +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string? FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string? fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/latest/HelloWorld/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/latest/HelloWorld/.openapi-generator/FILES index 479e2c02cc5c..7e49740eadbb 100644 --- a/samples/client/petstore/csharp/generichost/latest/HelloWorld/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/latest/HelloWorld/.openapi-generator/FILES @@ -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 diff --git a/samples/client/petstore/csharp/generichost/latest/HelloWorld/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/latest/HelloWorld/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..edb0bd0479a5 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/latest/HelloWorld/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,42 @@ +// +/* + * Minimal reproduction for csharp webhook bug + * + * This is an example API to reproduce a bug with webhooks in csharp codegen + * + * The version of the OpenAPI document: 1.0.0 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +#nullable enable + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string? FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string? fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/latest/InlineEnumAnyOf/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/latest/InlineEnumAnyOf/.openapi-generator/FILES index 8f168c503eca..7c3137c1b51f 100644 --- a/samples/client/petstore/csharp/generichost/latest/InlineEnumAnyOf/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/latest/InlineEnumAnyOf/.openapi-generator/FILES @@ -26,6 +26,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 diff --git a/samples/client/petstore/csharp/generichost/latest/InlineEnumAnyOf/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/latest/InlineEnumAnyOf/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..77779fe7d75a --- /dev/null +++ b/samples/client/petstore/csharp/generichost/latest/InlineEnumAnyOf/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,42 @@ +// +/* + * OpenAPI Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +#nullable enable + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string? FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string? fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/latest/OneOfList/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/latest/OneOfList/.openapi-generator/FILES index c3094ea1e371..54155a05db81 100644 --- a/samples/client/petstore/csharp/generichost/latest/OneOfList/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/latest/OneOfList/.openapi-generator/FILES @@ -24,6 +24,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 diff --git a/samples/client/petstore/csharp/generichost/latest/OneOfList/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/latest/OneOfList/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..f5b898e16331 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/latest/OneOfList/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,42 @@ +// +/* + * Oneof array test + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +#nullable enable + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string? FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string? fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/latest/Tags/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/latest/Tags/.openapi-generator/FILES index b08037a54926..27397861417c 100644 --- a/samples/client/petstore/csharp/generichost/latest/Tags/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/latest/Tags/.openapi-generator/FILES @@ -27,6 +27,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 diff --git a/samples/client/petstore/csharp/generichost/latest/Tags/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/latest/Tags/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..1e3e3f9f418f --- /dev/null +++ b/samples/client/petstore/csharp/generichost/latest/Tags/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,43 @@ +// +/* + * Files.com API + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 0.0.1 + * Contact: support@files.com + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +#nullable enable + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string? FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string? fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net10/AllOf/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net10/AllOf/.openapi-generator/FILES index b9ab612bd8b5..46a8286dea29 100644 --- a/samples/client/petstore/csharp/generichost/net10/AllOf/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net10/AllOf/.openapi-generator/FILES @@ -25,6 +25,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 diff --git a/samples/client/petstore/csharp/generichost/net10/AllOf/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net10/AllOf/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..1913a3a0f2d9 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net10/AllOf/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,42 @@ +// +/* + * Example + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +#nullable enable + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string? FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string? fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net10/AnyOf/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net10/AnyOf/.openapi-generator/FILES index dc42a5d47091..072cc8408121 100644 --- a/samples/client/petstore/csharp/generichost/net10/AnyOf/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net10/AnyOf/.openapi-generator/FILES @@ -25,6 +25,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 diff --git a/samples/client/petstore/csharp/generichost/net10/AnyOf/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net10/AnyOf/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..e629f4afdaec --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net10/AnyOf/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,42 @@ +// +/* + * fruity + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 0.0.1 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +#nullable enable + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string? FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string? fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net10/AnyOfNoCompare/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net10/AnyOfNoCompare/.openapi-generator/FILES index dc42a5d47091..072cc8408121 100644 --- a/samples/client/petstore/csharp/generichost/net10/AnyOfNoCompare/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net10/AnyOfNoCompare/.openapi-generator/FILES @@ -25,6 +25,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 diff --git a/samples/client/petstore/csharp/generichost/net10/AnyOfNoCompare/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net10/AnyOfNoCompare/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..e629f4afdaec --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net10/AnyOfNoCompare/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,42 @@ +// +/* + * fruity + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 0.0.1 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +#nullable enable + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string? FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string? fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net10/FormModels/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net10/FormModels/.openapi-generator/FILES index a9823b3075fd..737d53400248 100644 --- a/samples/client/petstore/csharp/generichost/net10/FormModels/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net10/FormModels/.openapi-generator/FILES @@ -165,6 +165,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/HttpSigningConfiguration.cs src/Org.OpenAPITools/Client/HttpSigningToken.cs diff --git a/samples/client/petstore/csharp/generichost/net10/FormModels/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net10/FormModels/api/openapi.yaml index a9ab8dd51c13..7017affc0b9c 100644 --- a/samples/client/petstore/csharp/generichost/net10/FormModels/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net10/FormModels/api/openapi.yaml @@ -326,6 +326,40 @@ paths: summary: uploads an image tags: - pet + /pet/{petId}/uploadImages: + post: + description: "" + operationId: uploadFiles + parameters: + - description: ID of pet to update + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + multipart/form-data: + schema: + $ref: "#/components/schemas/uploadFiles_request" + required: true + responses: + "200": + content: + application/json: + schema: + $ref: "#/components/schemas/ApiResponse" + description: successful operation + security: + - petstore_auth: + - write:pets + - read:pets + summary: uploads an images + tags: + - pet /store/inventory: get: description: Returns a map of status codes to quantities @@ -2748,6 +2782,16 @@ components: format: binary type: string type: object + uploadFiles_request: + properties: + files: + items: + format: binary + type: string + type: array + required: + - files + type: object testEnumParameters_request_enum_form_string_array_inner: default: $ enum: diff --git a/samples/client/petstore/csharp/generichost/net10/FormModels/docs/apis/PetApi.md b/samples/client/petstore/csharp/generichost/net10/FormModels/docs/apis/PetApi.md index e32c1e31e089..59d4ef8e6df0 100644 --- a/samples/client/petstore/csharp/generichost/net10/FormModels/docs/apis/PetApi.md +++ b/samples/client/petstore/csharp/generichost/net10/FormModels/docs/apis/PetApi.md @@ -13,6 +13,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* | [**UpdatePetWithForm**](PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data | | [**UploadFile**](PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image | | [**UploadFileWithRequiredFile**](PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) | +| [**UploadFiles**](PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images | # **AddPet** @@ -341,3 +342,38 @@ uploads an image (required) [[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + +# **UploadFiles** +> ApiResponse UploadFiles (List files, long petId) + +uploads an images + + +### Parameters + +| Name | Type | Description | Notes | +|------|------|-------------|-------| +| **files** | **List<System.IO.Stream>** | | | +| **petId** | **long** | ID of pet to update | | + +### Return type + +[**ApiResponse**](ApiResponse.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: multipart/form-data + - **Accept**: application/json + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | + +[[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + diff --git a/samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs b/samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs index 495d785314c5..1924842cdbef 100644 --- a/samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs @@ -196,7 +196,7 @@ public async Task TestEndpointParametersAsyncTest() string patternWithoutDelimiter = default; byte[] varByte = default; double varDouble = default; - Client.Option binary = default; + Client.Option binary = default; Client.Option callback = default; Client.Option date = default; Client.Option dateTime = default; diff --git a/samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 1f1d7f6c4576..a4aa8f3e245d 100644 --- a/samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools.Test/Api/PetApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools.Test/Api/PetApiTests.cs @@ -137,7 +137,7 @@ public async Task UploadFileAsyncTest() { long petId = default; Client.Option additionalMetadata = default; - Client.Option file = default; + Client.Option file = default; var response = await _instance.UploadFileAsync(petId, additionalMetadata, file); var model = response.Ok(); Assert.IsType(model); @@ -150,11 +150,24 @@ public async Task UploadFileAsyncTest() public async Task UploadFileWithRequiredFileAsyncTest() { long petId = default; - System.IO.Stream requiredFile = default; + Org.OpenAPITools.Client.FileParameter requiredFile = default; Client.Option additionalMetadata = default; var response = await _instance.UploadFileWithRequiredFileAsync(petId, requiredFile, additionalMetadata); var model = response.Ok(); Assert.IsType(model); } + + /// + /// Test UploadFiles + /// + [Fact (Skip = "not implemented")] + public async Task UploadFilesAsyncTest() + { + List files = default; + long petId = default; + var response = await _instance.UploadFilesAsync(files, petId); + var model = response.Ok(); + Assert.IsType(model); + } } } diff --git a/samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Api/DefaultApi.cs index 3c26a27185e6..44d52e7e1090 100644 --- a/samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Api/DefaultApi.cs +++ b/samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Api/DefaultApi.cs @@ -764,27 +764,19 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Api/FakeApi.cs b/samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Api/FakeApi.cs index 2a332dbf1eb9..0070617289e6 100644 --- a/samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Api/FakeApi.cs +++ b/samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Api/FakeApi.cs @@ -330,7 +330,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <> - Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -354,7 +354,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <> - Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// To test enum parameters @@ -4080,7 +4080,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); + partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); /// /// Validates the request parameters @@ -4092,7 +4092,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) + private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) { if (patternWithoutDelimiter == null) throw new ArgumentNullException(nameof(patternWithoutDelimiter)); @@ -4131,7 +4131,7 @@ private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte /// /// /// - private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLog = false; AfterTestEndpointParameters(ref suppressDefaultLog, apiResponseLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4158,7 +4158,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Logs exceptions that occur while retrieving the server response @@ -4180,7 +4180,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLogLocalVar = false; OnErrorTestEndpointParameters(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4209,7 +4209,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// /// /// - partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -4230,7 +4230,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -4262,7 +4262,7 @@ public async Task TestEndpointParametersOrDe /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -4281,14 +4281,8 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("number", ClientUtils.ParameterToString(number))); formParameterLocalVars.Add(new KeyValuePair("pattern_without_delimiter", ClientUtils.ParameterToString(patternWithoutDelimiter))); @@ -4298,7 +4292,7 @@ public async Task TestEndpointParametersAsyn formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.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."); if (callback.IsSet) formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); @@ -4327,6 +4321,9 @@ public async Task TestEndpointParametersAsyn if (varString.IsSet) formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4340,11 +4337,6 @@ public async Task TestEndpointParametersAsyn "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -4625,29 +4617,23 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (enumFormString.IsSet) + if (enumFormString.IsSet) formParameterLocalVars.Add(new KeyValuePair("enum_form_string", ClientUtils.ParameterToString(enumFormString.Value))); if (enumFormStringArray.IsSet) formParameterLocalVars.Add(new KeyValuePair("enum_form_string_array", ClientUtils.ParameterToString(enumFormStringArray.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Get; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -5534,29 +5520,21 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("param", ClientUtils.ParameterToString(param))); formParameterLocalVars.Add(new KeyValuePair("param2", ClientUtils.ParameterToString(param2))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Get; DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Api/PetApi.cs b/samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Api/PetApi.cs index d07d16c30828..fd403446d9a6 100644 --- a/samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Api/PetApi.cs +++ b/samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Api/PetApi.cs @@ -216,7 +216,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image @@ -229,7 +229,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -243,7 +243,7 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -256,7 +256,32 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); } /// @@ -415,6 +440,18 @@ public interface IUploadFileWithRequiredFileApiResponse : Org.OpenAPITools.Clien bool IsOk { get; } } + /// + /// The + /// + public interface IUploadFilesApiResponse : Org.OpenAPITools.Client.IApiResponse, IOk + { + /// + /// Returns true if the response is 200 Ok + /// + /// + bool IsOk { get; } + } + /// /// Represents a collection of functions to interact with the API endpoints /// @@ -599,6 +636,26 @@ internal void ExecuteOnErrorUploadFileWithRequiredFile(Exception exception) { OnErrorUploadFileWithRequiredFile?.Invoke(this, new ExceptionEventArgs(exception)); } + + /// + /// The event raised after the server response + /// + public event EventHandler OnUploadFiles; + + /// + /// The event raised after an error querying the server + /// + public event EventHandler OnErrorUploadFiles; + + internal void ExecuteOnUploadFiles(PetApi.UploadFilesApiResponse apiResponse) + { + OnUploadFiles?.Invoke(this, new ApiResponseEventArgs(apiResponse)); + } + + internal void ExecuteOnErrorUploadFiles(Exception exception) + { + OnErrorUploadFiles?.Invoke(this, new ExceptionEventArgs(exception)); + } } /// @@ -2330,18 +2387,17 @@ public async Task UpdatePetWithFormAsync(long pet : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (name.IsSet) + if (name.IsSet) formParameterLocalVars.Add(new KeyValuePair("name", ClientUtils.ParameterToString(name.Value))); if (status.IsSet) formParameterLocalVars.Add(new KeyValuePair("status", ClientUtils.ParameterToString(status.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2355,11 +2411,6 @@ public async Task UpdatePetWithFormAsync(long pet "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -2459,7 +2510,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); + partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); /// /// Validates the request parameters @@ -2467,7 +2518,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFile(Option additionalMetadata, Option file) + private void ValidateUploadFile(Option additionalMetadata, Option file) { if (additionalMetadata.IsSet && additionalMetadata.Value == null) throw new ArgumentNullException(nameof(additionalMetadata)); @@ -2483,7 +2534,7 @@ private void ValidateUploadFile(Option additionalMetadata, Option /// /// - private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) + private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLog = false; AfterUploadFile(ref suppressDefaultLog, apiResponseLocalVar, petId, additionalMetadata, file); @@ -2499,7 +2550,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); + partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); /// /// Logs exceptions that occur while retrieving the server response @@ -2510,7 +2561,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) + private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, additionalMetadata, file); @@ -2528,7 +2579,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// /// /// - partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); + partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); /// /// uploads an image @@ -2538,7 +2589,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2559,7 +2610,7 @@ public async Task UploadFileOrDefaultAsync(long petId, O /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2579,17 +2630,23 @@ public async Task UploadFileAsync(long petId, Option> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (additionalMetadata.IsSet) + if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); if (file.IsSet) - multipartContentLocalVar.Add(new StreamContent(file.Value)); + { + var streamContentLocalVar = new StreamContent(file.Value.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "file", file.Value.FileName ?? "file"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2604,11 +2661,6 @@ public async Task UploadFileAsync(long petId, Option additionalMetadata); + partial void FormatUploadFileWithRequiredFile(ref long petId, ref Org.OpenAPITools.Client.FileParameter requiredFile, ref Option additionalMetadata); /// /// Validates the request parameters @@ -2757,7 +2809,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, Option additionalMetadata) + private void ValidateUploadFileWithRequiredFile(Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { if (requiredFile == null) throw new ArgumentNullException(nameof(requiredFile)); @@ -2773,7 +2825,7 @@ private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, O /// /// /// - private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLog = false; AfterUploadFileWithRequiredFile(ref suppressDefaultLog, apiResponseLocalVar, petId, requiredFile, additionalMetadata); @@ -2789,7 +2841,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// Logs exceptions that occur while retrieving the server response @@ -2800,7 +2852,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFileWithRequiredFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, requiredFile, additionalMetadata); @@ -2818,7 +2870,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// /// /// - partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// uploads an image (required) @@ -2828,7 +2880,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2849,7 +2901,7 @@ public async Task UploadFileWithRequired /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2869,17 +2921,23 @@ public async Task UploadFileWithRequired : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/{petId}/uploadImageWithRequiredFile"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); multipartContentLocalVar.Add(new StreamContent(requiredFile)); + { + var streamContentLocalVar = new StreamContent(requiredFile.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile", requiredFile.FileName ?? "requiredFile"); + } if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2893,11 +2951,6 @@ public async Task UploadFileWithRequired "multipart/form-data" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - string[] acceptLocalVars = new string[] { "application/json", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" @@ -3038,5 +3091,283 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } + + partial void FormatUploadFiles(List files, ref long petId); + + /// + /// Validates the request parameters + /// + /// + /// + private void ValidateUploadFiles(List files) + { + if (files == null) + throw new ArgumentNullException(nameof(files)); + } + + /// + /// Processes the server response + /// + /// + /// + /// + private void AfterUploadFilesDefaultImplementation(IUploadFilesApiResponse apiResponseLocalVar, List files, long petId) + { + bool suppressDefaultLog = false; + AfterUploadFiles(ref suppressDefaultLog, apiResponseLocalVar, files, petId); + if (!suppressDefaultLog) + Logger.LogInformation("{0,-9} | {1} | {2}", (apiResponseLocalVar.DownloadedAt - apiResponseLocalVar.RequestedAt).TotalSeconds, apiResponseLocalVar.StatusCode, apiResponseLocalVar.Path); + } + + /// + /// Processes the server response + /// + /// + /// + /// + /// + partial void AfterUploadFiles(ref bool suppressDefaultLog, IUploadFilesApiResponse apiResponseLocalVar, List files, long petId); + + /// + /// Logs exceptions that occur while retrieving the server response + /// + /// + /// + /// + /// + /// + private void OnErrorUploadFilesDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId) + { + bool suppressDefaultLogLocalVar = false; + OnErrorUploadFiles(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, files, petId); + if (!suppressDefaultLogLocalVar) + Logger.LogError(exceptionLocalVar, "An error occurred while sending the request to the server."); + } + + /// + /// A partial method that gives developers a way to provide customized exception handling + /// + /// + /// + /// + /// + /// + /// + partial void OnErrorUploadFiles(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId); + + /// + /// uploads an images + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + try + { + return await UploadFilesAsync(files, petId, cancellationToken).ConfigureAwait(false); + } + catch (Exception) + { + return null; + } + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + UriBuilder uriBuilderLocalVar = new UriBuilder(); + + try + { + ValidateUploadFiles(files); + + FormatUploadFiles(files, ref petId); + + using (HttpRequestMessage httpRequestMessageLocalVar = new HttpRequestMessage()) + { + uriBuilderLocalVar.Host = HttpClient.BaseAddress.Host; + uriBuilderLocalVar.Port = HttpClient.BaseAddress.Port; + uriBuilderLocalVar.Scheme = HttpClient.BaseAddress.Scheme; + uriBuilderLocalVar.Path = HttpClient.BaseAddress.AbsolutePath == "/" + ? "/pet/{petId}/uploadImages" + : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}/uploadImages"); + uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); + + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); + + httpRequestMessageLocalVar.Content = multipartContentLocalVar; + + List> formParameterLocalVars = new List>(); + + foreach (Org.OpenAPITools.Client.FileParameter fileParameterLocalVar in files) + { + var streamContentLocalVar = new StreamContent(fileParameterLocalVar.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "files", fileParameterLocalVar.FileName ?? "files"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); + + List tokenBaseLocalVars = new List(); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; + + OAuthToken oauthTokenLocalVar1 = (OAuthToken) await OauthTokenProvider.GetAsync(cancellation: cancellationToken).ConfigureAwait(false); + + tokenBaseLocalVars.Add(oauthTokenLocalVar1); + + oauthTokenLocalVar1.UseInHeader(httpRequestMessageLocalVar, ""); + + string[] contentTypes = new string[] { + "multipart/form-data" + }; + + string[] acceptLocalVars = new string[] { + "application/json" + }; + + IEnumerable acceptHeaderValuesLocalVar = ClientUtils.SelectHeaderAcceptArray(acceptLocalVars); + + foreach (var acceptLocalVar in acceptHeaderValuesLocalVar) + httpRequestMessageLocalVar.Headers.Accept.Add(acceptLocalVar); + + httpRequestMessageLocalVar.Method = HttpMethod.Post; + + DateTime requestedAtLocalVar = DateTime.UtcNow; + + using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false)) + { + ILogger apiResponseLoggerLocalVar = LoggerFactory.CreateLogger(); + UploadFilesApiResponse apiResponseLocalVar; + + switch ((int)httpResponseMessageLocalVar.StatusCode) { + default: { + string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + apiResponseLocalVar = new(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/pet/{petId}/uploadImages", requestedAtLocalVar, _jsonSerializerOptions); + + break; + } + } + + AfterUploadFilesDefaultImplementation(apiResponseLocalVar, files, petId); + + Events.ExecuteOnUploadFiles(apiResponseLocalVar); + + if (apiResponseLocalVar.StatusCode == (HttpStatusCode) 429) + foreach(TokenBase tokenBaseLocalVar in tokenBaseLocalVars) + tokenBaseLocalVar.BeginRateLimit(); + + return apiResponseLocalVar; + } + } + } + catch(Exception e) + { + OnErrorUploadFilesDefaultImplementation(e, "/pet/{petId}/uploadImages", uriBuilderLocalVar.Path, files, petId); + Events.ExecuteOnErrorUploadFiles(e); + throw; + } + } + + /// + /// The + /// + public partial class UploadFilesApiResponse : Org.OpenAPITools.Client.ApiResponse, IUploadFilesApiResponse + { + /// + /// The logger + /// + public ILogger Logger { get; } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, string rawContent, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, rawContent, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, System.IO.Stream contentStream, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, contentStream, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + partial void OnCreated(global::System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage); + + /// + /// Returns true if the response is 200 Ok + /// + /// + public bool IsOk => 200 == (int)StatusCode; + + /// + /// Deserializes the response if the response is 200 Ok + /// + /// + public Org.OpenAPITools.Model.ApiResponse Ok() + { + // This logic may be modified with the AsModel.mustache template + return IsOk + ? System.Text.Json.JsonSerializer.Deserialize(RawContent, _jsonSerializerOptions) + : null; + } + + /// + /// Returns true if the response is 200 Ok and the deserialized response is not null + /// + /// + /// + public bool TryOk([NotNullWhen(true)]out Org.OpenAPITools.Model.ApiResponse result) + { + result = null; + + try + { + result = Ok(); + } catch (Exception e) + { + OnDeserializationErrorDefaultImplementation(e, (HttpStatusCode)200); + } + + return result != null; + } + + private void OnDeserializationErrorDefaultImplementation(Exception exception, HttpStatusCode httpStatusCode) + { + bool suppressDefaultLog = false; + OnDeserializationError(ref suppressDefaultLog, exception, httpStatusCode); + if (!suppressDefaultLog) + Logger.LogError(exception, "An error occurred while deserializing the {code} response.", httpStatusCode); + } + + partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); + } } } diff --git a/samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..6150dbcf4774 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,40 @@ +// +/* + * OpenAPI Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/.openapi-generator/FILES index ab28c754b4b1..a3e02b328e0a 100644 --- a/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/.openapi-generator/FILES @@ -140,6 +140,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/HttpSigningConfiguration.cs src/Org.OpenAPITools/Client/HttpSigningToken.cs diff --git a/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/api/openapi.yaml index d8106a5755fc..ca451f3fb832 100644 --- a/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/api/openapi.yaml @@ -331,6 +331,40 @@ paths: summary: uploads an image tags: - pet + /pet/{petId}/uploadImages: + post: + description: "" + operationId: uploadFiles + parameters: + - description: ID of pet to update + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + multipart/form-data: + schema: + $ref: "#/components/schemas/uploadFiles_request" + required: true + responses: + "200": + content: + application/json: + schema: + $ref: "#/components/schemas/ApiResponse" + description: successful operation + security: + - petstore_auth: + - write:pets + - read:pets + summary: uploads an images + tags: + - pet /store/inventory: get: description: Returns a map of status codes to quantities @@ -2924,6 +2958,16 @@ components: format: binary type: string type: object + uploadFiles_request: + properties: + files: + items: + format: binary + type: string + type: array + required: + - files + type: object testEnumParameters_request: properties: enum_form_string_array: diff --git a/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/docs/apis/PetApi.md b/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/docs/apis/PetApi.md index 2826ea00f728..b42ee516b313 100644 --- a/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/docs/apis/PetApi.md +++ b/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/docs/apis/PetApi.md @@ -13,6 +13,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* | [**UpdatePetWithForm**](PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data | | [**UploadFile**](PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image | | [**UploadFileWithRequiredFile**](PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) | +| [**UploadFiles**](PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images | # **AddPet** @@ -341,3 +342,38 @@ uploads an image (required) [[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + +# **UploadFiles** +> ApiResponse UploadFiles (List files, long petId) + +uploads an images + + +### Parameters + +| Name | Type | Description | Notes | +|------|------|-------------|-------| +| **files** | **List<System.IO.Stream>** | | | +| **petId** | **long** | ID of pet to update | | + +### Return type + +[**ApiResponse**](ApiResponse.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: multipart/form-data + - **Accept**: application/json + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | + +[[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + diff --git a/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs b/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs index 406dbc964a6d..d207bb93dc69 100644 --- a/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs @@ -196,7 +196,7 @@ public async Task TestEndpointParametersAsyncTest() string patternWithoutDelimiter = default!; byte[] varByte = default!; double varDouble = default!; - Client.Option binary = default!; + Client.Option binary = default!; Client.Option callback = default!; Client.Option date = default!; Client.Option dateTime = default!; diff --git a/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/src/Org.OpenAPITools.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 49e7b21b53c2..6bb1f953987c 100644 --- a/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/src/Org.OpenAPITools.Test/Api/PetApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/src/Org.OpenAPITools.Test/Api/PetApiTests.cs @@ -137,7 +137,7 @@ public async Task UploadFileAsyncTest() { long petId = default!; Client.Option additionalMetadata = default!; - Client.Option file = default!; + Client.Option file = default!; var response = await _instance.UploadFileAsync(petId, additionalMetadata, file); var model = response.Ok(); Assert.IsType(model); @@ -150,11 +150,24 @@ public async Task UploadFileAsyncTest() public async Task UploadFileWithRequiredFileAsyncTest() { long petId = default!; - System.IO.Stream requiredFile = default!; + Org.OpenAPITools.Client.FileParameter requiredFile = default!; Client.Option additionalMetadata = default!; var response = await _instance.UploadFileWithRequiredFileAsync(petId, requiredFile, additionalMetadata); var model = response.Ok(); Assert.IsType(model); } + + /// + /// Test UploadFiles + /// + [Fact (Skip = "not implemented")] + public async Task UploadFilesAsyncTest() + { + List files = default!; + long petId = default!; + var response = await _instance.UploadFilesAsync(files, petId); + var model = response.Ok(); + Assert.IsType(model); + } } } diff --git a/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/src/Org.OpenAPITools/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/src/Org.OpenAPITools/Api/DefaultApi.cs index 2391c7e1ee03..46b798fe32ca 100644 --- a/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/src/Org.OpenAPITools/Api/DefaultApi.cs +++ b/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/src/Org.OpenAPITools/Api/DefaultApi.cs @@ -766,15 +766,12 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + List> formParameterLocalVars = new List>(); - httpRequestMessageLocalVar.Content = multipartContentLocalVar; + formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); - List> formParameterLocalVars = new List>(); - - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -782,11 +779,6 @@ public async Task GetCountryAsync(string country, System "application/x-www-form-urlencoded" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/src/Org.OpenAPITools/Api/FakeApi.cs b/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/src/Org.OpenAPITools/Api/FakeApi.cs index 262a94ef2520..54a1c8c85360 100644 --- a/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/src/Org.OpenAPITools/Api/FakeApi.cs +++ b/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/src/Org.OpenAPITools/Api/FakeApi.cs @@ -332,7 +332,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <> - Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -356,7 +356,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <?> - Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// To test enum parameters @@ -4082,7 +4082,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); + partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); /// /// Validates the request parameters @@ -4094,7 +4094,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) + private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) { if (patternWithoutDelimiter == null) throw new ArgumentNullException(nameof(patternWithoutDelimiter)); @@ -4133,7 +4133,7 @@ private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte /// /// /// - private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLog = false; AfterTestEndpointParameters(ref suppressDefaultLog, apiResponseLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4160,7 +4160,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Logs exceptions that occur while retrieving the server response @@ -4182,7 +4182,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLogLocalVar = false; OnErrorTestEndpointParameters(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4211,7 +4211,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// /// /// - partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -4232,7 +4232,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -4264,7 +4264,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -4283,51 +4283,48 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + List> formParameterLocalVars = new List>(); - httpRequestMessageLocalVar.Content = multipartContentLocalVar; + formParameterLocalVars.Add(new KeyValuePair("number", ClientUtils.ParameterToString(number))); - List> formParameterLocalVars = new List>(); + formParameterLocalVars.Add(new KeyValuePair("pattern_without_delimiter", ClientUtils.ParameterToString(patternWithoutDelimiter))); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + formParameterLocalVars.Add(new KeyValuePair("byte", ClientUtils.ParameterToString(varByte))); - formParameterLocalVars.Add(new KeyValuePair("number", ClientUtils.ParameterToString(number))); - - formParameterLocalVars.Add(new KeyValuePair("pattern_without_delimiter", ClientUtils.ParameterToString(patternWithoutDelimiter))); - - formParameterLocalVars.Add(new KeyValuePair("byte", ClientUtils.ParameterToString(varByte))); - - formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); + formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.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."); if (callback.IsSet) - formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); + formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); if (date.IsSet) - formParameterLocalVars.Add(new KeyValuePair("date", ClientUtils.ParameterToString(date.Value))); + formParameterLocalVars.Add(new KeyValuePair("date", ClientUtils.ParameterToString(date.Value))); if (dateTime.IsSet) - formParameterLocalVars.Add(new KeyValuePair("dateTime", ClientUtils.ParameterToString(dateTime.Value))); + formParameterLocalVars.Add(new KeyValuePair("dateTime", ClientUtils.ParameterToString(dateTime.Value))); if (int32.IsSet) - formParameterLocalVars.Add(new KeyValuePair("int32", ClientUtils.ParameterToString(int32.Value))); + formParameterLocalVars.Add(new KeyValuePair("int32", ClientUtils.ParameterToString(int32.Value))); if (int64.IsSet) - formParameterLocalVars.Add(new KeyValuePair("int64", ClientUtils.ParameterToString(int64.Value))); + formParameterLocalVars.Add(new KeyValuePair("int64", ClientUtils.ParameterToString(int64.Value))); if (integer.IsSet) - formParameterLocalVars.Add(new KeyValuePair("integer", ClientUtils.ParameterToString(integer.Value))); + formParameterLocalVars.Add(new KeyValuePair("integer", ClientUtils.ParameterToString(integer.Value))); if (password.IsSet) - formParameterLocalVars.Add(new KeyValuePair("password", ClientUtils.ParameterToString(password.Value))); + formParameterLocalVars.Add(new KeyValuePair("password", ClientUtils.ParameterToString(password.Value))); if (varFloat.IsSet) - formParameterLocalVars.Add(new KeyValuePair("float", ClientUtils.ParameterToString(varFloat.Value))); + formParameterLocalVars.Add(new KeyValuePair("float", ClientUtils.ParameterToString(varFloat.Value))); if (varString.IsSet) - formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4342,11 +4339,6 @@ public async Task TestEndpointParametersAsyn "application/x-www-form-urlencoded" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -4639,17 +4631,16 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); + List> formParameterLocalVars = new List>(); - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - - List> formParameterLocalVars = new List>(); - - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (enumFormString.IsSet) - formParameterLocalVars.Add(new KeyValuePair("enum_form_string", ClientUtils.ParameterToString(enumFormString.Value))); + if (enumFormString.IsSet) + formParameterLocalVars.Add(new KeyValuePair("enum_form_string", ClientUtils.ParameterToString(enumFormString.Value))); if (enumFormStringArray.IsSet) - formParameterLocalVars.Add(new KeyValuePair("enum_form_string_array", ClientUtils.ParameterToString(enumFormStringArray.Value))); + formParameterLocalVars.Add(new KeyValuePair("enum_form_string_array", ClientUtils.ParameterToString(enumFormStringArray.Value))); + + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4657,11 +4648,6 @@ public async Task TestEnumParametersAsync(Option "application/x-www-form-urlencoded" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Get; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -5548,17 +5534,14 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; + List> formParameterLocalVars = new List>(); - List> formParameterLocalVars = new List>(); + formParameterLocalVars.Add(new KeyValuePair("param", ClientUtils.ParameterToString(param))); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + formParameterLocalVars.Add(new KeyValuePair("param2", ClientUtils.ParameterToString(param2))); - formParameterLocalVars.Add(new KeyValuePair("param", ClientUtils.ParameterToString(param))); - - formParameterLocalVars.Add(new KeyValuePair("param2", ClientUtils.ParameterToString(param2))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -5566,11 +5549,6 @@ public async Task TestJsonFormDataAsync(string par "application/x-www-form-urlencoded" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Get; DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/src/Org.OpenAPITools/Api/PetApi.cs b/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/src/Org.OpenAPITools/Api/PetApi.cs index 2d7e4dab0b84..c5de9cd55ad1 100644 --- a/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/src/Org.OpenAPITools/Api/PetApi.cs +++ b/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/src/Org.OpenAPITools/Api/PetApi.cs @@ -218,7 +218,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image @@ -231,7 +231,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <?> - Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -245,7 +245,7 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -258,7 +258,32 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <?> - Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <?> + Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); } /// @@ -417,6 +442,18 @@ public interface IUploadFileWithRequiredFileApiResponse : Org.OpenAPITools.Clien bool IsOk { get; } } + /// + /// The + /// + public interface IUploadFilesApiResponse : Org.OpenAPITools.Client.IApiResponse, IOk + { + /// + /// Returns true if the response is 200 Ok + /// + /// + bool IsOk { get; } + } + /// /// Represents a collection of functions to interact with the API endpoints /// @@ -601,6 +638,26 @@ internal void ExecuteOnErrorUploadFileWithRequiredFile(Exception exception) { OnErrorUploadFileWithRequiredFile?.Invoke(this, new ExceptionEventArgs(exception)); } + + /// + /// The event raised after the server response + /// + public event EventHandler? OnUploadFiles; + + /// + /// The event raised after an error querying the server + /// + public event EventHandler? OnErrorUploadFiles; + + internal void ExecuteOnUploadFiles(PetApi.UploadFilesApiResponse apiResponse) + { + OnUploadFiles?.Invoke(this, new ApiResponseEventArgs(apiResponse)); + } + + internal void ExecuteOnErrorUploadFiles(Exception exception) + { + OnErrorUploadFiles?.Invoke(this, new ExceptionEventArgs(exception)); + } } /// @@ -2332,17 +2389,16 @@ public async Task UpdatePetWithFormAsync(long pet : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - - List> formParameterLocalVars = new List>(); + List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (name.IsSet) - formParameterLocalVars.Add(new KeyValuePair("name", ClientUtils.ParameterToString(name.Value))); + if (name.IsSet) + formParameterLocalVars.Add(new KeyValuePair("name", ClientUtils.ParameterToString(name.Value))); if (status.IsSet) - formParameterLocalVars.Add(new KeyValuePair("status", ClientUtils.ParameterToString(status.Value))); + formParameterLocalVars.Add(new KeyValuePair("status", ClientUtils.ParameterToString(status.Value))); + + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2357,11 +2413,6 @@ public async Task UpdatePetWithFormAsync(long pet "application/x-www-form-urlencoded" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -2461,7 +2512,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); + partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); /// /// Validates the request parameters @@ -2469,7 +2520,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFile(Option additionalMetadata, Option file) + private void ValidateUploadFile(Option additionalMetadata, Option file) { if (additionalMetadata.IsSet && additionalMetadata.Value == null) throw new ArgumentNullException(nameof(additionalMetadata)); @@ -2485,7 +2536,7 @@ private void ValidateUploadFile(Option additionalMetadata, Option /// /// - private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) + private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLog = false; AfterUploadFile(ref suppressDefaultLog, apiResponseLocalVar, petId, additionalMetadata, file); @@ -2501,7 +2552,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); + partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); /// /// Logs exceptions that occur while retrieving the server response @@ -2512,7 +2563,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) + private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, additionalMetadata, file); @@ -2530,7 +2581,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// /// /// - partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); + partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); /// /// uploads an image @@ -2540,7 +2591,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2561,7 +2612,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2581,17 +2632,23 @@ public async Task UploadFileAsync(long petId, Option> formParameterLocalVars = new List>(); + List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (additionalMetadata.IsSet) - formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + if (additionalMetadata.IsSet) + formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); if (file.IsSet) - multipartContentLocalVar.Add(new StreamContent(file.Value)); + { + var streamContentLocalVar = new StreamContent(file.Value.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "file", file.Value.FileName ?? "file"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2606,11 +2663,6 @@ public async Task UploadFileAsync(long petId, Option additionalMetadata); + partial void FormatUploadFileWithRequiredFile(ref long petId, ref Org.OpenAPITools.Client.FileParameter requiredFile, ref Option additionalMetadata); /// /// Validates the request parameters @@ -2759,7 +2811,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, Option additionalMetadata) + private void ValidateUploadFileWithRequiredFile(Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { if (requiredFile == null) throw new ArgumentNullException(nameof(requiredFile)); @@ -2775,7 +2827,7 @@ private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, O /// /// /// - private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLog = false; AfterUploadFileWithRequiredFile(ref suppressDefaultLog, apiResponseLocalVar, petId, requiredFile, additionalMetadata); @@ -2791,7 +2843,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// Logs exceptions that occur while retrieving the server response @@ -2802,7 +2854,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFileWithRequiredFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, requiredFile, additionalMetadata); @@ -2820,7 +2872,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// /// /// - partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// uploads an image (required) @@ -2830,7 +2882,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2851,7 +2903,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2871,16 +2923,22 @@ public async Task UploadFileWithRequired : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/{petId}/uploadImageWithRequiredFile"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); + List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); multipartContentLocalVar.Add(new StreamContent(requiredFile)); + { + var streamContentLocalVar = new StreamContent(requiredFile.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile", requiredFile.FileName ?? "requiredFile"); + } if (additionalMetadata.IsSet) - formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2895,11 +2953,6 @@ public async Task UploadFileWithRequired "multipart/form-data" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - string[] acceptLocalVars = new string[] { "application/json", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" @@ -3040,5 +3093,283 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } + + partial void FormatUploadFiles(List files, ref long petId); + + /// + /// Validates the request parameters + /// + /// + /// + private void ValidateUploadFiles(List files) + { + if (files == null) + throw new ArgumentNullException(nameof(files)); + } + + /// + /// Processes the server response + /// + /// + /// + /// + private void AfterUploadFilesDefaultImplementation(IUploadFilesApiResponse apiResponseLocalVar, List files, long petId) + { + bool suppressDefaultLog = false; + AfterUploadFiles(ref suppressDefaultLog, apiResponseLocalVar, files, petId); + if (!suppressDefaultLog) + Logger.LogInformation("{0,-9} | {1} | {2}", (apiResponseLocalVar.DownloadedAt - apiResponseLocalVar.RequestedAt).TotalSeconds, apiResponseLocalVar.StatusCode, apiResponseLocalVar.Path); + } + + /// + /// Processes the server response + /// + /// + /// + /// + /// + partial void AfterUploadFiles(ref bool suppressDefaultLog, IUploadFilesApiResponse apiResponseLocalVar, List files, long petId); + + /// + /// Logs exceptions that occur while retrieving the server response + /// + /// + /// + /// + /// + /// + private void OnErrorUploadFilesDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId) + { + bool suppressDefaultLogLocalVar = false; + OnErrorUploadFiles(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, files, petId); + if (!suppressDefaultLogLocalVar) + Logger.LogError(exceptionLocalVar, "An error occurred while sending the request to the server."); + } + + /// + /// A partial method that gives developers a way to provide customized exception handling + /// + /// + /// + /// + /// + /// + /// + partial void OnErrorUploadFiles(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId); + + /// + /// uploads an images + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + try + { + return await UploadFilesAsync(files, petId, cancellationToken).ConfigureAwait(false); + } + catch (Exception) + { + return null; + } + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + UriBuilder uriBuilderLocalVar = new UriBuilder(); + + try + { + ValidateUploadFiles(files); + + FormatUploadFiles(files, ref petId); + + using (HttpRequestMessage httpRequestMessageLocalVar = new HttpRequestMessage()) + { + uriBuilderLocalVar.Host = HttpClient.BaseAddress!.Host; + uriBuilderLocalVar.Port = HttpClient.BaseAddress.Port; + uriBuilderLocalVar.Scheme = HttpClient.BaseAddress.Scheme; + uriBuilderLocalVar.Path = HttpClient.BaseAddress.AbsolutePath == "/" + ? "/pet/{petId}/uploadImages" + : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}/uploadImages"); + uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); + + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); + + httpRequestMessageLocalVar.Content = multipartContentLocalVar; + + List> formParameterLocalVars = new List>(); + + foreach (Org.OpenAPITools.Client.FileParameter fileParameterLocalVar in files) + { + var streamContentLocalVar = new StreamContent(fileParameterLocalVar.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "files", fileParameterLocalVar.FileName ?? "files"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); + + List tokenBaseLocalVars = new List(); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; + + OAuthToken oauthTokenLocalVar1 = (OAuthToken) await OauthTokenProvider.GetAsync(cancellation: cancellationToken).ConfigureAwait(false); + + tokenBaseLocalVars.Add(oauthTokenLocalVar1); + + oauthTokenLocalVar1.UseInHeader(httpRequestMessageLocalVar, ""); + + string[] contentTypes = new string[] { + "multipart/form-data" + }; + + string[] acceptLocalVars = new string[] { + "application/json" + }; + + IEnumerable acceptHeaderValuesLocalVar = ClientUtils.SelectHeaderAcceptArray(acceptLocalVars); + + foreach (var acceptLocalVar in acceptHeaderValuesLocalVar) + httpRequestMessageLocalVar.Headers.Accept.Add(acceptLocalVar); + + httpRequestMessageLocalVar.Method = HttpMethod.Post; + + DateTime requestedAtLocalVar = DateTime.UtcNow; + + using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false)) + { + ILogger apiResponseLoggerLocalVar = LoggerFactory.CreateLogger(); + UploadFilesApiResponse apiResponseLocalVar; + + switch ((int)httpResponseMessageLocalVar.StatusCode) { + default: { + string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + apiResponseLocalVar = new(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/pet/{petId}/uploadImages", requestedAtLocalVar, _jsonSerializerOptions); + + break; + } + } + + AfterUploadFilesDefaultImplementation(apiResponseLocalVar, files, petId); + + Events.ExecuteOnUploadFiles(apiResponseLocalVar); + + if (apiResponseLocalVar.StatusCode == (HttpStatusCode) 429) + foreach(TokenBase tokenBaseLocalVar in tokenBaseLocalVars) + tokenBaseLocalVar.BeginRateLimit(); + + return apiResponseLocalVar; + } + } + } + catch(Exception e) + { + OnErrorUploadFilesDefaultImplementation(e, "/pet/{petId}/uploadImages", uriBuilderLocalVar.Path, files, petId); + Events.ExecuteOnErrorUploadFiles(e); + throw; + } + } + + /// + /// The + /// + public partial class UploadFilesApiResponse : Org.OpenAPITools.Client.ApiResponse, IUploadFilesApiResponse + { + /// + /// The logger + /// + public ILogger Logger { get; } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, string rawContent, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, rawContent, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, System.IO.Stream contentStream, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, contentStream, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + partial void OnCreated(global::System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage); + + /// + /// Returns true if the response is 200 Ok + /// + /// + public bool IsOk => 200 == (int)StatusCode; + + /// + /// Deserializes the response if the response is 200 Ok + /// + /// + public Org.OpenAPITools.Model.ApiResponse? Ok() + { + // This logic may be modified with the AsModel.mustache template + return IsOk + ? System.Text.Json.JsonSerializer.Deserialize(RawContent, _jsonSerializerOptions) + : null; + } + + /// + /// Returns true if the response is 200 Ok and the deserialized response is not null + /// + /// + /// + public bool TryOk([NotNullWhen(true)]out Org.OpenAPITools.Model.ApiResponse? result) + { + result = null; + + try + { + result = Ok(); + } catch (Exception e) + { + OnDeserializationErrorDefaultImplementation(e, (HttpStatusCode)200); + } + + return result != null; + } + + private void OnDeserializationErrorDefaultImplementation(Exception exception, HttpStatusCode httpStatusCode) + { + bool suppressDefaultLog = false; + OnDeserializationError(ref suppressDefaultLog, exception, httpStatusCode); + if (!suppressDefaultLog) + Logger.LogError(exception, "An error occurred while deserializing the {code} response.", httpStatusCode); + } + + partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); + } } } diff --git a/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..77779fe7d75a --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,42 @@ +// +/* + * OpenAPI Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +#nullable enable + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string? FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string? fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net10/OneOf/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net10/OneOf/.openapi-generator/FILES index a36efde4422e..cfb76c7ed0ac 100644 --- a/samples/client/petstore/csharp/generichost/net10/OneOf/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net10/OneOf/.openapi-generator/FILES @@ -26,6 +26,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 diff --git a/samples/client/petstore/csharp/generichost/net10/OneOf/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net10/OneOf/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..e629f4afdaec --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net10/OneOf/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,42 @@ +// +/* + * fruity + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 0.0.1 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +#nullable enable + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string? FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string? fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net10/Petstore/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net10/Petstore/.openapi-generator/FILES index ab28c754b4b1..a3e02b328e0a 100644 --- a/samples/client/petstore/csharp/generichost/net10/Petstore/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net10/Petstore/.openapi-generator/FILES @@ -140,6 +140,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/HttpSigningConfiguration.cs src/Org.OpenAPITools/Client/HttpSigningToken.cs diff --git a/samples/client/petstore/csharp/generichost/net10/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net10/Petstore/api/openapi.yaml index d8106a5755fc..ca451f3fb832 100644 --- a/samples/client/petstore/csharp/generichost/net10/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net10/Petstore/api/openapi.yaml @@ -331,6 +331,40 @@ paths: summary: uploads an image tags: - pet + /pet/{petId}/uploadImages: + post: + description: "" + operationId: uploadFiles + parameters: + - description: ID of pet to update + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + multipart/form-data: + schema: + $ref: "#/components/schemas/uploadFiles_request" + required: true + responses: + "200": + content: + application/json: + schema: + $ref: "#/components/schemas/ApiResponse" + description: successful operation + security: + - petstore_auth: + - write:pets + - read:pets + summary: uploads an images + tags: + - pet /store/inventory: get: description: Returns a map of status codes to quantities @@ -2924,6 +2958,16 @@ components: format: binary type: string type: object + uploadFiles_request: + properties: + files: + items: + format: binary + type: string + type: array + required: + - files + type: object testEnumParameters_request: properties: enum_form_string_array: diff --git a/samples/client/petstore/csharp/generichost/net10/Petstore/docs/apis/PetApi.md b/samples/client/petstore/csharp/generichost/net10/Petstore/docs/apis/PetApi.md index 2826ea00f728..b42ee516b313 100644 --- a/samples/client/petstore/csharp/generichost/net10/Petstore/docs/apis/PetApi.md +++ b/samples/client/petstore/csharp/generichost/net10/Petstore/docs/apis/PetApi.md @@ -13,6 +13,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* | [**UpdatePetWithForm**](PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data | | [**UploadFile**](PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image | | [**UploadFileWithRequiredFile**](PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) | +| [**UploadFiles**](PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images | # **AddPet** @@ -341,3 +342,38 @@ uploads an image (required) [[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + +# **UploadFiles** +> ApiResponse UploadFiles (List files, long petId) + +uploads an images + + +### Parameters + +| Name | Type | Description | Notes | +|------|------|-------------|-------| +| **files** | **List<System.IO.Stream>** | | | +| **petId** | **long** | ID of pet to update | | + +### Return type + +[**ApiResponse**](ApiResponse.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: multipart/form-data + - **Accept**: application/json + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | + +[[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + diff --git a/samples/client/petstore/csharp/generichost/net10/Petstore/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs b/samples/client/petstore/csharp/generichost/net10/Petstore/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs index 66769b3aee6a..fed093fb206f 100644 --- a/samples/client/petstore/csharp/generichost/net10/Petstore/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net10/Petstore/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs @@ -196,7 +196,7 @@ public async Task TestEndpointParametersAsyncTest() string patternWithoutDelimiter = default; byte[] varByte = default; double varDouble = default; - Client.Option binary = default; + Client.Option binary = default; Client.Option callback = default; Client.Option date = default; Client.Option dateTime = default; diff --git a/samples/client/petstore/csharp/generichost/net10/Petstore/src/Org.OpenAPITools.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/net10/Petstore/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 215e88093797..e9b05337bb59 100644 --- a/samples/client/petstore/csharp/generichost/net10/Petstore/src/Org.OpenAPITools.Test/Api/PetApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net10/Petstore/src/Org.OpenAPITools.Test/Api/PetApiTests.cs @@ -137,7 +137,7 @@ public async Task UploadFileAsyncTest() { long petId = default; Client.Option additionalMetadata = default; - Client.Option file = default; + Client.Option file = default; var response = await _instance.UploadFileAsync(petId, additionalMetadata, file); var model = response.Ok(); Assert.IsType(model); @@ -150,11 +150,24 @@ public async Task UploadFileAsyncTest() public async Task UploadFileWithRequiredFileAsyncTest() { long petId = default; - System.IO.Stream requiredFile = default; + Org.OpenAPITools.Client.FileParameter requiredFile = default; Client.Option additionalMetadata = default; var response = await _instance.UploadFileWithRequiredFileAsync(petId, requiredFile, additionalMetadata); var model = response.Ok(); Assert.IsType(model); } + + /// + /// Test UploadFiles + /// + [Fact (Skip = "not implemented")] + public async Task UploadFilesAsyncTest() + { + List files = default; + long petId = default; + var response = await _instance.UploadFilesAsync(files, petId); + var model = response.Ok(); + Assert.IsType(model); + } } } diff --git a/samples/client/petstore/csharp/generichost/net10/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net10/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs index 3c26a27185e6..44d52e7e1090 100644 --- a/samples/client/petstore/csharp/generichost/net10/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs +++ b/samples/client/petstore/csharp/generichost/net10/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs @@ -764,27 +764,19 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net10/Petstore/src/Org.OpenAPITools/Api/FakeApi.cs b/samples/client/petstore/csharp/generichost/net10/Petstore/src/Org.OpenAPITools/Api/FakeApi.cs index 01aaf0ccbd85..482421f8c4ea 100644 --- a/samples/client/petstore/csharp/generichost/net10/Petstore/src/Org.OpenAPITools/Api/FakeApi.cs +++ b/samples/client/petstore/csharp/generichost/net10/Petstore/src/Org.OpenAPITools/Api/FakeApi.cs @@ -330,7 +330,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <> - Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -354,7 +354,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <> - Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// To test enum parameters @@ -4080,7 +4080,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); + partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); /// /// Validates the request parameters @@ -4092,7 +4092,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) + private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) { if (patternWithoutDelimiter == null) throw new ArgumentNullException(nameof(patternWithoutDelimiter)); @@ -4131,7 +4131,7 @@ private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte /// /// /// - private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLog = false; AfterTestEndpointParameters(ref suppressDefaultLog, apiResponseLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4158,7 +4158,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Logs exceptions that occur while retrieving the server response @@ -4180,7 +4180,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLogLocalVar = false; OnErrorTestEndpointParameters(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4209,7 +4209,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// /// /// - partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -4230,7 +4230,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -4262,7 +4262,7 @@ public async Task TestEndpointParametersOrDe /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -4281,14 +4281,8 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("number", ClientUtils.ParameterToString(number))); formParameterLocalVars.Add(new KeyValuePair("pattern_without_delimiter", ClientUtils.ParameterToString(patternWithoutDelimiter))); @@ -4298,7 +4292,7 @@ public async Task TestEndpointParametersAsyn formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.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."); if (callback.IsSet) formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); @@ -4327,6 +4321,9 @@ public async Task TestEndpointParametersAsyn if (varString.IsSet) formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4340,11 +4337,6 @@ public async Task TestEndpointParametersAsyn "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -4637,29 +4629,23 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (enumFormString.IsSet) + if (enumFormString.IsSet) formParameterLocalVars.Add(new KeyValuePair("enum_form_string", ClientUtils.ParameterToString(enumFormString.Value))); if (enumFormStringArray.IsSet) formParameterLocalVars.Add(new KeyValuePair("enum_form_string_array", ClientUtils.ParameterToString(enumFormStringArray.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Get; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -5546,29 +5532,21 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("param", ClientUtils.ParameterToString(param))); formParameterLocalVars.Add(new KeyValuePair("param2", ClientUtils.ParameterToString(param2))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Get; DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net10/Petstore/src/Org.OpenAPITools/Api/PetApi.cs b/samples/client/petstore/csharp/generichost/net10/Petstore/src/Org.OpenAPITools/Api/PetApi.cs index a1817e3df697..da4dfd225bc4 100644 --- a/samples/client/petstore/csharp/generichost/net10/Petstore/src/Org.OpenAPITools/Api/PetApi.cs +++ b/samples/client/petstore/csharp/generichost/net10/Petstore/src/Org.OpenAPITools/Api/PetApi.cs @@ -216,7 +216,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image @@ -229,7 +229,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -243,7 +243,7 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -256,7 +256,32 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); } /// @@ -415,6 +440,18 @@ public interface IUploadFileWithRequiredFileApiResponse : Org.OpenAPITools.Clien bool IsOk { get; } } + /// + /// The + /// + public interface IUploadFilesApiResponse : Org.OpenAPITools.Client.IApiResponse, IOk + { + /// + /// Returns true if the response is 200 Ok + /// + /// + bool IsOk { get; } + } + /// /// Represents a collection of functions to interact with the API endpoints /// @@ -599,6 +636,26 @@ internal void ExecuteOnErrorUploadFileWithRequiredFile(Exception exception) { OnErrorUploadFileWithRequiredFile?.Invoke(this, new ExceptionEventArgs(exception)); } + + /// + /// The event raised after the server response + /// + public event EventHandler OnUploadFiles; + + /// + /// The event raised after an error querying the server + /// + public event EventHandler OnErrorUploadFiles; + + internal void ExecuteOnUploadFiles(PetApi.UploadFilesApiResponse apiResponse) + { + OnUploadFiles?.Invoke(this, new ApiResponseEventArgs(apiResponse)); + } + + internal void ExecuteOnErrorUploadFiles(Exception exception) + { + OnErrorUploadFiles?.Invoke(this, new ExceptionEventArgs(exception)); + } } /// @@ -2330,18 +2387,17 @@ public async Task UpdatePetWithFormAsync(long pet : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (name.IsSet) + if (name.IsSet) formParameterLocalVars.Add(new KeyValuePair("name", ClientUtils.ParameterToString(name.Value))); if (status.IsSet) formParameterLocalVars.Add(new KeyValuePair("status", ClientUtils.ParameterToString(status.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2355,11 +2411,6 @@ public async Task UpdatePetWithFormAsync(long pet "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -2459,7 +2510,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); + partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); /// /// Validates the request parameters @@ -2467,7 +2518,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFile(Option additionalMetadata, Option file) + private void ValidateUploadFile(Option additionalMetadata, Option file) { if (additionalMetadata.IsSet && additionalMetadata.Value == null) throw new ArgumentNullException(nameof(additionalMetadata)); @@ -2483,7 +2534,7 @@ private void ValidateUploadFile(Option additionalMetadata, Option /// /// - private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) + private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLog = false; AfterUploadFile(ref suppressDefaultLog, apiResponseLocalVar, petId, additionalMetadata, file); @@ -2499,7 +2550,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); + partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); /// /// Logs exceptions that occur while retrieving the server response @@ -2510,7 +2561,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) + private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, additionalMetadata, file); @@ -2528,7 +2579,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// /// /// - partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); + partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); /// /// uploads an image @@ -2538,7 +2589,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2559,7 +2610,7 @@ public async Task UploadFileOrDefaultAsync(long petId, O /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2579,17 +2630,23 @@ public async Task UploadFileAsync(long petId, Option> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (additionalMetadata.IsSet) + if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); if (file.IsSet) - multipartContentLocalVar.Add(new StreamContent(file.Value)); + { + var streamContentLocalVar = new StreamContent(file.Value.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "file", file.Value.FileName ?? "file"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2604,11 +2661,6 @@ public async Task UploadFileAsync(long petId, Option additionalMetadata); + partial void FormatUploadFileWithRequiredFile(ref long petId, ref Org.OpenAPITools.Client.FileParameter requiredFile, ref Option additionalMetadata); /// /// Validates the request parameters @@ -2757,7 +2809,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, Option additionalMetadata) + private void ValidateUploadFileWithRequiredFile(Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { if (requiredFile == null) throw new ArgumentNullException(nameof(requiredFile)); @@ -2773,7 +2825,7 @@ private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, O /// /// /// - private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLog = false; AfterUploadFileWithRequiredFile(ref suppressDefaultLog, apiResponseLocalVar, petId, requiredFile, additionalMetadata); @@ -2789,7 +2841,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// Logs exceptions that occur while retrieving the server response @@ -2800,7 +2852,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFileWithRequiredFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, requiredFile, additionalMetadata); @@ -2818,7 +2870,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// /// /// - partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// uploads an image (required) @@ -2828,7 +2880,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2849,7 +2901,7 @@ public async Task UploadFileWithRequired /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2869,17 +2921,23 @@ public async Task UploadFileWithRequired : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/{petId}/uploadImageWithRequiredFile"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); multipartContentLocalVar.Add(new StreamContent(requiredFile)); + { + var streamContentLocalVar = new StreamContent(requiredFile.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile", requiredFile.FileName ?? "requiredFile"); + } if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2893,11 +2951,6 @@ public async Task UploadFileWithRequired "multipart/form-data" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - string[] acceptLocalVars = new string[] { "application/json", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" @@ -3038,5 +3091,283 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } + + partial void FormatUploadFiles(List files, ref long petId); + + /// + /// Validates the request parameters + /// + /// + /// + private void ValidateUploadFiles(List files) + { + if (files == null) + throw new ArgumentNullException(nameof(files)); + } + + /// + /// Processes the server response + /// + /// + /// + /// + private void AfterUploadFilesDefaultImplementation(IUploadFilesApiResponse apiResponseLocalVar, List files, long petId) + { + bool suppressDefaultLog = false; + AfterUploadFiles(ref suppressDefaultLog, apiResponseLocalVar, files, petId); + if (!suppressDefaultLog) + Logger.LogInformation("{0,-9} | {1} | {2}", (apiResponseLocalVar.DownloadedAt - apiResponseLocalVar.RequestedAt).TotalSeconds, apiResponseLocalVar.StatusCode, apiResponseLocalVar.Path); + } + + /// + /// Processes the server response + /// + /// + /// + /// + /// + partial void AfterUploadFiles(ref bool suppressDefaultLog, IUploadFilesApiResponse apiResponseLocalVar, List files, long petId); + + /// + /// Logs exceptions that occur while retrieving the server response + /// + /// + /// + /// + /// + /// + private void OnErrorUploadFilesDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId) + { + bool suppressDefaultLogLocalVar = false; + OnErrorUploadFiles(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, files, petId); + if (!suppressDefaultLogLocalVar) + Logger.LogError(exceptionLocalVar, "An error occurred while sending the request to the server."); + } + + /// + /// A partial method that gives developers a way to provide customized exception handling + /// + /// + /// + /// + /// + /// + /// + partial void OnErrorUploadFiles(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId); + + /// + /// uploads an images + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + try + { + return await UploadFilesAsync(files, petId, cancellationToken).ConfigureAwait(false); + } + catch (Exception) + { + return null; + } + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + UriBuilder uriBuilderLocalVar = new UriBuilder(); + + try + { + ValidateUploadFiles(files); + + FormatUploadFiles(files, ref petId); + + using (HttpRequestMessage httpRequestMessageLocalVar = new HttpRequestMessage()) + { + uriBuilderLocalVar.Host = HttpClient.BaseAddress.Host; + uriBuilderLocalVar.Port = HttpClient.BaseAddress.Port; + uriBuilderLocalVar.Scheme = HttpClient.BaseAddress.Scheme; + uriBuilderLocalVar.Path = HttpClient.BaseAddress.AbsolutePath == "/" + ? "/pet/{petId}/uploadImages" + : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}/uploadImages"); + uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); + + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); + + httpRequestMessageLocalVar.Content = multipartContentLocalVar; + + List> formParameterLocalVars = new List>(); + + foreach (Org.OpenAPITools.Client.FileParameter fileParameterLocalVar in files) + { + var streamContentLocalVar = new StreamContent(fileParameterLocalVar.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "files", fileParameterLocalVar.FileName ?? "files"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); + + List tokenBaseLocalVars = new List(); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; + + OAuthToken oauthTokenLocalVar1 = (OAuthToken) await OauthTokenProvider.GetAsync(cancellation: cancellationToken).ConfigureAwait(false); + + tokenBaseLocalVars.Add(oauthTokenLocalVar1); + + oauthTokenLocalVar1.UseInHeader(httpRequestMessageLocalVar, ""); + + string[] contentTypes = new string[] { + "multipart/form-data" + }; + + string[] acceptLocalVars = new string[] { + "application/json" + }; + + IEnumerable acceptHeaderValuesLocalVar = ClientUtils.SelectHeaderAcceptArray(acceptLocalVars); + + foreach (var acceptLocalVar in acceptHeaderValuesLocalVar) + httpRequestMessageLocalVar.Headers.Accept.Add(acceptLocalVar); + + httpRequestMessageLocalVar.Method = HttpMethod.Post; + + DateTime requestedAtLocalVar = DateTime.UtcNow; + + using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false)) + { + ILogger apiResponseLoggerLocalVar = LoggerFactory.CreateLogger(); + UploadFilesApiResponse apiResponseLocalVar; + + switch ((int)httpResponseMessageLocalVar.StatusCode) { + default: { + string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + apiResponseLocalVar = new(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/pet/{petId}/uploadImages", requestedAtLocalVar, _jsonSerializerOptions); + + break; + } + } + + AfterUploadFilesDefaultImplementation(apiResponseLocalVar, files, petId); + + Events.ExecuteOnUploadFiles(apiResponseLocalVar); + + if (apiResponseLocalVar.StatusCode == (HttpStatusCode) 429) + foreach(TokenBase tokenBaseLocalVar in tokenBaseLocalVars) + tokenBaseLocalVar.BeginRateLimit(); + + return apiResponseLocalVar; + } + } + } + catch(Exception e) + { + OnErrorUploadFilesDefaultImplementation(e, "/pet/{petId}/uploadImages", uriBuilderLocalVar.Path, files, petId); + Events.ExecuteOnErrorUploadFiles(e); + throw; + } + } + + /// + /// The + /// + public partial class UploadFilesApiResponse : Org.OpenAPITools.Client.ApiResponse, IUploadFilesApiResponse + { + /// + /// The logger + /// + public ILogger Logger { get; } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, string rawContent, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, rawContent, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, System.IO.Stream contentStream, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, contentStream, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + partial void OnCreated(global::System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage); + + /// + /// Returns true if the response is 200 Ok + /// + /// + public bool IsOk => 200 == (int)StatusCode; + + /// + /// Deserializes the response if the response is 200 Ok + /// + /// + public Org.OpenAPITools.Model.ApiResponse Ok() + { + // This logic may be modified with the AsModel.mustache template + return IsOk + ? System.Text.Json.JsonSerializer.Deserialize(RawContent, _jsonSerializerOptions) + : null; + } + + /// + /// Returns true if the response is 200 Ok and the deserialized response is not null + /// + /// + /// + public bool TryOk([NotNullWhen(true)]out Org.OpenAPITools.Model.ApiResponse result) + { + result = null; + + try + { + result = Ok(); + } catch (Exception e) + { + OnDeserializationErrorDefaultImplementation(e, (HttpStatusCode)200); + } + + return result != null; + } + + private void OnDeserializationErrorDefaultImplementation(Exception exception, HttpStatusCode httpStatusCode) + { + bool suppressDefaultLog = false; + OnDeserializationError(ref suppressDefaultLog, exception, httpStatusCode); + if (!suppressDefaultLog) + Logger.LogError(exception, "An error occurred while deserializing the {code} response.", httpStatusCode); + } + + partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); + } } } diff --git a/samples/client/petstore/csharp/generichost/net10/Petstore/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net10/Petstore/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..6150dbcf4774 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net10/Petstore/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,40 @@ +// +/* + * OpenAPI Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net10/SourceGeneration/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net10/SourceGeneration/.openapi-generator/FILES index ab28c754b4b1..a3e02b328e0a 100644 --- a/samples/client/petstore/csharp/generichost/net10/SourceGeneration/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net10/SourceGeneration/.openapi-generator/FILES @@ -140,6 +140,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/HttpSigningConfiguration.cs src/Org.OpenAPITools/Client/HttpSigningToken.cs diff --git a/samples/client/petstore/csharp/generichost/net10/SourceGeneration/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net10/SourceGeneration/api/openapi.yaml index d8106a5755fc..ca451f3fb832 100644 --- a/samples/client/petstore/csharp/generichost/net10/SourceGeneration/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net10/SourceGeneration/api/openapi.yaml @@ -331,6 +331,40 @@ paths: summary: uploads an image tags: - pet + /pet/{petId}/uploadImages: + post: + description: "" + operationId: uploadFiles + parameters: + - description: ID of pet to update + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + multipart/form-data: + schema: + $ref: "#/components/schemas/uploadFiles_request" + required: true + responses: + "200": + content: + application/json: + schema: + $ref: "#/components/schemas/ApiResponse" + description: successful operation + security: + - petstore_auth: + - write:pets + - read:pets + summary: uploads an images + tags: + - pet /store/inventory: get: description: Returns a map of status codes to quantities @@ -2924,6 +2958,16 @@ components: format: binary type: string type: object + uploadFiles_request: + properties: + files: + items: + format: binary + type: string + type: array + required: + - files + type: object testEnumParameters_request: properties: enum_form_string_array: diff --git a/samples/client/petstore/csharp/generichost/net10/SourceGeneration/docs/apis/PetApi.md b/samples/client/petstore/csharp/generichost/net10/SourceGeneration/docs/apis/PetApi.md index 2826ea00f728..b42ee516b313 100644 --- a/samples/client/petstore/csharp/generichost/net10/SourceGeneration/docs/apis/PetApi.md +++ b/samples/client/petstore/csharp/generichost/net10/SourceGeneration/docs/apis/PetApi.md @@ -13,6 +13,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* | [**UpdatePetWithForm**](PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data | | [**UploadFile**](PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image | | [**UploadFileWithRequiredFile**](PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) | +| [**UploadFiles**](PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images | # **AddPet** @@ -341,3 +342,38 @@ uploads an image (required) [[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + +# **UploadFiles** +> ApiResponse UploadFiles (List files, long petId) + +uploads an images + + +### Parameters + +| Name | Type | Description | Notes | +|------|------|-------------|-------| +| **files** | **List<System.IO.Stream>** | | | +| **petId** | **long** | ID of pet to update | | + +### Return type + +[**ApiResponse**](ApiResponse.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: multipart/form-data + - **Accept**: application/json + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | + +[[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + diff --git a/samples/client/petstore/csharp/generichost/net10/SourceGeneration/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs b/samples/client/petstore/csharp/generichost/net10/SourceGeneration/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs index 406dbc964a6d..d207bb93dc69 100644 --- a/samples/client/petstore/csharp/generichost/net10/SourceGeneration/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net10/SourceGeneration/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs @@ -196,7 +196,7 @@ public async Task TestEndpointParametersAsyncTest() string patternWithoutDelimiter = default!; byte[] varByte = default!; double varDouble = default!; - Client.Option binary = default!; + Client.Option binary = default!; Client.Option callback = default!; Client.Option date = default!; Client.Option dateTime = default!; diff --git a/samples/client/petstore/csharp/generichost/net10/SourceGeneration/src/Org.OpenAPITools.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/net10/SourceGeneration/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 49e7b21b53c2..6bb1f953987c 100644 --- a/samples/client/petstore/csharp/generichost/net10/SourceGeneration/src/Org.OpenAPITools.Test/Api/PetApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net10/SourceGeneration/src/Org.OpenAPITools.Test/Api/PetApiTests.cs @@ -137,7 +137,7 @@ public async Task UploadFileAsyncTest() { long petId = default!; Client.Option additionalMetadata = default!; - Client.Option file = default!; + Client.Option file = default!; var response = await _instance.UploadFileAsync(petId, additionalMetadata, file); var model = response.Ok(); Assert.IsType(model); @@ -150,11 +150,24 @@ public async Task UploadFileAsyncTest() public async Task UploadFileWithRequiredFileAsyncTest() { long petId = default!; - System.IO.Stream requiredFile = default!; + Org.OpenAPITools.Client.FileParameter requiredFile = default!; Client.Option additionalMetadata = default!; var response = await _instance.UploadFileWithRequiredFileAsync(petId, requiredFile, additionalMetadata); var model = response.Ok(); Assert.IsType(model); } + + /// + /// Test UploadFiles + /// + [Fact (Skip = "not implemented")] + public async Task UploadFilesAsyncTest() + { + List files = default!; + long petId = default!; + var response = await _instance.UploadFilesAsync(files, petId); + var model = response.Ok(); + Assert.IsType(model); + } } } diff --git a/samples/client/petstore/csharp/generichost/net10/SourceGeneration/src/Org.OpenAPITools/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net10/SourceGeneration/src/Org.OpenAPITools/Api/DefaultApi.cs index 2391c7e1ee03..46b798fe32ca 100644 --- a/samples/client/petstore/csharp/generichost/net10/SourceGeneration/src/Org.OpenAPITools/Api/DefaultApi.cs +++ b/samples/client/petstore/csharp/generichost/net10/SourceGeneration/src/Org.OpenAPITools/Api/DefaultApi.cs @@ -766,15 +766,12 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + List> formParameterLocalVars = new List>(); - httpRequestMessageLocalVar.Content = multipartContentLocalVar; + formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); - List> formParameterLocalVars = new List>(); - - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -782,11 +779,6 @@ public async Task GetCountryAsync(string country, System "application/x-www-form-urlencoded" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net10/SourceGeneration/src/Org.OpenAPITools/Api/FakeApi.cs b/samples/client/petstore/csharp/generichost/net10/SourceGeneration/src/Org.OpenAPITools/Api/FakeApi.cs index 262a94ef2520..54a1c8c85360 100644 --- a/samples/client/petstore/csharp/generichost/net10/SourceGeneration/src/Org.OpenAPITools/Api/FakeApi.cs +++ b/samples/client/petstore/csharp/generichost/net10/SourceGeneration/src/Org.OpenAPITools/Api/FakeApi.cs @@ -332,7 +332,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <> - Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -356,7 +356,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <?> - Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// To test enum parameters @@ -4082,7 +4082,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); + partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); /// /// Validates the request parameters @@ -4094,7 +4094,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) + private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) { if (patternWithoutDelimiter == null) throw new ArgumentNullException(nameof(patternWithoutDelimiter)); @@ -4133,7 +4133,7 @@ private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte /// /// /// - private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLog = false; AfterTestEndpointParameters(ref suppressDefaultLog, apiResponseLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4160,7 +4160,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Logs exceptions that occur while retrieving the server response @@ -4182,7 +4182,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLogLocalVar = false; OnErrorTestEndpointParameters(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4211,7 +4211,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// /// /// - partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -4232,7 +4232,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -4264,7 +4264,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -4283,51 +4283,48 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + List> formParameterLocalVars = new List>(); - httpRequestMessageLocalVar.Content = multipartContentLocalVar; + formParameterLocalVars.Add(new KeyValuePair("number", ClientUtils.ParameterToString(number))); - List> formParameterLocalVars = new List>(); + formParameterLocalVars.Add(new KeyValuePair("pattern_without_delimiter", ClientUtils.ParameterToString(patternWithoutDelimiter))); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + formParameterLocalVars.Add(new KeyValuePair("byte", ClientUtils.ParameterToString(varByte))); - formParameterLocalVars.Add(new KeyValuePair("number", ClientUtils.ParameterToString(number))); - - formParameterLocalVars.Add(new KeyValuePair("pattern_without_delimiter", ClientUtils.ParameterToString(patternWithoutDelimiter))); - - formParameterLocalVars.Add(new KeyValuePair("byte", ClientUtils.ParameterToString(varByte))); - - formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); + formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.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."); if (callback.IsSet) - formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); + formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); if (date.IsSet) - formParameterLocalVars.Add(new KeyValuePair("date", ClientUtils.ParameterToString(date.Value))); + formParameterLocalVars.Add(new KeyValuePair("date", ClientUtils.ParameterToString(date.Value))); if (dateTime.IsSet) - formParameterLocalVars.Add(new KeyValuePair("dateTime", ClientUtils.ParameterToString(dateTime.Value))); + formParameterLocalVars.Add(new KeyValuePair("dateTime", ClientUtils.ParameterToString(dateTime.Value))); if (int32.IsSet) - formParameterLocalVars.Add(new KeyValuePair("int32", ClientUtils.ParameterToString(int32.Value))); + formParameterLocalVars.Add(new KeyValuePair("int32", ClientUtils.ParameterToString(int32.Value))); if (int64.IsSet) - formParameterLocalVars.Add(new KeyValuePair("int64", ClientUtils.ParameterToString(int64.Value))); + formParameterLocalVars.Add(new KeyValuePair("int64", ClientUtils.ParameterToString(int64.Value))); if (integer.IsSet) - formParameterLocalVars.Add(new KeyValuePair("integer", ClientUtils.ParameterToString(integer.Value))); + formParameterLocalVars.Add(new KeyValuePair("integer", ClientUtils.ParameterToString(integer.Value))); if (password.IsSet) - formParameterLocalVars.Add(new KeyValuePair("password", ClientUtils.ParameterToString(password.Value))); + formParameterLocalVars.Add(new KeyValuePair("password", ClientUtils.ParameterToString(password.Value))); if (varFloat.IsSet) - formParameterLocalVars.Add(new KeyValuePair("float", ClientUtils.ParameterToString(varFloat.Value))); + formParameterLocalVars.Add(new KeyValuePair("float", ClientUtils.ParameterToString(varFloat.Value))); if (varString.IsSet) - formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4342,11 +4339,6 @@ public async Task TestEndpointParametersAsyn "application/x-www-form-urlencoded" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -4639,17 +4631,16 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); + List> formParameterLocalVars = new List>(); - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - - List> formParameterLocalVars = new List>(); - - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (enumFormString.IsSet) - formParameterLocalVars.Add(new KeyValuePair("enum_form_string", ClientUtils.ParameterToString(enumFormString.Value))); + if (enumFormString.IsSet) + formParameterLocalVars.Add(new KeyValuePair("enum_form_string", ClientUtils.ParameterToString(enumFormString.Value))); if (enumFormStringArray.IsSet) - formParameterLocalVars.Add(new KeyValuePair("enum_form_string_array", ClientUtils.ParameterToString(enumFormStringArray.Value))); + formParameterLocalVars.Add(new KeyValuePair("enum_form_string_array", ClientUtils.ParameterToString(enumFormStringArray.Value))); + + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4657,11 +4648,6 @@ public async Task TestEnumParametersAsync(Option "application/x-www-form-urlencoded" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Get; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -5548,17 +5534,14 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; + List> formParameterLocalVars = new List>(); - List> formParameterLocalVars = new List>(); + formParameterLocalVars.Add(new KeyValuePair("param", ClientUtils.ParameterToString(param))); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + formParameterLocalVars.Add(new KeyValuePair("param2", ClientUtils.ParameterToString(param2))); - formParameterLocalVars.Add(new KeyValuePair("param", ClientUtils.ParameterToString(param))); - - formParameterLocalVars.Add(new KeyValuePair("param2", ClientUtils.ParameterToString(param2))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -5566,11 +5549,6 @@ public async Task TestJsonFormDataAsync(string par "application/x-www-form-urlencoded" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Get; DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net10/SourceGeneration/src/Org.OpenAPITools/Api/PetApi.cs b/samples/client/petstore/csharp/generichost/net10/SourceGeneration/src/Org.OpenAPITools/Api/PetApi.cs index 2d7e4dab0b84..c5de9cd55ad1 100644 --- a/samples/client/petstore/csharp/generichost/net10/SourceGeneration/src/Org.OpenAPITools/Api/PetApi.cs +++ b/samples/client/petstore/csharp/generichost/net10/SourceGeneration/src/Org.OpenAPITools/Api/PetApi.cs @@ -218,7 +218,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image @@ -231,7 +231,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <?> - Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -245,7 +245,7 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -258,7 +258,32 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <?> - Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <?> + Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); } /// @@ -417,6 +442,18 @@ public interface IUploadFileWithRequiredFileApiResponse : Org.OpenAPITools.Clien bool IsOk { get; } } + /// + /// The + /// + public interface IUploadFilesApiResponse : Org.OpenAPITools.Client.IApiResponse, IOk + { + /// + /// Returns true if the response is 200 Ok + /// + /// + bool IsOk { get; } + } + /// /// Represents a collection of functions to interact with the API endpoints /// @@ -601,6 +638,26 @@ internal void ExecuteOnErrorUploadFileWithRequiredFile(Exception exception) { OnErrorUploadFileWithRequiredFile?.Invoke(this, new ExceptionEventArgs(exception)); } + + /// + /// The event raised after the server response + /// + public event EventHandler? OnUploadFiles; + + /// + /// The event raised after an error querying the server + /// + public event EventHandler? OnErrorUploadFiles; + + internal void ExecuteOnUploadFiles(PetApi.UploadFilesApiResponse apiResponse) + { + OnUploadFiles?.Invoke(this, new ApiResponseEventArgs(apiResponse)); + } + + internal void ExecuteOnErrorUploadFiles(Exception exception) + { + OnErrorUploadFiles?.Invoke(this, new ExceptionEventArgs(exception)); + } } /// @@ -2332,17 +2389,16 @@ public async Task UpdatePetWithFormAsync(long pet : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - - List> formParameterLocalVars = new List>(); + List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (name.IsSet) - formParameterLocalVars.Add(new KeyValuePair("name", ClientUtils.ParameterToString(name.Value))); + if (name.IsSet) + formParameterLocalVars.Add(new KeyValuePair("name", ClientUtils.ParameterToString(name.Value))); if (status.IsSet) - formParameterLocalVars.Add(new KeyValuePair("status", ClientUtils.ParameterToString(status.Value))); + formParameterLocalVars.Add(new KeyValuePair("status", ClientUtils.ParameterToString(status.Value))); + + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2357,11 +2413,6 @@ public async Task UpdatePetWithFormAsync(long pet "application/x-www-form-urlencoded" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -2461,7 +2512,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); + partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); /// /// Validates the request parameters @@ -2469,7 +2520,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFile(Option additionalMetadata, Option file) + private void ValidateUploadFile(Option additionalMetadata, Option file) { if (additionalMetadata.IsSet && additionalMetadata.Value == null) throw new ArgumentNullException(nameof(additionalMetadata)); @@ -2485,7 +2536,7 @@ private void ValidateUploadFile(Option additionalMetadata, Option /// /// - private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) + private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLog = false; AfterUploadFile(ref suppressDefaultLog, apiResponseLocalVar, petId, additionalMetadata, file); @@ -2501,7 +2552,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); + partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); /// /// Logs exceptions that occur while retrieving the server response @@ -2512,7 +2563,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) + private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, additionalMetadata, file); @@ -2530,7 +2581,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// /// /// - partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); + partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); /// /// uploads an image @@ -2540,7 +2591,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2561,7 +2612,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2581,17 +2632,23 @@ public async Task UploadFileAsync(long petId, Option> formParameterLocalVars = new List>(); + List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (additionalMetadata.IsSet) - formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + if (additionalMetadata.IsSet) + formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); if (file.IsSet) - multipartContentLocalVar.Add(new StreamContent(file.Value)); + { + var streamContentLocalVar = new StreamContent(file.Value.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "file", file.Value.FileName ?? "file"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2606,11 +2663,6 @@ public async Task UploadFileAsync(long petId, Option additionalMetadata); + partial void FormatUploadFileWithRequiredFile(ref long petId, ref Org.OpenAPITools.Client.FileParameter requiredFile, ref Option additionalMetadata); /// /// Validates the request parameters @@ -2759,7 +2811,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, Option additionalMetadata) + private void ValidateUploadFileWithRequiredFile(Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { if (requiredFile == null) throw new ArgumentNullException(nameof(requiredFile)); @@ -2775,7 +2827,7 @@ private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, O /// /// /// - private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLog = false; AfterUploadFileWithRequiredFile(ref suppressDefaultLog, apiResponseLocalVar, petId, requiredFile, additionalMetadata); @@ -2791,7 +2843,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// Logs exceptions that occur while retrieving the server response @@ -2802,7 +2854,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFileWithRequiredFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, requiredFile, additionalMetadata); @@ -2820,7 +2872,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// /// /// - partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// uploads an image (required) @@ -2830,7 +2882,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2851,7 +2903,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2871,16 +2923,22 @@ public async Task UploadFileWithRequired : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/{petId}/uploadImageWithRequiredFile"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); + List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); multipartContentLocalVar.Add(new StreamContent(requiredFile)); + { + var streamContentLocalVar = new StreamContent(requiredFile.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile", requiredFile.FileName ?? "requiredFile"); + } if (additionalMetadata.IsSet) - formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2895,11 +2953,6 @@ public async Task UploadFileWithRequired "multipart/form-data" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - string[] acceptLocalVars = new string[] { "application/json", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" @@ -3040,5 +3093,283 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } + + partial void FormatUploadFiles(List files, ref long petId); + + /// + /// Validates the request parameters + /// + /// + /// + private void ValidateUploadFiles(List files) + { + if (files == null) + throw new ArgumentNullException(nameof(files)); + } + + /// + /// Processes the server response + /// + /// + /// + /// + private void AfterUploadFilesDefaultImplementation(IUploadFilesApiResponse apiResponseLocalVar, List files, long petId) + { + bool suppressDefaultLog = false; + AfterUploadFiles(ref suppressDefaultLog, apiResponseLocalVar, files, petId); + if (!suppressDefaultLog) + Logger.LogInformation("{0,-9} | {1} | {2}", (apiResponseLocalVar.DownloadedAt - apiResponseLocalVar.RequestedAt).TotalSeconds, apiResponseLocalVar.StatusCode, apiResponseLocalVar.Path); + } + + /// + /// Processes the server response + /// + /// + /// + /// + /// + partial void AfterUploadFiles(ref bool suppressDefaultLog, IUploadFilesApiResponse apiResponseLocalVar, List files, long petId); + + /// + /// Logs exceptions that occur while retrieving the server response + /// + /// + /// + /// + /// + /// + private void OnErrorUploadFilesDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId) + { + bool suppressDefaultLogLocalVar = false; + OnErrorUploadFiles(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, files, petId); + if (!suppressDefaultLogLocalVar) + Logger.LogError(exceptionLocalVar, "An error occurred while sending the request to the server."); + } + + /// + /// A partial method that gives developers a way to provide customized exception handling + /// + /// + /// + /// + /// + /// + /// + partial void OnErrorUploadFiles(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId); + + /// + /// uploads an images + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + try + { + return await UploadFilesAsync(files, petId, cancellationToken).ConfigureAwait(false); + } + catch (Exception) + { + return null; + } + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + UriBuilder uriBuilderLocalVar = new UriBuilder(); + + try + { + ValidateUploadFiles(files); + + FormatUploadFiles(files, ref petId); + + using (HttpRequestMessage httpRequestMessageLocalVar = new HttpRequestMessage()) + { + uriBuilderLocalVar.Host = HttpClient.BaseAddress!.Host; + uriBuilderLocalVar.Port = HttpClient.BaseAddress.Port; + uriBuilderLocalVar.Scheme = HttpClient.BaseAddress.Scheme; + uriBuilderLocalVar.Path = HttpClient.BaseAddress.AbsolutePath == "/" + ? "/pet/{petId}/uploadImages" + : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}/uploadImages"); + uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); + + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); + + httpRequestMessageLocalVar.Content = multipartContentLocalVar; + + List> formParameterLocalVars = new List>(); + + foreach (Org.OpenAPITools.Client.FileParameter fileParameterLocalVar in files) + { + var streamContentLocalVar = new StreamContent(fileParameterLocalVar.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "files", fileParameterLocalVar.FileName ?? "files"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); + + List tokenBaseLocalVars = new List(); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; + + OAuthToken oauthTokenLocalVar1 = (OAuthToken) await OauthTokenProvider.GetAsync(cancellation: cancellationToken).ConfigureAwait(false); + + tokenBaseLocalVars.Add(oauthTokenLocalVar1); + + oauthTokenLocalVar1.UseInHeader(httpRequestMessageLocalVar, ""); + + string[] contentTypes = new string[] { + "multipart/form-data" + }; + + string[] acceptLocalVars = new string[] { + "application/json" + }; + + IEnumerable acceptHeaderValuesLocalVar = ClientUtils.SelectHeaderAcceptArray(acceptLocalVars); + + foreach (var acceptLocalVar in acceptHeaderValuesLocalVar) + httpRequestMessageLocalVar.Headers.Accept.Add(acceptLocalVar); + + httpRequestMessageLocalVar.Method = HttpMethod.Post; + + DateTime requestedAtLocalVar = DateTime.UtcNow; + + using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false)) + { + ILogger apiResponseLoggerLocalVar = LoggerFactory.CreateLogger(); + UploadFilesApiResponse apiResponseLocalVar; + + switch ((int)httpResponseMessageLocalVar.StatusCode) { + default: { + string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + apiResponseLocalVar = new(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/pet/{petId}/uploadImages", requestedAtLocalVar, _jsonSerializerOptions); + + break; + } + } + + AfterUploadFilesDefaultImplementation(apiResponseLocalVar, files, petId); + + Events.ExecuteOnUploadFiles(apiResponseLocalVar); + + if (apiResponseLocalVar.StatusCode == (HttpStatusCode) 429) + foreach(TokenBase tokenBaseLocalVar in tokenBaseLocalVars) + tokenBaseLocalVar.BeginRateLimit(); + + return apiResponseLocalVar; + } + } + } + catch(Exception e) + { + OnErrorUploadFilesDefaultImplementation(e, "/pet/{petId}/uploadImages", uriBuilderLocalVar.Path, files, petId); + Events.ExecuteOnErrorUploadFiles(e); + throw; + } + } + + /// + /// The + /// + public partial class UploadFilesApiResponse : Org.OpenAPITools.Client.ApiResponse, IUploadFilesApiResponse + { + /// + /// The logger + /// + public ILogger Logger { get; } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, string rawContent, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, rawContent, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, System.IO.Stream contentStream, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, contentStream, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + partial void OnCreated(global::System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage); + + /// + /// Returns true if the response is 200 Ok + /// + /// + public bool IsOk => 200 == (int)StatusCode; + + /// + /// Deserializes the response if the response is 200 Ok + /// + /// + public Org.OpenAPITools.Model.ApiResponse? Ok() + { + // This logic may be modified with the AsModel.mustache template + return IsOk + ? System.Text.Json.JsonSerializer.Deserialize(RawContent, _jsonSerializerOptions) + : null; + } + + /// + /// Returns true if the response is 200 Ok and the deserialized response is not null + /// + /// + /// + public bool TryOk([NotNullWhen(true)]out Org.OpenAPITools.Model.ApiResponse? result) + { + result = null; + + try + { + result = Ok(); + } catch (Exception e) + { + OnDeserializationErrorDefaultImplementation(e, (HttpStatusCode)200); + } + + return result != null; + } + + private void OnDeserializationErrorDefaultImplementation(Exception exception, HttpStatusCode httpStatusCode) + { + bool suppressDefaultLog = false; + OnDeserializationError(ref suppressDefaultLog, exception, httpStatusCode); + if (!suppressDefaultLog) + Logger.LogError(exception, "An error occurred while deserializing the {code} response.", httpStatusCode); + } + + partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); + } } } diff --git a/samples/client/petstore/csharp/generichost/net10/SourceGeneration/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net10/SourceGeneration/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..77779fe7d75a --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net10/SourceGeneration/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,42 @@ +// +/* + * OpenAPI Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +#nullable enable + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string? FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string? fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net10/UseDateTimeForDate/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net10/UseDateTimeForDate/.openapi-generator/FILES index 5abbcf46f35c..e28da391730f 100644 --- a/samples/client/petstore/csharp/generichost/net10/UseDateTimeForDate/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net10/UseDateTimeForDate/.openapi-generator/FILES @@ -21,6 +21,7 @@ src/Org.OpenAPITools/Client/CookieContainer.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 diff --git a/samples/client/petstore/csharp/generichost/net10/UseDateTimeForDate/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net10/UseDateTimeForDate/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..11da1d925144 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net10/UseDateTimeForDate/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,42 @@ +// +/* + * OpenAPI Dates + * + * Thic spec contains endpoints with dates in different formats + * + * The version of the OpenAPI document: 1.0.0 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +#nullable enable + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string? FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string? fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.7/AllOf/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net4.7/AllOf/.openapi-generator/FILES index 47b2b9b5c4f4..1c80f1449c66 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/AllOf/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net4.7/AllOf/.openapi-generator/FILES @@ -23,6 +23,7 @@ src/Org.OpenAPITools/Client/CookieContainer.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 diff --git a/samples/client/petstore/csharp/generichost/net4.7/AllOf/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net4.7/AllOf/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..936f8415fda6 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.7/AllOf/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,40 @@ +// +/* + * Example + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.7/AnyOf/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net4.7/AnyOf/.openapi-generator/FILES index 59cc1ea25a08..5e82fcb80ae5 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/AnyOf/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net4.7/AnyOf/.openapi-generator/FILES @@ -23,6 +23,7 @@ src/Org.OpenAPITools/Client/CookieContainer.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 diff --git a/samples/client/petstore/csharp/generichost/net4.7/AnyOf/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net4.7/AnyOf/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..5c8e0767f76a --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.7/AnyOf/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,40 @@ +// +/* + * fruity + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 0.0.1 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.7/AnyOfNoCompare/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net4.7/AnyOfNoCompare/.openapi-generator/FILES index 59cc1ea25a08..5e82fcb80ae5 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/AnyOfNoCompare/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net4.7/AnyOfNoCompare/.openapi-generator/FILES @@ -23,6 +23,7 @@ src/Org.OpenAPITools/Client/CookieContainer.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 diff --git a/samples/client/petstore/csharp/generichost/net4.7/AnyOfNoCompare/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net4.7/AnyOfNoCompare/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..5c8e0767f76a --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.7/AnyOfNoCompare/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,40 @@ +// +/* + * fruity + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 0.0.1 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.7/FormModels/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net4.7/FormModels/.openapi-generator/FILES index 3c592107ec19..4d9b3d8248d3 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/FormModels/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/.openapi-generator/FILES @@ -163,6 +163,7 @@ src/Org.OpenAPITools/Client/CookieContainer.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/HttpSigningConfiguration.cs src/Org.OpenAPITools/Client/HttpSigningToken.cs diff --git a/samples/client/petstore/csharp/generichost/net4.7/FormModels/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net4.7/FormModels/api/openapi.yaml index a9ab8dd51c13..7017affc0b9c 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/FormModels/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/api/openapi.yaml @@ -326,6 +326,40 @@ paths: summary: uploads an image tags: - pet + /pet/{petId}/uploadImages: + post: + description: "" + operationId: uploadFiles + parameters: + - description: ID of pet to update + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + multipart/form-data: + schema: + $ref: "#/components/schemas/uploadFiles_request" + required: true + responses: + "200": + content: + application/json: + schema: + $ref: "#/components/schemas/ApiResponse" + description: successful operation + security: + - petstore_auth: + - write:pets + - read:pets + summary: uploads an images + tags: + - pet /store/inventory: get: description: Returns a map of status codes to quantities @@ -2748,6 +2782,16 @@ components: format: binary type: string type: object + uploadFiles_request: + properties: + files: + items: + format: binary + type: string + type: array + required: + - files + type: object testEnumParameters_request_enum_form_string_array_inner: default: $ enum: diff --git a/samples/client/petstore/csharp/generichost/net4.7/FormModels/docs/apis/PetApi.md b/samples/client/petstore/csharp/generichost/net4.7/FormModels/docs/apis/PetApi.md index e32c1e31e089..59d4ef8e6df0 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/FormModels/docs/apis/PetApi.md +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/docs/apis/PetApi.md @@ -13,6 +13,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* | [**UpdatePetWithForm**](PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data | | [**UploadFile**](PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image | | [**UploadFileWithRequiredFile**](PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) | +| [**UploadFiles**](PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images | # **AddPet** @@ -341,3 +342,38 @@ uploads an image (required) [[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + +# **UploadFiles** +> ApiResponse UploadFiles (List files, long petId) + +uploads an images + + +### Parameters + +| Name | Type | Description | Notes | +|------|------|-------------|-------| +| **files** | **List<System.IO.Stream>** | | | +| **petId** | **long** | ID of pet to update | | + +### Return type + +[**ApiResponse**](ApiResponse.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: multipart/form-data + - **Accept**: application/json + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | + +[[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + diff --git a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs index dbca7881df47..62c158ea45da 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs @@ -196,7 +196,7 @@ public async Task TestEndpointParametersAsyncTest() string patternWithoutDelimiter = default; byte[] varByte = default; double varDouble = default; - Client.Option binary = default; + Client.Option binary = default; Client.Option callback = default; Client.Option date = default; Client.Option dateTime = default; diff --git a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 1f1d7f6c4576..a4aa8f3e245d 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools.Test/Api/PetApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools.Test/Api/PetApiTests.cs @@ -137,7 +137,7 @@ public async Task UploadFileAsyncTest() { long petId = default; Client.Option additionalMetadata = default; - Client.Option file = default; + Client.Option file = default; var response = await _instance.UploadFileAsync(petId, additionalMetadata, file); var model = response.Ok(); Assert.IsType(model); @@ -150,11 +150,24 @@ public async Task UploadFileAsyncTest() public async Task UploadFileWithRequiredFileAsyncTest() { long petId = default; - System.IO.Stream requiredFile = default; + Org.OpenAPITools.Client.FileParameter requiredFile = default; Client.Option additionalMetadata = default; var response = await _instance.UploadFileWithRequiredFileAsync(petId, requiredFile, additionalMetadata); var model = response.Ok(); Assert.IsType(model); } + + /// + /// Test UploadFiles + /// + [Fact (Skip = "not implemented")] + public async Task UploadFilesAsyncTest() + { + List files = default; + long petId = default; + var response = await _instance.UploadFilesAsync(files, petId); + var model = response.Ok(); + Assert.IsType(model); + } } } diff --git a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Api/DefaultApi.cs index 1bbf43279f7c..24a69b84527e 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Api/DefaultApi.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Api/DefaultApi.cs @@ -763,27 +763,19 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = new HttpMethod("POST"); DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Api/FakeApi.cs b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Api/FakeApi.cs index ed9c440bd2b8..9f2605d1777f 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Api/FakeApi.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Api/FakeApi.cs @@ -330,7 +330,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <> - Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -354,7 +354,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <> - Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// To test enum parameters @@ -4071,7 +4071,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); + partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); /// /// Validates the request parameters @@ -4083,7 +4083,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) + private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) { if (patternWithoutDelimiter == null) throw new ArgumentNullException(nameof(patternWithoutDelimiter)); @@ -4122,7 +4122,7 @@ private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte /// /// /// - private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLog = false; AfterTestEndpointParameters(ref suppressDefaultLog, apiResponseLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4149,7 +4149,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Logs exceptions that occur while retrieving the server response @@ -4171,7 +4171,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLogLocalVar = false; OnErrorTestEndpointParameters(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4200,7 +4200,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// /// /// - partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -4221,7 +4221,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -4253,7 +4253,7 @@ public async Task TestEndpointParametersOrDe /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -4272,14 +4272,8 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("number", ClientUtils.ParameterToString(number))); formParameterLocalVars.Add(new KeyValuePair("pattern_without_delimiter", ClientUtils.ParameterToString(patternWithoutDelimiter))); @@ -4289,7 +4283,7 @@ public async Task TestEndpointParametersAsyn formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.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."); if (callback.IsSet) formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); @@ -4318,6 +4312,9 @@ public async Task TestEndpointParametersAsyn if (varString.IsSet) formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4331,11 +4328,6 @@ public async Task TestEndpointParametersAsyn "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = new HttpMethod("POST"); DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -4616,29 +4608,23 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (enumFormString.IsSet) + if (enumFormString.IsSet) formParameterLocalVars.Add(new KeyValuePair("enum_form_string", ClientUtils.ParameterToString(enumFormString.Value))); if (enumFormStringArray.IsSet) formParameterLocalVars.Add(new KeyValuePair("enum_form_string_array", ClientUtils.ParameterToString(enumFormStringArray.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = new HttpMethod("GET"); DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -5524,29 +5510,21 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("param", ClientUtils.ParameterToString(param))); formParameterLocalVars.Add(new KeyValuePair("param2", ClientUtils.ParameterToString(param2))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = new HttpMethod("GET"); DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Api/PetApi.cs b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Api/PetApi.cs index 0eaf83e1f41e..11f4b994064c 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Api/PetApi.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Api/PetApi.cs @@ -216,7 +216,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image @@ -229,7 +229,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -243,7 +243,7 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -256,7 +256,32 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); } /// @@ -415,6 +440,18 @@ public interface IUploadFileWithRequiredFileApiResponse : Org.OpenAPITools.Clien bool IsOk { get; } } + /// + /// The + /// + public interface IUploadFilesApiResponse : Org.OpenAPITools.Client.IApiResponse, IOk + { + /// + /// Returns true if the response is 200 Ok + /// + /// + bool IsOk { get; } + } + /// /// Represents a collection of functions to interact with the API endpoints /// @@ -599,6 +636,26 @@ internal void ExecuteOnErrorUploadFileWithRequiredFile(Exception exception) { OnErrorUploadFileWithRequiredFile?.Invoke(this, new ExceptionEventArgs(exception)); } + + /// + /// The event raised after the server response + /// + public event EventHandler OnUploadFiles; + + /// + /// The event raised after an error querying the server + /// + public event EventHandler OnErrorUploadFiles; + + internal void ExecuteOnUploadFiles(PetApi.UploadFilesApiResponse apiResponse) + { + OnUploadFiles?.Invoke(this, new ApiResponseEventArgs(apiResponse)); + } + + internal void ExecuteOnErrorUploadFiles(Exception exception) + { + OnErrorUploadFiles?.Invoke(this, new ExceptionEventArgs(exception)); + } } /// @@ -2326,18 +2383,17 @@ public async Task UpdatePetWithFormAsync(long pet : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (name.IsSet) + if (name.IsSet) formParameterLocalVars.Add(new KeyValuePair("name", ClientUtils.ParameterToString(name.Value))); if (status.IsSet) formParameterLocalVars.Add(new KeyValuePair("status", ClientUtils.ParameterToString(status.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2351,11 +2407,6 @@ public async Task UpdatePetWithFormAsync(long pet "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = new HttpMethod("POST"); DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -2455,7 +2506,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); + partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); /// /// Validates the request parameters @@ -2463,7 +2514,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFile(Option additionalMetadata, Option file) + private void ValidateUploadFile(Option additionalMetadata, Option file) { if (additionalMetadata.IsSet && additionalMetadata.Value == null) throw new ArgumentNullException(nameof(additionalMetadata)); @@ -2479,7 +2530,7 @@ private void ValidateUploadFile(Option additionalMetadata, Option /// /// - private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) + private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLog = false; AfterUploadFile(ref suppressDefaultLog, apiResponseLocalVar, petId, additionalMetadata, file); @@ -2495,7 +2546,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); + partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); /// /// Logs exceptions that occur while retrieving the server response @@ -2506,7 +2557,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) + private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, additionalMetadata, file); @@ -2524,7 +2575,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// /// /// - partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); + partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); /// /// uploads an image @@ -2534,7 +2585,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2555,7 +2606,7 @@ public async Task UploadFileOrDefaultAsync(long petId, O /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2575,17 +2626,23 @@ public async Task UploadFileAsync(long petId, Option> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (additionalMetadata.IsSet) + if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); if (file.IsSet) - multipartContentLocalVar.Add(new StreamContent(file.Value)); + { + var streamContentLocalVar = new StreamContent(file.Value.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "file", file.Value.FileName ?? "file"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2600,11 +2657,6 @@ public async Task UploadFileAsync(long petId, Option additionalMetadata); + partial void FormatUploadFileWithRequiredFile(ref long petId, ref Org.OpenAPITools.Client.FileParameter requiredFile, ref Option additionalMetadata); /// /// Validates the request parameters @@ -2752,7 +2804,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, Option additionalMetadata) + private void ValidateUploadFileWithRequiredFile(Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { if (requiredFile == null) throw new ArgumentNullException(nameof(requiredFile)); @@ -2768,7 +2820,7 @@ private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, O /// /// /// - private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLog = false; AfterUploadFileWithRequiredFile(ref suppressDefaultLog, apiResponseLocalVar, petId, requiredFile, additionalMetadata); @@ -2784,7 +2836,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// Logs exceptions that occur while retrieving the server response @@ -2795,7 +2847,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFileWithRequiredFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, requiredFile, additionalMetadata); @@ -2813,7 +2865,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// /// /// - partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// uploads an image (required) @@ -2823,7 +2875,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2844,7 +2896,7 @@ public async Task UploadFileWithRequired /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2864,17 +2916,23 @@ public async Task UploadFileWithRequired : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/{petId}/uploadImageWithRequiredFile"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); multipartContentLocalVar.Add(new StreamContent(requiredFile)); + { + var streamContentLocalVar = new StreamContent(requiredFile.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile", requiredFile.FileName ?? "requiredFile"); + } if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2888,11 +2946,6 @@ public async Task UploadFileWithRequired "multipart/form-data" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - string[] acceptLocalVars = new string[] { "application/json", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" @@ -3032,5 +3085,282 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } + + partial void FormatUploadFiles(List files, ref long petId); + + /// + /// Validates the request parameters + /// + /// + /// + private void ValidateUploadFiles(List files) + { + if (files == null) + throw new ArgumentNullException(nameof(files)); + } + + /// + /// Processes the server response + /// + /// + /// + /// + private void AfterUploadFilesDefaultImplementation(IUploadFilesApiResponse apiResponseLocalVar, List files, long petId) + { + bool suppressDefaultLog = false; + AfterUploadFiles(ref suppressDefaultLog, apiResponseLocalVar, files, petId); + if (!suppressDefaultLog) + Logger.LogInformation("{0,-9} | {1} | {2}", (apiResponseLocalVar.DownloadedAt - apiResponseLocalVar.RequestedAt).TotalSeconds, apiResponseLocalVar.StatusCode, apiResponseLocalVar.Path); + } + + /// + /// Processes the server response + /// + /// + /// + /// + /// + partial void AfterUploadFiles(ref bool suppressDefaultLog, IUploadFilesApiResponse apiResponseLocalVar, List files, long petId); + + /// + /// Logs exceptions that occur while retrieving the server response + /// + /// + /// + /// + /// + /// + private void OnErrorUploadFilesDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId) + { + bool suppressDefaultLogLocalVar = false; + OnErrorUploadFiles(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, files, petId); + if (!suppressDefaultLogLocalVar) + Logger.LogError(exceptionLocalVar, "An error occurred while sending the request to the server."); + } + + /// + /// A partial method that gives developers a way to provide customized exception handling + /// + /// + /// + /// + /// + /// + /// + partial void OnErrorUploadFiles(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId); + + /// + /// uploads an images + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + try + { + return await UploadFilesAsync(files, petId, cancellationToken).ConfigureAwait(false); + } + catch (Exception) + { + return null; + } + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + UriBuilder uriBuilderLocalVar = new UriBuilder(); + + try + { + ValidateUploadFiles(files); + + FormatUploadFiles(files, ref petId); + + using (HttpRequestMessage httpRequestMessageLocalVar = new HttpRequestMessage()) + { + uriBuilderLocalVar.Host = HttpClient.BaseAddress.Host; + uriBuilderLocalVar.Port = HttpClient.BaseAddress.Port; + uriBuilderLocalVar.Scheme = HttpClient.BaseAddress.Scheme; + uriBuilderLocalVar.Path = HttpClient.BaseAddress.AbsolutePath == "/" + ? "/pet/{petId}/uploadImages" + : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}/uploadImages"); + uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); + + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); + + httpRequestMessageLocalVar.Content = multipartContentLocalVar; + + List> formParameterLocalVars = new List>(); + + foreach (Org.OpenAPITools.Client.FileParameter fileParameterLocalVar in files) + { + var streamContentLocalVar = new StreamContent(fileParameterLocalVar.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "files", fileParameterLocalVar.FileName ?? "files"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); + + List tokenBaseLocalVars = new List(); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; + + OAuthToken oauthTokenLocalVar1 = (OAuthToken) await OauthTokenProvider.GetAsync(cancellation: cancellationToken).ConfigureAwait(false); + + tokenBaseLocalVars.Add(oauthTokenLocalVar1); + + oauthTokenLocalVar1.UseInHeader(httpRequestMessageLocalVar, ""); + + string[] contentTypes = new string[] { + "multipart/form-data" + }; + + string[] acceptLocalVars = new string[] { + "application/json" + }; + + IEnumerable acceptHeaderValuesLocalVar = ClientUtils.SelectHeaderAcceptArray(acceptLocalVars); + + foreach (var acceptLocalVar in acceptHeaderValuesLocalVar) + httpRequestMessageLocalVar.Headers.Accept.Add(acceptLocalVar); + httpRequestMessageLocalVar.Method = new HttpMethod("POST"); + + DateTime requestedAtLocalVar = DateTime.UtcNow; + + using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false)) + { + ILogger apiResponseLoggerLocalVar = LoggerFactory.CreateLogger(); + UploadFilesApiResponse apiResponseLocalVar; + + switch ((int)httpResponseMessageLocalVar.StatusCode) { + default: { + string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync().ConfigureAwait(false); + apiResponseLocalVar = new UploadFilesApiResponse(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/pet/{petId}/uploadImages", requestedAtLocalVar, _jsonSerializerOptions); + + break; + } + } + + AfterUploadFilesDefaultImplementation(apiResponseLocalVar, files, petId); + + Events.ExecuteOnUploadFiles(apiResponseLocalVar); + + if (apiResponseLocalVar.StatusCode == (HttpStatusCode) 429) + foreach(TokenBase tokenBaseLocalVar in tokenBaseLocalVars) + tokenBaseLocalVar.BeginRateLimit(); + + return apiResponseLocalVar; + } + } + } + catch(Exception e) + { + OnErrorUploadFilesDefaultImplementation(e, "/pet/{petId}/uploadImages", uriBuilderLocalVar.Path, files, petId); + Events.ExecuteOnErrorUploadFiles(e); + throw; + } + } + + /// + /// The + /// + public partial class UploadFilesApiResponse : Org.OpenAPITools.Client.ApiResponse, IUploadFilesApiResponse + { + /// + /// The logger + /// + public ILogger Logger { get; } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, string rawContent, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, rawContent, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, System.IO.Stream contentStream, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, contentStream, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + partial void OnCreated(global::System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage); + + /// + /// Returns true if the response is 200 Ok + /// + /// + public bool IsOk => 200 == (int)StatusCode; + + /// + /// Deserializes the response if the response is 200 Ok + /// + /// + public Org.OpenAPITools.Model.ApiResponse Ok() + { + // This logic may be modified with the AsModel.mustache template + return IsOk + ? System.Text.Json.JsonSerializer.Deserialize(RawContent, _jsonSerializerOptions) + : default; + } + + /// + /// Returns true if the response is 200 Ok and the deserialized response is not null + /// + /// + /// + public bool TryOk(out Org.OpenAPITools.Model.ApiResponse result) + { + result = null; + + try + { + result = Ok(); + } catch (Exception e) + { + OnDeserializationErrorDefaultImplementation(e, (HttpStatusCode)200); + } + + return result != null; + } + + private void OnDeserializationErrorDefaultImplementation(Exception exception, HttpStatusCode httpStatusCode) + { + bool suppressDefaultLog = false; + OnDeserializationError(ref suppressDefaultLog, exception, httpStatusCode); + if (!suppressDefaultLog) + Logger.LogError(exception, "An error occurred while deserializing the {code} response.", httpStatusCode); + } + + partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); + } } } diff --git a/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..6150dbcf4774 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,40 @@ +// +/* + * OpenAPI Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.7/OneOf/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net4.7/OneOf/.openapi-generator/FILES index 47a388f55336..ef946be5e2fb 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/OneOf/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net4.7/OneOf/.openapi-generator/FILES @@ -24,6 +24,7 @@ src/Org.OpenAPITools/Client/CookieContainer.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 diff --git a/samples/client/petstore/csharp/generichost/net4.7/OneOf/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net4.7/OneOf/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..5c8e0767f76a --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.7/OneOf/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,40 @@ +// +/* + * fruity + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 0.0.1 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.7/Petstore/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net4.7/Petstore/.openapi-generator/FILES index a6635c9d8351..82501a149e01 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/Petstore/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net4.7/Petstore/.openapi-generator/FILES @@ -138,6 +138,7 @@ src/Org.OpenAPITools/Client/CookieContainer.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/HttpSigningConfiguration.cs src/Org.OpenAPITools/Client/HttpSigningToken.cs diff --git a/samples/client/petstore/csharp/generichost/net4.7/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net4.7/Petstore/api/openapi.yaml index d8106a5755fc..ca451f3fb832 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net4.7/Petstore/api/openapi.yaml @@ -331,6 +331,40 @@ paths: summary: uploads an image tags: - pet + /pet/{petId}/uploadImages: + post: + description: "" + operationId: uploadFiles + parameters: + - description: ID of pet to update + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + multipart/form-data: + schema: + $ref: "#/components/schemas/uploadFiles_request" + required: true + responses: + "200": + content: + application/json: + schema: + $ref: "#/components/schemas/ApiResponse" + description: successful operation + security: + - petstore_auth: + - write:pets + - read:pets + summary: uploads an images + tags: + - pet /store/inventory: get: description: Returns a map of status codes to quantities @@ -2924,6 +2958,16 @@ components: format: binary type: string type: object + uploadFiles_request: + properties: + files: + items: + format: binary + type: string + type: array + required: + - files + type: object testEnumParameters_request: properties: enum_form_string_array: diff --git a/samples/client/petstore/csharp/generichost/net4.7/Petstore/docs/apis/PetApi.md b/samples/client/petstore/csharp/generichost/net4.7/Petstore/docs/apis/PetApi.md index 2826ea00f728..b42ee516b313 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/Petstore/docs/apis/PetApi.md +++ b/samples/client/petstore/csharp/generichost/net4.7/Petstore/docs/apis/PetApi.md @@ -13,6 +13,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* | [**UpdatePetWithForm**](PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data | | [**UploadFile**](PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image | | [**UploadFileWithRequiredFile**](PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) | +| [**UploadFiles**](PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images | # **AddPet** @@ -341,3 +342,38 @@ uploads an image (required) [[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + +# **UploadFiles** +> ApiResponse UploadFiles (List files, long petId) + +uploads an images + + +### Parameters + +| Name | Type | Description | Notes | +|------|------|-------------|-------| +| **files** | **List<System.IO.Stream>** | | | +| **petId** | **long** | ID of pet to update | | + +### Return type + +[**ApiResponse**](ApiResponse.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: multipart/form-data + - **Accept**: application/json + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | + +[[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + diff --git a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs index ce85f85778ef..6420b47bc8b4 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs @@ -196,7 +196,7 @@ public async Task TestEndpointParametersAsyncTest() string patternWithoutDelimiter = default; byte[] varByte = default; double varDouble = default; - Client.Option binary = default; + Client.Option binary = default; Client.Option callback = default; Client.Option date = default; Client.Option dateTime = default; diff --git a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 215e88093797..e9b05337bb59 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools.Test/Api/PetApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools.Test/Api/PetApiTests.cs @@ -137,7 +137,7 @@ public async Task UploadFileAsyncTest() { long petId = default; Client.Option additionalMetadata = default; - Client.Option file = default; + Client.Option file = default; var response = await _instance.UploadFileAsync(petId, additionalMetadata, file); var model = response.Ok(); Assert.IsType(model); @@ -150,11 +150,24 @@ public async Task UploadFileAsyncTest() public async Task UploadFileWithRequiredFileAsyncTest() { long petId = default; - System.IO.Stream requiredFile = default; + Org.OpenAPITools.Client.FileParameter requiredFile = default; Client.Option additionalMetadata = default; var response = await _instance.UploadFileWithRequiredFileAsync(petId, requiredFile, additionalMetadata); var model = response.Ok(); Assert.IsType(model); } + + /// + /// Test UploadFiles + /// + [Fact (Skip = "not implemented")] + public async Task UploadFilesAsyncTest() + { + List files = default; + long petId = default; + var response = await _instance.UploadFilesAsync(files, petId); + var model = response.Ok(); + Assert.IsType(model); + } } } diff --git a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs index 1bbf43279f7c..24a69b84527e 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs @@ -763,27 +763,19 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = new HttpMethod("POST"); DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Api/FakeApi.cs b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Api/FakeApi.cs index feec543b8c1f..a3a842305a6f 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Api/FakeApi.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Api/FakeApi.cs @@ -330,7 +330,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <> - Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -354,7 +354,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <> - Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// To test enum parameters @@ -4071,7 +4071,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); + partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); /// /// Validates the request parameters @@ -4083,7 +4083,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) + private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) { if (patternWithoutDelimiter == null) throw new ArgumentNullException(nameof(patternWithoutDelimiter)); @@ -4122,7 +4122,7 @@ private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte /// /// /// - private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLog = false; AfterTestEndpointParameters(ref suppressDefaultLog, apiResponseLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4149,7 +4149,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Logs exceptions that occur while retrieving the server response @@ -4171,7 +4171,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLogLocalVar = false; OnErrorTestEndpointParameters(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4200,7 +4200,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// /// /// - partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -4221,7 +4221,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -4253,7 +4253,7 @@ public async Task TestEndpointParametersOrDe /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -4272,14 +4272,8 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("number", ClientUtils.ParameterToString(number))); formParameterLocalVars.Add(new KeyValuePair("pattern_without_delimiter", ClientUtils.ParameterToString(patternWithoutDelimiter))); @@ -4289,7 +4283,7 @@ public async Task TestEndpointParametersAsyn formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.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."); if (callback.IsSet) formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); @@ -4318,6 +4312,9 @@ public async Task TestEndpointParametersAsyn if (varString.IsSet) formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4331,11 +4328,6 @@ public async Task TestEndpointParametersAsyn "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = new HttpMethod("POST"); DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -4628,29 +4620,23 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (enumFormString.IsSet) + if (enumFormString.IsSet) formParameterLocalVars.Add(new KeyValuePair("enum_form_string", ClientUtils.ParameterToString(enumFormString.Value))); if (enumFormStringArray.IsSet) formParameterLocalVars.Add(new KeyValuePair("enum_form_string_array", ClientUtils.ParameterToString(enumFormStringArray.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = new HttpMethod("GET"); DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -5536,29 +5522,21 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("param", ClientUtils.ParameterToString(param))); formParameterLocalVars.Add(new KeyValuePair("param2", ClientUtils.ParameterToString(param2))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = new HttpMethod("GET"); DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Api/PetApi.cs b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Api/PetApi.cs index 7fe162b51bfb..9d04b53a95c5 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Api/PetApi.cs +++ b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Api/PetApi.cs @@ -216,7 +216,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image @@ -229,7 +229,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -243,7 +243,7 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -256,7 +256,32 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); } /// @@ -415,6 +440,18 @@ public interface IUploadFileWithRequiredFileApiResponse : Org.OpenAPITools.Clien bool IsOk { get; } } + /// + /// The + /// + public interface IUploadFilesApiResponse : Org.OpenAPITools.Client.IApiResponse, IOk + { + /// + /// Returns true if the response is 200 Ok + /// + /// + bool IsOk { get; } + } + /// /// Represents a collection of functions to interact with the API endpoints /// @@ -599,6 +636,26 @@ internal void ExecuteOnErrorUploadFileWithRequiredFile(Exception exception) { OnErrorUploadFileWithRequiredFile?.Invoke(this, new ExceptionEventArgs(exception)); } + + /// + /// The event raised after the server response + /// + public event EventHandler OnUploadFiles; + + /// + /// The event raised after an error querying the server + /// + public event EventHandler OnErrorUploadFiles; + + internal void ExecuteOnUploadFiles(PetApi.UploadFilesApiResponse apiResponse) + { + OnUploadFiles?.Invoke(this, new ApiResponseEventArgs(apiResponse)); + } + + internal void ExecuteOnErrorUploadFiles(Exception exception) + { + OnErrorUploadFiles?.Invoke(this, new ExceptionEventArgs(exception)); + } } /// @@ -2326,18 +2383,17 @@ public async Task UpdatePetWithFormAsync(long pet : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (name.IsSet) + if (name.IsSet) formParameterLocalVars.Add(new KeyValuePair("name", ClientUtils.ParameterToString(name.Value))); if (status.IsSet) formParameterLocalVars.Add(new KeyValuePair("status", ClientUtils.ParameterToString(status.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2351,11 +2407,6 @@ public async Task UpdatePetWithFormAsync(long pet "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = new HttpMethod("POST"); DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -2455,7 +2506,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); + partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); /// /// Validates the request parameters @@ -2463,7 +2514,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFile(Option additionalMetadata, Option file) + private void ValidateUploadFile(Option additionalMetadata, Option file) { if (additionalMetadata.IsSet && additionalMetadata.Value == null) throw new ArgumentNullException(nameof(additionalMetadata)); @@ -2479,7 +2530,7 @@ private void ValidateUploadFile(Option additionalMetadata, Option /// /// - private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) + private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLog = false; AfterUploadFile(ref suppressDefaultLog, apiResponseLocalVar, petId, additionalMetadata, file); @@ -2495,7 +2546,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); + partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); /// /// Logs exceptions that occur while retrieving the server response @@ -2506,7 +2557,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) + private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, additionalMetadata, file); @@ -2524,7 +2575,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// /// /// - partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); + partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); /// /// uploads an image @@ -2534,7 +2585,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2555,7 +2606,7 @@ public async Task UploadFileOrDefaultAsync(long petId, O /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2575,17 +2626,23 @@ public async Task UploadFileAsync(long petId, Option> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (additionalMetadata.IsSet) + if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); if (file.IsSet) - multipartContentLocalVar.Add(new StreamContent(file.Value)); + { + var streamContentLocalVar = new StreamContent(file.Value.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "file", file.Value.FileName ?? "file"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2600,11 +2657,6 @@ public async Task UploadFileAsync(long petId, Option additionalMetadata); + partial void FormatUploadFileWithRequiredFile(ref long petId, ref Org.OpenAPITools.Client.FileParameter requiredFile, ref Option additionalMetadata); /// /// Validates the request parameters @@ -2752,7 +2804,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, Option additionalMetadata) + private void ValidateUploadFileWithRequiredFile(Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { if (requiredFile == null) throw new ArgumentNullException(nameof(requiredFile)); @@ -2768,7 +2820,7 @@ private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, O /// /// /// - private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLog = false; AfterUploadFileWithRequiredFile(ref suppressDefaultLog, apiResponseLocalVar, petId, requiredFile, additionalMetadata); @@ -2784,7 +2836,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// Logs exceptions that occur while retrieving the server response @@ -2795,7 +2847,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFileWithRequiredFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, requiredFile, additionalMetadata); @@ -2813,7 +2865,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// /// /// - partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// uploads an image (required) @@ -2823,7 +2875,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2844,7 +2896,7 @@ public async Task UploadFileWithRequired /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2864,17 +2916,23 @@ public async Task UploadFileWithRequired : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/{petId}/uploadImageWithRequiredFile"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); multipartContentLocalVar.Add(new StreamContent(requiredFile)); + { + var streamContentLocalVar = new StreamContent(requiredFile.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile", requiredFile.FileName ?? "requiredFile"); + } if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2888,11 +2946,6 @@ public async Task UploadFileWithRequired "multipart/form-data" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - string[] acceptLocalVars = new string[] { "application/json", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" @@ -3032,5 +3085,282 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } + + partial void FormatUploadFiles(List files, ref long petId); + + /// + /// Validates the request parameters + /// + /// + /// + private void ValidateUploadFiles(List files) + { + if (files == null) + throw new ArgumentNullException(nameof(files)); + } + + /// + /// Processes the server response + /// + /// + /// + /// + private void AfterUploadFilesDefaultImplementation(IUploadFilesApiResponse apiResponseLocalVar, List files, long petId) + { + bool suppressDefaultLog = false; + AfterUploadFiles(ref suppressDefaultLog, apiResponseLocalVar, files, petId); + if (!suppressDefaultLog) + Logger.LogInformation("{0,-9} | {1} | {2}", (apiResponseLocalVar.DownloadedAt - apiResponseLocalVar.RequestedAt).TotalSeconds, apiResponseLocalVar.StatusCode, apiResponseLocalVar.Path); + } + + /// + /// Processes the server response + /// + /// + /// + /// + /// + partial void AfterUploadFiles(ref bool suppressDefaultLog, IUploadFilesApiResponse apiResponseLocalVar, List files, long petId); + + /// + /// Logs exceptions that occur while retrieving the server response + /// + /// + /// + /// + /// + /// + private void OnErrorUploadFilesDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId) + { + bool suppressDefaultLogLocalVar = false; + OnErrorUploadFiles(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, files, petId); + if (!suppressDefaultLogLocalVar) + Logger.LogError(exceptionLocalVar, "An error occurred while sending the request to the server."); + } + + /// + /// A partial method that gives developers a way to provide customized exception handling + /// + /// + /// + /// + /// + /// + /// + partial void OnErrorUploadFiles(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId); + + /// + /// uploads an images + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + try + { + return await UploadFilesAsync(files, petId, cancellationToken).ConfigureAwait(false); + } + catch (Exception) + { + return null; + } + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + UriBuilder uriBuilderLocalVar = new UriBuilder(); + + try + { + ValidateUploadFiles(files); + + FormatUploadFiles(files, ref petId); + + using (HttpRequestMessage httpRequestMessageLocalVar = new HttpRequestMessage()) + { + uriBuilderLocalVar.Host = HttpClient.BaseAddress.Host; + uriBuilderLocalVar.Port = HttpClient.BaseAddress.Port; + uriBuilderLocalVar.Scheme = HttpClient.BaseAddress.Scheme; + uriBuilderLocalVar.Path = HttpClient.BaseAddress.AbsolutePath == "/" + ? "/pet/{petId}/uploadImages" + : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}/uploadImages"); + uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); + + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); + + httpRequestMessageLocalVar.Content = multipartContentLocalVar; + + List> formParameterLocalVars = new List>(); + + foreach (Org.OpenAPITools.Client.FileParameter fileParameterLocalVar in files) + { + var streamContentLocalVar = new StreamContent(fileParameterLocalVar.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "files", fileParameterLocalVar.FileName ?? "files"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); + + List tokenBaseLocalVars = new List(); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; + + OAuthToken oauthTokenLocalVar1 = (OAuthToken) await OauthTokenProvider.GetAsync(cancellation: cancellationToken).ConfigureAwait(false); + + tokenBaseLocalVars.Add(oauthTokenLocalVar1); + + oauthTokenLocalVar1.UseInHeader(httpRequestMessageLocalVar, ""); + + string[] contentTypes = new string[] { + "multipart/form-data" + }; + + string[] acceptLocalVars = new string[] { + "application/json" + }; + + IEnumerable acceptHeaderValuesLocalVar = ClientUtils.SelectHeaderAcceptArray(acceptLocalVars); + + foreach (var acceptLocalVar in acceptHeaderValuesLocalVar) + httpRequestMessageLocalVar.Headers.Accept.Add(acceptLocalVar); + httpRequestMessageLocalVar.Method = new HttpMethod("POST"); + + DateTime requestedAtLocalVar = DateTime.UtcNow; + + using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false)) + { + ILogger apiResponseLoggerLocalVar = LoggerFactory.CreateLogger(); + UploadFilesApiResponse apiResponseLocalVar; + + switch ((int)httpResponseMessageLocalVar.StatusCode) { + default: { + string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync().ConfigureAwait(false); + apiResponseLocalVar = new UploadFilesApiResponse(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/pet/{petId}/uploadImages", requestedAtLocalVar, _jsonSerializerOptions); + + break; + } + } + + AfterUploadFilesDefaultImplementation(apiResponseLocalVar, files, petId); + + Events.ExecuteOnUploadFiles(apiResponseLocalVar); + + if (apiResponseLocalVar.StatusCode == (HttpStatusCode) 429) + foreach(TokenBase tokenBaseLocalVar in tokenBaseLocalVars) + tokenBaseLocalVar.BeginRateLimit(); + + return apiResponseLocalVar; + } + } + } + catch(Exception e) + { + OnErrorUploadFilesDefaultImplementation(e, "/pet/{petId}/uploadImages", uriBuilderLocalVar.Path, files, petId); + Events.ExecuteOnErrorUploadFiles(e); + throw; + } + } + + /// + /// The + /// + public partial class UploadFilesApiResponse : Org.OpenAPITools.Client.ApiResponse, IUploadFilesApiResponse + { + /// + /// The logger + /// + public ILogger Logger { get; } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, string rawContent, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, rawContent, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, System.IO.Stream contentStream, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, contentStream, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + partial void OnCreated(global::System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage); + + /// + /// Returns true if the response is 200 Ok + /// + /// + public bool IsOk => 200 == (int)StatusCode; + + /// + /// Deserializes the response if the response is 200 Ok + /// + /// + public Org.OpenAPITools.Model.ApiResponse Ok() + { + // This logic may be modified with the AsModel.mustache template + return IsOk + ? System.Text.Json.JsonSerializer.Deserialize(RawContent, _jsonSerializerOptions) + : default; + } + + /// + /// Returns true if the response is 200 Ok and the deserialized response is not null + /// + /// + /// + public bool TryOk(out Org.OpenAPITools.Model.ApiResponse result) + { + result = null; + + try + { + result = Ok(); + } catch (Exception e) + { + OnDeserializationErrorDefaultImplementation(e, (HttpStatusCode)200); + } + + return result != null; + } + + private void OnDeserializationErrorDefaultImplementation(Exception exception, HttpStatusCode httpStatusCode) + { + bool suppressDefaultLog = false; + OnDeserializationError(ref suppressDefaultLog, exception, httpStatusCode); + if (!suppressDefaultLog) + Logger.LogError(exception, "An error occurred while deserializing the {code} response.", httpStatusCode); + } + + partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); + } } } diff --git a/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..6150dbcf4774 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,40 @@ +// +/* + * OpenAPI Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.7/UseDateTimeForDate/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net4.7/UseDateTimeForDate/.openapi-generator/FILES index 5abbcf46f35c..e28da391730f 100644 --- a/samples/client/petstore/csharp/generichost/net4.7/UseDateTimeForDate/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net4.7/UseDateTimeForDate/.openapi-generator/FILES @@ -21,6 +21,7 @@ src/Org.OpenAPITools/Client/CookieContainer.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 diff --git a/samples/client/petstore/csharp/generichost/net4.7/UseDateTimeForDate/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net4.7/UseDateTimeForDate/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..253a70bc8053 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.7/UseDateTimeForDate/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,40 @@ +// +/* + * OpenAPI Dates + * + * Thic spec contains endpoints with dates in different formats + * + * The version of the OpenAPI document: 1.0.0 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.8/AllOf/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net4.8/AllOf/.openapi-generator/FILES index 47b2b9b5c4f4..1c80f1449c66 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/AllOf/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net4.8/AllOf/.openapi-generator/FILES @@ -23,6 +23,7 @@ src/Org.OpenAPITools/Client/CookieContainer.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 diff --git a/samples/client/petstore/csharp/generichost/net4.8/AllOf/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net4.8/AllOf/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..936f8415fda6 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.8/AllOf/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,40 @@ +// +/* + * Example + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.8/AnyOf/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net4.8/AnyOf/.openapi-generator/FILES index 59cc1ea25a08..5e82fcb80ae5 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/AnyOf/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net4.8/AnyOf/.openapi-generator/FILES @@ -23,6 +23,7 @@ src/Org.OpenAPITools/Client/CookieContainer.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 diff --git a/samples/client/petstore/csharp/generichost/net4.8/AnyOf/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net4.8/AnyOf/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..5c8e0767f76a --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.8/AnyOf/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,40 @@ +// +/* + * fruity + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 0.0.1 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.8/AnyOfNoCompare/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net4.8/AnyOfNoCompare/.openapi-generator/FILES index 59cc1ea25a08..5e82fcb80ae5 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/AnyOfNoCompare/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net4.8/AnyOfNoCompare/.openapi-generator/FILES @@ -23,6 +23,7 @@ src/Org.OpenAPITools/Client/CookieContainer.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 diff --git a/samples/client/petstore/csharp/generichost/net4.8/AnyOfNoCompare/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net4.8/AnyOfNoCompare/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..5c8e0767f76a --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.8/AnyOfNoCompare/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,40 @@ +// +/* + * fruity + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 0.0.1 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.8/FormModels/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net4.8/FormModels/.openapi-generator/FILES index 3c592107ec19..4d9b3d8248d3 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/FormModels/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/.openapi-generator/FILES @@ -163,6 +163,7 @@ src/Org.OpenAPITools/Client/CookieContainer.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/HttpSigningConfiguration.cs src/Org.OpenAPITools/Client/HttpSigningToken.cs diff --git a/samples/client/petstore/csharp/generichost/net4.8/FormModels/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net4.8/FormModels/api/openapi.yaml index a9ab8dd51c13..7017affc0b9c 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/FormModels/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/api/openapi.yaml @@ -326,6 +326,40 @@ paths: summary: uploads an image tags: - pet + /pet/{petId}/uploadImages: + post: + description: "" + operationId: uploadFiles + parameters: + - description: ID of pet to update + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + multipart/form-data: + schema: + $ref: "#/components/schemas/uploadFiles_request" + required: true + responses: + "200": + content: + application/json: + schema: + $ref: "#/components/schemas/ApiResponse" + description: successful operation + security: + - petstore_auth: + - write:pets + - read:pets + summary: uploads an images + tags: + - pet /store/inventory: get: description: Returns a map of status codes to quantities @@ -2748,6 +2782,16 @@ components: format: binary type: string type: object + uploadFiles_request: + properties: + files: + items: + format: binary + type: string + type: array + required: + - files + type: object testEnumParameters_request_enum_form_string_array_inner: default: $ enum: diff --git a/samples/client/petstore/csharp/generichost/net4.8/FormModels/docs/apis/PetApi.md b/samples/client/petstore/csharp/generichost/net4.8/FormModels/docs/apis/PetApi.md index e32c1e31e089..59d4ef8e6df0 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/FormModels/docs/apis/PetApi.md +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/docs/apis/PetApi.md @@ -13,6 +13,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* | [**UpdatePetWithForm**](PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data | | [**UploadFile**](PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image | | [**UploadFileWithRequiredFile**](PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) | +| [**UploadFiles**](PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images | # **AddPet** @@ -341,3 +342,38 @@ uploads an image (required) [[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + +# **UploadFiles** +> ApiResponse UploadFiles (List files, long petId) + +uploads an images + + +### Parameters + +| Name | Type | Description | Notes | +|------|------|-------------|-------| +| **files** | **List<System.IO.Stream>** | | | +| **petId** | **long** | ID of pet to update | | + +### Return type + +[**ApiResponse**](ApiResponse.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: multipart/form-data + - **Accept**: application/json + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | + +[[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + diff --git a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs index dbca7881df47..62c158ea45da 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs @@ -196,7 +196,7 @@ public async Task TestEndpointParametersAsyncTest() string patternWithoutDelimiter = default; byte[] varByte = default; double varDouble = default; - Client.Option binary = default; + Client.Option binary = default; Client.Option callback = default; Client.Option date = default; Client.Option dateTime = default; diff --git a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 1f1d7f6c4576..a4aa8f3e245d 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools.Test/Api/PetApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools.Test/Api/PetApiTests.cs @@ -137,7 +137,7 @@ public async Task UploadFileAsyncTest() { long petId = default; Client.Option additionalMetadata = default; - Client.Option file = default; + Client.Option file = default; var response = await _instance.UploadFileAsync(petId, additionalMetadata, file); var model = response.Ok(); Assert.IsType(model); @@ -150,11 +150,24 @@ public async Task UploadFileAsyncTest() public async Task UploadFileWithRequiredFileAsyncTest() { long petId = default; - System.IO.Stream requiredFile = default; + Org.OpenAPITools.Client.FileParameter requiredFile = default; Client.Option additionalMetadata = default; var response = await _instance.UploadFileWithRequiredFileAsync(petId, requiredFile, additionalMetadata); var model = response.Ok(); Assert.IsType(model); } + + /// + /// Test UploadFiles + /// + [Fact (Skip = "not implemented")] + public async Task UploadFilesAsyncTest() + { + List files = default; + long petId = default; + var response = await _instance.UploadFilesAsync(files, petId); + var model = response.Ok(); + Assert.IsType(model); + } } } diff --git a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Api/DefaultApi.cs index 1bbf43279f7c..24a69b84527e 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Api/DefaultApi.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Api/DefaultApi.cs @@ -763,27 +763,19 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = new HttpMethod("POST"); DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Api/FakeApi.cs b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Api/FakeApi.cs index ed9c440bd2b8..9f2605d1777f 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Api/FakeApi.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Api/FakeApi.cs @@ -330,7 +330,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <> - Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -354,7 +354,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <> - Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// To test enum parameters @@ -4071,7 +4071,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); + partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); /// /// Validates the request parameters @@ -4083,7 +4083,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) + private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) { if (patternWithoutDelimiter == null) throw new ArgumentNullException(nameof(patternWithoutDelimiter)); @@ -4122,7 +4122,7 @@ private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte /// /// /// - private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLog = false; AfterTestEndpointParameters(ref suppressDefaultLog, apiResponseLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4149,7 +4149,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Logs exceptions that occur while retrieving the server response @@ -4171,7 +4171,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLogLocalVar = false; OnErrorTestEndpointParameters(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4200,7 +4200,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// /// /// - partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -4221,7 +4221,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -4253,7 +4253,7 @@ public async Task TestEndpointParametersOrDe /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -4272,14 +4272,8 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("number", ClientUtils.ParameterToString(number))); formParameterLocalVars.Add(new KeyValuePair("pattern_without_delimiter", ClientUtils.ParameterToString(patternWithoutDelimiter))); @@ -4289,7 +4283,7 @@ public async Task TestEndpointParametersAsyn formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.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."); if (callback.IsSet) formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); @@ -4318,6 +4312,9 @@ public async Task TestEndpointParametersAsyn if (varString.IsSet) formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4331,11 +4328,6 @@ public async Task TestEndpointParametersAsyn "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = new HttpMethod("POST"); DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -4616,29 +4608,23 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (enumFormString.IsSet) + if (enumFormString.IsSet) formParameterLocalVars.Add(new KeyValuePair("enum_form_string", ClientUtils.ParameterToString(enumFormString.Value))); if (enumFormStringArray.IsSet) formParameterLocalVars.Add(new KeyValuePair("enum_form_string_array", ClientUtils.ParameterToString(enumFormStringArray.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = new HttpMethod("GET"); DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -5524,29 +5510,21 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("param", ClientUtils.ParameterToString(param))); formParameterLocalVars.Add(new KeyValuePair("param2", ClientUtils.ParameterToString(param2))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = new HttpMethod("GET"); DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Api/PetApi.cs b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Api/PetApi.cs index 0eaf83e1f41e..11f4b994064c 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Api/PetApi.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Api/PetApi.cs @@ -216,7 +216,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image @@ -229,7 +229,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -243,7 +243,7 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -256,7 +256,32 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); } /// @@ -415,6 +440,18 @@ public interface IUploadFileWithRequiredFileApiResponse : Org.OpenAPITools.Clien bool IsOk { get; } } + /// + /// The + /// + public interface IUploadFilesApiResponse : Org.OpenAPITools.Client.IApiResponse, IOk + { + /// + /// Returns true if the response is 200 Ok + /// + /// + bool IsOk { get; } + } + /// /// Represents a collection of functions to interact with the API endpoints /// @@ -599,6 +636,26 @@ internal void ExecuteOnErrorUploadFileWithRequiredFile(Exception exception) { OnErrorUploadFileWithRequiredFile?.Invoke(this, new ExceptionEventArgs(exception)); } + + /// + /// The event raised after the server response + /// + public event EventHandler OnUploadFiles; + + /// + /// The event raised after an error querying the server + /// + public event EventHandler OnErrorUploadFiles; + + internal void ExecuteOnUploadFiles(PetApi.UploadFilesApiResponse apiResponse) + { + OnUploadFiles?.Invoke(this, new ApiResponseEventArgs(apiResponse)); + } + + internal void ExecuteOnErrorUploadFiles(Exception exception) + { + OnErrorUploadFiles?.Invoke(this, new ExceptionEventArgs(exception)); + } } /// @@ -2326,18 +2383,17 @@ public async Task UpdatePetWithFormAsync(long pet : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (name.IsSet) + if (name.IsSet) formParameterLocalVars.Add(new KeyValuePair("name", ClientUtils.ParameterToString(name.Value))); if (status.IsSet) formParameterLocalVars.Add(new KeyValuePair("status", ClientUtils.ParameterToString(status.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2351,11 +2407,6 @@ public async Task UpdatePetWithFormAsync(long pet "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = new HttpMethod("POST"); DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -2455,7 +2506,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); + partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); /// /// Validates the request parameters @@ -2463,7 +2514,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFile(Option additionalMetadata, Option file) + private void ValidateUploadFile(Option additionalMetadata, Option file) { if (additionalMetadata.IsSet && additionalMetadata.Value == null) throw new ArgumentNullException(nameof(additionalMetadata)); @@ -2479,7 +2530,7 @@ private void ValidateUploadFile(Option additionalMetadata, Option /// /// - private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) + private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLog = false; AfterUploadFile(ref suppressDefaultLog, apiResponseLocalVar, petId, additionalMetadata, file); @@ -2495,7 +2546,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); + partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); /// /// Logs exceptions that occur while retrieving the server response @@ -2506,7 +2557,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) + private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, additionalMetadata, file); @@ -2524,7 +2575,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// /// /// - partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); + partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); /// /// uploads an image @@ -2534,7 +2585,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2555,7 +2606,7 @@ public async Task UploadFileOrDefaultAsync(long petId, O /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2575,17 +2626,23 @@ public async Task UploadFileAsync(long petId, Option> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (additionalMetadata.IsSet) + if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); if (file.IsSet) - multipartContentLocalVar.Add(new StreamContent(file.Value)); + { + var streamContentLocalVar = new StreamContent(file.Value.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "file", file.Value.FileName ?? "file"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2600,11 +2657,6 @@ public async Task UploadFileAsync(long petId, Option additionalMetadata); + partial void FormatUploadFileWithRequiredFile(ref long petId, ref Org.OpenAPITools.Client.FileParameter requiredFile, ref Option additionalMetadata); /// /// Validates the request parameters @@ -2752,7 +2804,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, Option additionalMetadata) + private void ValidateUploadFileWithRequiredFile(Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { if (requiredFile == null) throw new ArgumentNullException(nameof(requiredFile)); @@ -2768,7 +2820,7 @@ private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, O /// /// /// - private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLog = false; AfterUploadFileWithRequiredFile(ref suppressDefaultLog, apiResponseLocalVar, petId, requiredFile, additionalMetadata); @@ -2784,7 +2836,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// Logs exceptions that occur while retrieving the server response @@ -2795,7 +2847,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFileWithRequiredFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, requiredFile, additionalMetadata); @@ -2813,7 +2865,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// /// /// - partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// uploads an image (required) @@ -2823,7 +2875,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2844,7 +2896,7 @@ public async Task UploadFileWithRequired /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2864,17 +2916,23 @@ public async Task UploadFileWithRequired : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/{petId}/uploadImageWithRequiredFile"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); multipartContentLocalVar.Add(new StreamContent(requiredFile)); + { + var streamContentLocalVar = new StreamContent(requiredFile.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile", requiredFile.FileName ?? "requiredFile"); + } if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2888,11 +2946,6 @@ public async Task UploadFileWithRequired "multipart/form-data" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - string[] acceptLocalVars = new string[] { "application/json", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" @@ -3032,5 +3085,282 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } + + partial void FormatUploadFiles(List files, ref long petId); + + /// + /// Validates the request parameters + /// + /// + /// + private void ValidateUploadFiles(List files) + { + if (files == null) + throw new ArgumentNullException(nameof(files)); + } + + /// + /// Processes the server response + /// + /// + /// + /// + private void AfterUploadFilesDefaultImplementation(IUploadFilesApiResponse apiResponseLocalVar, List files, long petId) + { + bool suppressDefaultLog = false; + AfterUploadFiles(ref suppressDefaultLog, apiResponseLocalVar, files, petId); + if (!suppressDefaultLog) + Logger.LogInformation("{0,-9} | {1} | {2}", (apiResponseLocalVar.DownloadedAt - apiResponseLocalVar.RequestedAt).TotalSeconds, apiResponseLocalVar.StatusCode, apiResponseLocalVar.Path); + } + + /// + /// Processes the server response + /// + /// + /// + /// + /// + partial void AfterUploadFiles(ref bool suppressDefaultLog, IUploadFilesApiResponse apiResponseLocalVar, List files, long petId); + + /// + /// Logs exceptions that occur while retrieving the server response + /// + /// + /// + /// + /// + /// + private void OnErrorUploadFilesDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId) + { + bool suppressDefaultLogLocalVar = false; + OnErrorUploadFiles(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, files, petId); + if (!suppressDefaultLogLocalVar) + Logger.LogError(exceptionLocalVar, "An error occurred while sending the request to the server."); + } + + /// + /// A partial method that gives developers a way to provide customized exception handling + /// + /// + /// + /// + /// + /// + /// + partial void OnErrorUploadFiles(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId); + + /// + /// uploads an images + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + try + { + return await UploadFilesAsync(files, petId, cancellationToken).ConfigureAwait(false); + } + catch (Exception) + { + return null; + } + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + UriBuilder uriBuilderLocalVar = new UriBuilder(); + + try + { + ValidateUploadFiles(files); + + FormatUploadFiles(files, ref petId); + + using (HttpRequestMessage httpRequestMessageLocalVar = new HttpRequestMessage()) + { + uriBuilderLocalVar.Host = HttpClient.BaseAddress.Host; + uriBuilderLocalVar.Port = HttpClient.BaseAddress.Port; + uriBuilderLocalVar.Scheme = HttpClient.BaseAddress.Scheme; + uriBuilderLocalVar.Path = HttpClient.BaseAddress.AbsolutePath == "/" + ? "/pet/{petId}/uploadImages" + : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}/uploadImages"); + uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); + + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); + + httpRequestMessageLocalVar.Content = multipartContentLocalVar; + + List> formParameterLocalVars = new List>(); + + foreach (Org.OpenAPITools.Client.FileParameter fileParameterLocalVar in files) + { + var streamContentLocalVar = new StreamContent(fileParameterLocalVar.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "files", fileParameterLocalVar.FileName ?? "files"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); + + List tokenBaseLocalVars = new List(); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; + + OAuthToken oauthTokenLocalVar1 = (OAuthToken) await OauthTokenProvider.GetAsync(cancellation: cancellationToken).ConfigureAwait(false); + + tokenBaseLocalVars.Add(oauthTokenLocalVar1); + + oauthTokenLocalVar1.UseInHeader(httpRequestMessageLocalVar, ""); + + string[] contentTypes = new string[] { + "multipart/form-data" + }; + + string[] acceptLocalVars = new string[] { + "application/json" + }; + + IEnumerable acceptHeaderValuesLocalVar = ClientUtils.SelectHeaderAcceptArray(acceptLocalVars); + + foreach (var acceptLocalVar in acceptHeaderValuesLocalVar) + httpRequestMessageLocalVar.Headers.Accept.Add(acceptLocalVar); + httpRequestMessageLocalVar.Method = new HttpMethod("POST"); + + DateTime requestedAtLocalVar = DateTime.UtcNow; + + using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false)) + { + ILogger apiResponseLoggerLocalVar = LoggerFactory.CreateLogger(); + UploadFilesApiResponse apiResponseLocalVar; + + switch ((int)httpResponseMessageLocalVar.StatusCode) { + default: { + string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync().ConfigureAwait(false); + apiResponseLocalVar = new UploadFilesApiResponse(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/pet/{petId}/uploadImages", requestedAtLocalVar, _jsonSerializerOptions); + + break; + } + } + + AfterUploadFilesDefaultImplementation(apiResponseLocalVar, files, petId); + + Events.ExecuteOnUploadFiles(apiResponseLocalVar); + + if (apiResponseLocalVar.StatusCode == (HttpStatusCode) 429) + foreach(TokenBase tokenBaseLocalVar in tokenBaseLocalVars) + tokenBaseLocalVar.BeginRateLimit(); + + return apiResponseLocalVar; + } + } + } + catch(Exception e) + { + OnErrorUploadFilesDefaultImplementation(e, "/pet/{petId}/uploadImages", uriBuilderLocalVar.Path, files, petId); + Events.ExecuteOnErrorUploadFiles(e); + throw; + } + } + + /// + /// The + /// + public partial class UploadFilesApiResponse : Org.OpenAPITools.Client.ApiResponse, IUploadFilesApiResponse + { + /// + /// The logger + /// + public ILogger Logger { get; } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, string rawContent, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, rawContent, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, System.IO.Stream contentStream, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, contentStream, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + partial void OnCreated(global::System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage); + + /// + /// Returns true if the response is 200 Ok + /// + /// + public bool IsOk => 200 == (int)StatusCode; + + /// + /// Deserializes the response if the response is 200 Ok + /// + /// + public Org.OpenAPITools.Model.ApiResponse Ok() + { + // This logic may be modified with the AsModel.mustache template + return IsOk + ? System.Text.Json.JsonSerializer.Deserialize(RawContent, _jsonSerializerOptions) + : default; + } + + /// + /// Returns true if the response is 200 Ok and the deserialized response is not null + /// + /// + /// + public bool TryOk(out Org.OpenAPITools.Model.ApiResponse result) + { + result = null; + + try + { + result = Ok(); + } catch (Exception e) + { + OnDeserializationErrorDefaultImplementation(e, (HttpStatusCode)200); + } + + return result != null; + } + + private void OnDeserializationErrorDefaultImplementation(Exception exception, HttpStatusCode httpStatusCode) + { + bool suppressDefaultLog = false; + OnDeserializationError(ref suppressDefaultLog, exception, httpStatusCode); + if (!suppressDefaultLog) + Logger.LogError(exception, "An error occurred while deserializing the {code} response.", httpStatusCode); + } + + partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); + } } } diff --git a/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..6150dbcf4774 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,40 @@ +// +/* + * OpenAPI Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.8/OneOf/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net4.8/OneOf/.openapi-generator/FILES index 47a388f55336..ef946be5e2fb 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/OneOf/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net4.8/OneOf/.openapi-generator/FILES @@ -24,6 +24,7 @@ src/Org.OpenAPITools/Client/CookieContainer.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 diff --git a/samples/client/petstore/csharp/generichost/net4.8/OneOf/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net4.8/OneOf/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..5c8e0767f76a --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.8/OneOf/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,40 @@ +// +/* + * fruity + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 0.0.1 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.8/Petstore/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net4.8/Petstore/.openapi-generator/FILES index a6635c9d8351..82501a149e01 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/Petstore/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net4.8/Petstore/.openapi-generator/FILES @@ -138,6 +138,7 @@ src/Org.OpenAPITools/Client/CookieContainer.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/HttpSigningConfiguration.cs src/Org.OpenAPITools/Client/HttpSigningToken.cs diff --git a/samples/client/petstore/csharp/generichost/net4.8/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net4.8/Petstore/api/openapi.yaml index d8106a5755fc..ca451f3fb832 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net4.8/Petstore/api/openapi.yaml @@ -331,6 +331,40 @@ paths: summary: uploads an image tags: - pet + /pet/{petId}/uploadImages: + post: + description: "" + operationId: uploadFiles + parameters: + - description: ID of pet to update + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + multipart/form-data: + schema: + $ref: "#/components/schemas/uploadFiles_request" + required: true + responses: + "200": + content: + application/json: + schema: + $ref: "#/components/schemas/ApiResponse" + description: successful operation + security: + - petstore_auth: + - write:pets + - read:pets + summary: uploads an images + tags: + - pet /store/inventory: get: description: Returns a map of status codes to quantities @@ -2924,6 +2958,16 @@ components: format: binary type: string type: object + uploadFiles_request: + properties: + files: + items: + format: binary + type: string + type: array + required: + - files + type: object testEnumParameters_request: properties: enum_form_string_array: diff --git a/samples/client/petstore/csharp/generichost/net4.8/Petstore/docs/apis/PetApi.md b/samples/client/petstore/csharp/generichost/net4.8/Petstore/docs/apis/PetApi.md index 2826ea00f728..b42ee516b313 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/Petstore/docs/apis/PetApi.md +++ b/samples/client/petstore/csharp/generichost/net4.8/Petstore/docs/apis/PetApi.md @@ -13,6 +13,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* | [**UpdatePetWithForm**](PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data | | [**UploadFile**](PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image | | [**UploadFileWithRequiredFile**](PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) | +| [**UploadFiles**](PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images | # **AddPet** @@ -341,3 +342,38 @@ uploads an image (required) [[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + +# **UploadFiles** +> ApiResponse UploadFiles (List files, long petId) + +uploads an images + + +### Parameters + +| Name | Type | Description | Notes | +|------|------|-------------|-------| +| **files** | **List<System.IO.Stream>** | | | +| **petId** | **long** | ID of pet to update | | + +### Return type + +[**ApiResponse**](ApiResponse.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: multipart/form-data + - **Accept**: application/json + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | + +[[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + diff --git a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs index ce85f85778ef..6420b47bc8b4 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs @@ -196,7 +196,7 @@ public async Task TestEndpointParametersAsyncTest() string patternWithoutDelimiter = default; byte[] varByte = default; double varDouble = default; - Client.Option binary = default; + Client.Option binary = default; Client.Option callback = default; Client.Option date = default; Client.Option dateTime = default; diff --git a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 215e88093797..e9b05337bb59 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools.Test/Api/PetApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools.Test/Api/PetApiTests.cs @@ -137,7 +137,7 @@ public async Task UploadFileAsyncTest() { long petId = default; Client.Option additionalMetadata = default; - Client.Option file = default; + Client.Option file = default; var response = await _instance.UploadFileAsync(petId, additionalMetadata, file); var model = response.Ok(); Assert.IsType(model); @@ -150,11 +150,24 @@ public async Task UploadFileAsyncTest() public async Task UploadFileWithRequiredFileAsyncTest() { long petId = default; - System.IO.Stream requiredFile = default; + Org.OpenAPITools.Client.FileParameter requiredFile = default; Client.Option additionalMetadata = default; var response = await _instance.UploadFileWithRequiredFileAsync(petId, requiredFile, additionalMetadata); var model = response.Ok(); Assert.IsType(model); } + + /// + /// Test UploadFiles + /// + [Fact (Skip = "not implemented")] + public async Task UploadFilesAsyncTest() + { + List files = default; + long petId = default; + var response = await _instance.UploadFilesAsync(files, petId); + var model = response.Ok(); + Assert.IsType(model); + } } } diff --git a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs index 1bbf43279f7c..24a69b84527e 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs @@ -763,27 +763,19 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = new HttpMethod("POST"); DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Api/FakeApi.cs b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Api/FakeApi.cs index feec543b8c1f..a3a842305a6f 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Api/FakeApi.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Api/FakeApi.cs @@ -330,7 +330,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <> - Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -354,7 +354,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <> - Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// To test enum parameters @@ -4071,7 +4071,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); + partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); /// /// Validates the request parameters @@ -4083,7 +4083,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) + private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) { if (patternWithoutDelimiter == null) throw new ArgumentNullException(nameof(patternWithoutDelimiter)); @@ -4122,7 +4122,7 @@ private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte /// /// /// - private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLog = false; AfterTestEndpointParameters(ref suppressDefaultLog, apiResponseLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4149,7 +4149,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Logs exceptions that occur while retrieving the server response @@ -4171,7 +4171,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLogLocalVar = false; OnErrorTestEndpointParameters(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4200,7 +4200,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// /// /// - partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -4221,7 +4221,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -4253,7 +4253,7 @@ public async Task TestEndpointParametersOrDe /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -4272,14 +4272,8 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("number", ClientUtils.ParameterToString(number))); formParameterLocalVars.Add(new KeyValuePair("pattern_without_delimiter", ClientUtils.ParameterToString(patternWithoutDelimiter))); @@ -4289,7 +4283,7 @@ public async Task TestEndpointParametersAsyn formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.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."); if (callback.IsSet) formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); @@ -4318,6 +4312,9 @@ public async Task TestEndpointParametersAsyn if (varString.IsSet) formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4331,11 +4328,6 @@ public async Task TestEndpointParametersAsyn "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = new HttpMethod("POST"); DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -4628,29 +4620,23 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (enumFormString.IsSet) + if (enumFormString.IsSet) formParameterLocalVars.Add(new KeyValuePair("enum_form_string", ClientUtils.ParameterToString(enumFormString.Value))); if (enumFormStringArray.IsSet) formParameterLocalVars.Add(new KeyValuePair("enum_form_string_array", ClientUtils.ParameterToString(enumFormStringArray.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = new HttpMethod("GET"); DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -5536,29 +5522,21 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("param", ClientUtils.ParameterToString(param))); formParameterLocalVars.Add(new KeyValuePair("param2", ClientUtils.ParameterToString(param2))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = new HttpMethod("GET"); DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Api/PetApi.cs b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Api/PetApi.cs index 7fe162b51bfb..9d04b53a95c5 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Api/PetApi.cs +++ b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Api/PetApi.cs @@ -216,7 +216,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image @@ -229,7 +229,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -243,7 +243,7 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -256,7 +256,32 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); } /// @@ -415,6 +440,18 @@ public interface IUploadFileWithRequiredFileApiResponse : Org.OpenAPITools.Clien bool IsOk { get; } } + /// + /// The + /// + public interface IUploadFilesApiResponse : Org.OpenAPITools.Client.IApiResponse, IOk + { + /// + /// Returns true if the response is 200 Ok + /// + /// + bool IsOk { get; } + } + /// /// Represents a collection of functions to interact with the API endpoints /// @@ -599,6 +636,26 @@ internal void ExecuteOnErrorUploadFileWithRequiredFile(Exception exception) { OnErrorUploadFileWithRequiredFile?.Invoke(this, new ExceptionEventArgs(exception)); } + + /// + /// The event raised after the server response + /// + public event EventHandler OnUploadFiles; + + /// + /// The event raised after an error querying the server + /// + public event EventHandler OnErrorUploadFiles; + + internal void ExecuteOnUploadFiles(PetApi.UploadFilesApiResponse apiResponse) + { + OnUploadFiles?.Invoke(this, new ApiResponseEventArgs(apiResponse)); + } + + internal void ExecuteOnErrorUploadFiles(Exception exception) + { + OnErrorUploadFiles?.Invoke(this, new ExceptionEventArgs(exception)); + } } /// @@ -2326,18 +2383,17 @@ public async Task UpdatePetWithFormAsync(long pet : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (name.IsSet) + if (name.IsSet) formParameterLocalVars.Add(new KeyValuePair("name", ClientUtils.ParameterToString(name.Value))); if (status.IsSet) formParameterLocalVars.Add(new KeyValuePair("status", ClientUtils.ParameterToString(status.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2351,11 +2407,6 @@ public async Task UpdatePetWithFormAsync(long pet "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = new HttpMethod("POST"); DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -2455,7 +2506,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); + partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); /// /// Validates the request parameters @@ -2463,7 +2514,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFile(Option additionalMetadata, Option file) + private void ValidateUploadFile(Option additionalMetadata, Option file) { if (additionalMetadata.IsSet && additionalMetadata.Value == null) throw new ArgumentNullException(nameof(additionalMetadata)); @@ -2479,7 +2530,7 @@ private void ValidateUploadFile(Option additionalMetadata, Option /// /// - private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) + private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLog = false; AfterUploadFile(ref suppressDefaultLog, apiResponseLocalVar, petId, additionalMetadata, file); @@ -2495,7 +2546,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); + partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); /// /// Logs exceptions that occur while retrieving the server response @@ -2506,7 +2557,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) + private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, additionalMetadata, file); @@ -2524,7 +2575,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// /// /// - partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); + partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); /// /// uploads an image @@ -2534,7 +2585,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2555,7 +2606,7 @@ public async Task UploadFileOrDefaultAsync(long petId, O /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2575,17 +2626,23 @@ public async Task UploadFileAsync(long petId, Option> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (additionalMetadata.IsSet) + if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); if (file.IsSet) - multipartContentLocalVar.Add(new StreamContent(file.Value)); + { + var streamContentLocalVar = new StreamContent(file.Value.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "file", file.Value.FileName ?? "file"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2600,11 +2657,6 @@ public async Task UploadFileAsync(long petId, Option additionalMetadata); + partial void FormatUploadFileWithRequiredFile(ref long petId, ref Org.OpenAPITools.Client.FileParameter requiredFile, ref Option additionalMetadata); /// /// Validates the request parameters @@ -2752,7 +2804,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, Option additionalMetadata) + private void ValidateUploadFileWithRequiredFile(Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { if (requiredFile == null) throw new ArgumentNullException(nameof(requiredFile)); @@ -2768,7 +2820,7 @@ private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, O /// /// /// - private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLog = false; AfterUploadFileWithRequiredFile(ref suppressDefaultLog, apiResponseLocalVar, petId, requiredFile, additionalMetadata); @@ -2784,7 +2836,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// Logs exceptions that occur while retrieving the server response @@ -2795,7 +2847,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFileWithRequiredFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, requiredFile, additionalMetadata); @@ -2813,7 +2865,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// /// /// - partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// uploads an image (required) @@ -2823,7 +2875,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2844,7 +2896,7 @@ public async Task UploadFileWithRequired /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2864,17 +2916,23 @@ public async Task UploadFileWithRequired : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/{petId}/uploadImageWithRequiredFile"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); multipartContentLocalVar.Add(new StreamContent(requiredFile)); + { + var streamContentLocalVar = new StreamContent(requiredFile.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile", requiredFile.FileName ?? "requiredFile"); + } if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2888,11 +2946,6 @@ public async Task UploadFileWithRequired "multipart/form-data" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - string[] acceptLocalVars = new string[] { "application/json", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" @@ -3032,5 +3085,282 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } + + partial void FormatUploadFiles(List files, ref long petId); + + /// + /// Validates the request parameters + /// + /// + /// + private void ValidateUploadFiles(List files) + { + if (files == null) + throw new ArgumentNullException(nameof(files)); + } + + /// + /// Processes the server response + /// + /// + /// + /// + private void AfterUploadFilesDefaultImplementation(IUploadFilesApiResponse apiResponseLocalVar, List files, long petId) + { + bool suppressDefaultLog = false; + AfterUploadFiles(ref suppressDefaultLog, apiResponseLocalVar, files, petId); + if (!suppressDefaultLog) + Logger.LogInformation("{0,-9} | {1} | {2}", (apiResponseLocalVar.DownloadedAt - apiResponseLocalVar.RequestedAt).TotalSeconds, apiResponseLocalVar.StatusCode, apiResponseLocalVar.Path); + } + + /// + /// Processes the server response + /// + /// + /// + /// + /// + partial void AfterUploadFiles(ref bool suppressDefaultLog, IUploadFilesApiResponse apiResponseLocalVar, List files, long petId); + + /// + /// Logs exceptions that occur while retrieving the server response + /// + /// + /// + /// + /// + /// + private void OnErrorUploadFilesDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId) + { + bool suppressDefaultLogLocalVar = false; + OnErrorUploadFiles(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, files, petId); + if (!suppressDefaultLogLocalVar) + Logger.LogError(exceptionLocalVar, "An error occurred while sending the request to the server."); + } + + /// + /// A partial method that gives developers a way to provide customized exception handling + /// + /// + /// + /// + /// + /// + /// + partial void OnErrorUploadFiles(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId); + + /// + /// uploads an images + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + try + { + return await UploadFilesAsync(files, petId, cancellationToken).ConfigureAwait(false); + } + catch (Exception) + { + return null; + } + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + UriBuilder uriBuilderLocalVar = new UriBuilder(); + + try + { + ValidateUploadFiles(files); + + FormatUploadFiles(files, ref petId); + + using (HttpRequestMessage httpRequestMessageLocalVar = new HttpRequestMessage()) + { + uriBuilderLocalVar.Host = HttpClient.BaseAddress.Host; + uriBuilderLocalVar.Port = HttpClient.BaseAddress.Port; + uriBuilderLocalVar.Scheme = HttpClient.BaseAddress.Scheme; + uriBuilderLocalVar.Path = HttpClient.BaseAddress.AbsolutePath == "/" + ? "/pet/{petId}/uploadImages" + : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}/uploadImages"); + uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); + + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); + + httpRequestMessageLocalVar.Content = multipartContentLocalVar; + + List> formParameterLocalVars = new List>(); + + foreach (Org.OpenAPITools.Client.FileParameter fileParameterLocalVar in files) + { + var streamContentLocalVar = new StreamContent(fileParameterLocalVar.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "files", fileParameterLocalVar.FileName ?? "files"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); + + List tokenBaseLocalVars = new List(); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; + + OAuthToken oauthTokenLocalVar1 = (OAuthToken) await OauthTokenProvider.GetAsync(cancellation: cancellationToken).ConfigureAwait(false); + + tokenBaseLocalVars.Add(oauthTokenLocalVar1); + + oauthTokenLocalVar1.UseInHeader(httpRequestMessageLocalVar, ""); + + string[] contentTypes = new string[] { + "multipart/form-data" + }; + + string[] acceptLocalVars = new string[] { + "application/json" + }; + + IEnumerable acceptHeaderValuesLocalVar = ClientUtils.SelectHeaderAcceptArray(acceptLocalVars); + + foreach (var acceptLocalVar in acceptHeaderValuesLocalVar) + httpRequestMessageLocalVar.Headers.Accept.Add(acceptLocalVar); + httpRequestMessageLocalVar.Method = new HttpMethod("POST"); + + DateTime requestedAtLocalVar = DateTime.UtcNow; + + using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false)) + { + ILogger apiResponseLoggerLocalVar = LoggerFactory.CreateLogger(); + UploadFilesApiResponse apiResponseLocalVar; + + switch ((int)httpResponseMessageLocalVar.StatusCode) { + default: { + string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync().ConfigureAwait(false); + apiResponseLocalVar = new UploadFilesApiResponse(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/pet/{petId}/uploadImages", requestedAtLocalVar, _jsonSerializerOptions); + + break; + } + } + + AfterUploadFilesDefaultImplementation(apiResponseLocalVar, files, petId); + + Events.ExecuteOnUploadFiles(apiResponseLocalVar); + + if (apiResponseLocalVar.StatusCode == (HttpStatusCode) 429) + foreach(TokenBase tokenBaseLocalVar in tokenBaseLocalVars) + tokenBaseLocalVar.BeginRateLimit(); + + return apiResponseLocalVar; + } + } + } + catch(Exception e) + { + OnErrorUploadFilesDefaultImplementation(e, "/pet/{petId}/uploadImages", uriBuilderLocalVar.Path, files, petId); + Events.ExecuteOnErrorUploadFiles(e); + throw; + } + } + + /// + /// The + /// + public partial class UploadFilesApiResponse : Org.OpenAPITools.Client.ApiResponse, IUploadFilesApiResponse + { + /// + /// The logger + /// + public ILogger Logger { get; } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, string rawContent, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, rawContent, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, System.IO.Stream contentStream, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, contentStream, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + partial void OnCreated(global::System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage); + + /// + /// Returns true if the response is 200 Ok + /// + /// + public bool IsOk => 200 == (int)StatusCode; + + /// + /// Deserializes the response if the response is 200 Ok + /// + /// + public Org.OpenAPITools.Model.ApiResponse Ok() + { + // This logic may be modified with the AsModel.mustache template + return IsOk + ? System.Text.Json.JsonSerializer.Deserialize(RawContent, _jsonSerializerOptions) + : default; + } + + /// + /// Returns true if the response is 200 Ok and the deserialized response is not null + /// + /// + /// + public bool TryOk(out Org.OpenAPITools.Model.ApiResponse result) + { + result = null; + + try + { + result = Ok(); + } catch (Exception e) + { + OnDeserializationErrorDefaultImplementation(e, (HttpStatusCode)200); + } + + return result != null; + } + + private void OnDeserializationErrorDefaultImplementation(Exception exception, HttpStatusCode httpStatusCode) + { + bool suppressDefaultLog = false; + OnDeserializationError(ref suppressDefaultLog, exception, httpStatusCode); + if (!suppressDefaultLog) + Logger.LogError(exception, "An error occurred while deserializing the {code} response.", httpStatusCode); + } + + partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); + } } } diff --git a/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..6150dbcf4774 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,40 @@ +// +/* + * OpenAPI Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net4.8/UseDateTimeForDate/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net4.8/UseDateTimeForDate/.openapi-generator/FILES index 5abbcf46f35c..e28da391730f 100644 --- a/samples/client/petstore/csharp/generichost/net4.8/UseDateTimeForDate/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net4.8/UseDateTimeForDate/.openapi-generator/FILES @@ -21,6 +21,7 @@ src/Org.OpenAPITools/Client/CookieContainer.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 diff --git a/samples/client/petstore/csharp/generichost/net4.8/UseDateTimeForDate/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net4.8/UseDateTimeForDate/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..253a70bc8053 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net4.8/UseDateTimeForDate/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,40 @@ +// +/* + * OpenAPI Dates + * + * Thic spec contains endpoints with dates in different formats + * + * The version of the OpenAPI document: 1.0.0 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/AllOf/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net8/AllOf/.openapi-generator/FILES index b9ab612bd8b5..46a8286dea29 100644 --- a/samples/client/petstore/csharp/generichost/net8/AllOf/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net8/AllOf/.openapi-generator/FILES @@ -25,6 +25,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 diff --git a/samples/client/petstore/csharp/generichost/net8/AllOf/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net8/AllOf/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..1913a3a0f2d9 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/AllOf/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,42 @@ +// +/* + * Example + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +#nullable enable + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string? FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string? fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/AnyOf/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net8/AnyOf/.openapi-generator/FILES index dc42a5d47091..072cc8408121 100644 --- a/samples/client/petstore/csharp/generichost/net8/AnyOf/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net8/AnyOf/.openapi-generator/FILES @@ -25,6 +25,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 diff --git a/samples/client/petstore/csharp/generichost/net8/AnyOf/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net8/AnyOf/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..e629f4afdaec --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/AnyOf/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,42 @@ +// +/* + * fruity + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 0.0.1 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +#nullable enable + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string? FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string? fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/AnyOfNoCompare/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net8/AnyOfNoCompare/.openapi-generator/FILES index dc42a5d47091..072cc8408121 100644 --- a/samples/client/petstore/csharp/generichost/net8/AnyOfNoCompare/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net8/AnyOfNoCompare/.openapi-generator/FILES @@ -25,6 +25,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 diff --git a/samples/client/petstore/csharp/generichost/net8/AnyOfNoCompare/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net8/AnyOfNoCompare/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..e629f4afdaec --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/AnyOfNoCompare/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,42 @@ +// +/* + * fruity + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 0.0.1 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +#nullable enable + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string? FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string? fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/FormModels/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net8/FormModels/.openapi-generator/FILES index a9823b3075fd..737d53400248 100644 --- a/samples/client/petstore/csharp/generichost/net8/FormModels/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/.openapi-generator/FILES @@ -165,6 +165,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/HttpSigningConfiguration.cs src/Org.OpenAPITools/Client/HttpSigningToken.cs diff --git a/samples/client/petstore/csharp/generichost/net8/FormModels/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net8/FormModels/api/openapi.yaml index a9ab8dd51c13..7017affc0b9c 100644 --- a/samples/client/petstore/csharp/generichost/net8/FormModels/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/api/openapi.yaml @@ -326,6 +326,40 @@ paths: summary: uploads an image tags: - pet + /pet/{petId}/uploadImages: + post: + description: "" + operationId: uploadFiles + parameters: + - description: ID of pet to update + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + multipart/form-data: + schema: + $ref: "#/components/schemas/uploadFiles_request" + required: true + responses: + "200": + content: + application/json: + schema: + $ref: "#/components/schemas/ApiResponse" + description: successful operation + security: + - petstore_auth: + - write:pets + - read:pets + summary: uploads an images + tags: + - pet /store/inventory: get: description: Returns a map of status codes to quantities @@ -2748,6 +2782,16 @@ components: format: binary type: string type: object + uploadFiles_request: + properties: + files: + items: + format: binary + type: string + type: array + required: + - files + type: object testEnumParameters_request_enum_form_string_array_inner: default: $ enum: diff --git a/samples/client/petstore/csharp/generichost/net8/FormModels/docs/apis/PetApi.md b/samples/client/petstore/csharp/generichost/net8/FormModels/docs/apis/PetApi.md index e32c1e31e089..59d4ef8e6df0 100644 --- a/samples/client/petstore/csharp/generichost/net8/FormModels/docs/apis/PetApi.md +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/docs/apis/PetApi.md @@ -13,6 +13,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* | [**UpdatePetWithForm**](PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data | | [**UploadFile**](PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image | | [**UploadFileWithRequiredFile**](PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) | +| [**UploadFiles**](PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images | # **AddPet** @@ -341,3 +342,38 @@ uploads an image (required) [[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + +# **UploadFiles** +> ApiResponse UploadFiles (List files, long petId) + +uploads an images + + +### Parameters + +| Name | Type | Description | Notes | +|------|------|-------------|-------| +| **files** | **List<System.IO.Stream>** | | | +| **petId** | **long** | ID of pet to update | | + +### Return type + +[**ApiResponse**](ApiResponse.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: multipart/form-data + - **Accept**: application/json + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | + +[[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + diff --git a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs index 495d785314c5..1924842cdbef 100644 --- a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs @@ -196,7 +196,7 @@ public async Task TestEndpointParametersAsyncTest() string patternWithoutDelimiter = default; byte[] varByte = default; double varDouble = default; - Client.Option binary = default; + Client.Option binary = default; Client.Option callback = default; Client.Option date = default; Client.Option dateTime = default; diff --git a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 1f1d7f6c4576..a4aa8f3e245d 100644 --- a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools.Test/Api/PetApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools.Test/Api/PetApiTests.cs @@ -137,7 +137,7 @@ public async Task UploadFileAsyncTest() { long petId = default; Client.Option additionalMetadata = default; - Client.Option file = default; + Client.Option file = default; var response = await _instance.UploadFileAsync(petId, additionalMetadata, file); var model = response.Ok(); Assert.IsType(model); @@ -150,11 +150,24 @@ public async Task UploadFileAsyncTest() public async Task UploadFileWithRequiredFileAsyncTest() { long petId = default; - System.IO.Stream requiredFile = default; + Org.OpenAPITools.Client.FileParameter requiredFile = default; Client.Option additionalMetadata = default; var response = await _instance.UploadFileWithRequiredFileAsync(petId, requiredFile, additionalMetadata); var model = response.Ok(); Assert.IsType(model); } + + /// + /// Test UploadFiles + /// + [Fact (Skip = "not implemented")] + public async Task UploadFilesAsyncTest() + { + List files = default; + long petId = default; + var response = await _instance.UploadFilesAsync(files, petId); + var model = response.Ok(); + Assert.IsType(model); + } } } diff --git a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Api/DefaultApi.cs index 3c26a27185e6..44d52e7e1090 100644 --- a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Api/DefaultApi.cs +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Api/DefaultApi.cs @@ -764,27 +764,19 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Api/FakeApi.cs b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Api/FakeApi.cs index 2a332dbf1eb9..0070617289e6 100644 --- a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Api/FakeApi.cs +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Api/FakeApi.cs @@ -330,7 +330,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <> - Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -354,7 +354,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <> - Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// To test enum parameters @@ -4080,7 +4080,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); + partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); /// /// Validates the request parameters @@ -4092,7 +4092,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) + private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) { if (patternWithoutDelimiter == null) throw new ArgumentNullException(nameof(patternWithoutDelimiter)); @@ -4131,7 +4131,7 @@ private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte /// /// /// - private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLog = false; AfterTestEndpointParameters(ref suppressDefaultLog, apiResponseLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4158,7 +4158,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Logs exceptions that occur while retrieving the server response @@ -4180,7 +4180,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLogLocalVar = false; OnErrorTestEndpointParameters(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4209,7 +4209,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// /// /// - partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -4230,7 +4230,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -4262,7 +4262,7 @@ public async Task TestEndpointParametersOrDe /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -4281,14 +4281,8 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("number", ClientUtils.ParameterToString(number))); formParameterLocalVars.Add(new KeyValuePair("pattern_without_delimiter", ClientUtils.ParameterToString(patternWithoutDelimiter))); @@ -4298,7 +4292,7 @@ public async Task TestEndpointParametersAsyn formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.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."); if (callback.IsSet) formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); @@ -4327,6 +4321,9 @@ public async Task TestEndpointParametersAsyn if (varString.IsSet) formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4340,11 +4337,6 @@ public async Task TestEndpointParametersAsyn "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -4625,29 +4617,23 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (enumFormString.IsSet) + if (enumFormString.IsSet) formParameterLocalVars.Add(new KeyValuePair("enum_form_string", ClientUtils.ParameterToString(enumFormString.Value))); if (enumFormStringArray.IsSet) formParameterLocalVars.Add(new KeyValuePair("enum_form_string_array", ClientUtils.ParameterToString(enumFormStringArray.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Get; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -5534,29 +5520,21 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("param", ClientUtils.ParameterToString(param))); formParameterLocalVars.Add(new KeyValuePair("param2", ClientUtils.ParameterToString(param2))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Get; DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Api/PetApi.cs b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Api/PetApi.cs index d07d16c30828..fd403446d9a6 100644 --- a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Api/PetApi.cs +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Api/PetApi.cs @@ -216,7 +216,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image @@ -229,7 +229,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -243,7 +243,7 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -256,7 +256,32 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); } /// @@ -415,6 +440,18 @@ public interface IUploadFileWithRequiredFileApiResponse : Org.OpenAPITools.Clien bool IsOk { get; } } + /// + /// The + /// + public interface IUploadFilesApiResponse : Org.OpenAPITools.Client.IApiResponse, IOk + { + /// + /// Returns true if the response is 200 Ok + /// + /// + bool IsOk { get; } + } + /// /// Represents a collection of functions to interact with the API endpoints /// @@ -599,6 +636,26 @@ internal void ExecuteOnErrorUploadFileWithRequiredFile(Exception exception) { OnErrorUploadFileWithRequiredFile?.Invoke(this, new ExceptionEventArgs(exception)); } + + /// + /// The event raised after the server response + /// + public event EventHandler OnUploadFiles; + + /// + /// The event raised after an error querying the server + /// + public event EventHandler OnErrorUploadFiles; + + internal void ExecuteOnUploadFiles(PetApi.UploadFilesApiResponse apiResponse) + { + OnUploadFiles?.Invoke(this, new ApiResponseEventArgs(apiResponse)); + } + + internal void ExecuteOnErrorUploadFiles(Exception exception) + { + OnErrorUploadFiles?.Invoke(this, new ExceptionEventArgs(exception)); + } } /// @@ -2330,18 +2387,17 @@ public async Task UpdatePetWithFormAsync(long pet : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (name.IsSet) + if (name.IsSet) formParameterLocalVars.Add(new KeyValuePair("name", ClientUtils.ParameterToString(name.Value))); if (status.IsSet) formParameterLocalVars.Add(new KeyValuePair("status", ClientUtils.ParameterToString(status.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2355,11 +2411,6 @@ public async Task UpdatePetWithFormAsync(long pet "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -2459,7 +2510,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); + partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); /// /// Validates the request parameters @@ -2467,7 +2518,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFile(Option additionalMetadata, Option file) + private void ValidateUploadFile(Option additionalMetadata, Option file) { if (additionalMetadata.IsSet && additionalMetadata.Value == null) throw new ArgumentNullException(nameof(additionalMetadata)); @@ -2483,7 +2534,7 @@ private void ValidateUploadFile(Option additionalMetadata, Option /// /// - private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) + private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLog = false; AfterUploadFile(ref suppressDefaultLog, apiResponseLocalVar, petId, additionalMetadata, file); @@ -2499,7 +2550,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); + partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); /// /// Logs exceptions that occur while retrieving the server response @@ -2510,7 +2561,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) + private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, additionalMetadata, file); @@ -2528,7 +2579,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// /// /// - partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); + partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); /// /// uploads an image @@ -2538,7 +2589,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2559,7 +2610,7 @@ public async Task UploadFileOrDefaultAsync(long petId, O /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2579,17 +2630,23 @@ public async Task UploadFileAsync(long petId, Option> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (additionalMetadata.IsSet) + if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); if (file.IsSet) - multipartContentLocalVar.Add(new StreamContent(file.Value)); + { + var streamContentLocalVar = new StreamContent(file.Value.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "file", file.Value.FileName ?? "file"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2604,11 +2661,6 @@ public async Task UploadFileAsync(long petId, Option additionalMetadata); + partial void FormatUploadFileWithRequiredFile(ref long petId, ref Org.OpenAPITools.Client.FileParameter requiredFile, ref Option additionalMetadata); /// /// Validates the request parameters @@ -2757,7 +2809,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, Option additionalMetadata) + private void ValidateUploadFileWithRequiredFile(Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { if (requiredFile == null) throw new ArgumentNullException(nameof(requiredFile)); @@ -2773,7 +2825,7 @@ private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, O /// /// /// - private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLog = false; AfterUploadFileWithRequiredFile(ref suppressDefaultLog, apiResponseLocalVar, petId, requiredFile, additionalMetadata); @@ -2789,7 +2841,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// Logs exceptions that occur while retrieving the server response @@ -2800,7 +2852,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFileWithRequiredFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, requiredFile, additionalMetadata); @@ -2818,7 +2870,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// /// /// - partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// uploads an image (required) @@ -2828,7 +2880,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2849,7 +2901,7 @@ public async Task UploadFileWithRequired /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2869,17 +2921,23 @@ public async Task UploadFileWithRequired : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/{petId}/uploadImageWithRequiredFile"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); multipartContentLocalVar.Add(new StreamContent(requiredFile)); + { + var streamContentLocalVar = new StreamContent(requiredFile.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile", requiredFile.FileName ?? "requiredFile"); + } if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2893,11 +2951,6 @@ public async Task UploadFileWithRequired "multipart/form-data" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - string[] acceptLocalVars = new string[] { "application/json", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" @@ -3038,5 +3091,283 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } + + partial void FormatUploadFiles(List files, ref long petId); + + /// + /// Validates the request parameters + /// + /// + /// + private void ValidateUploadFiles(List files) + { + if (files == null) + throw new ArgumentNullException(nameof(files)); + } + + /// + /// Processes the server response + /// + /// + /// + /// + private void AfterUploadFilesDefaultImplementation(IUploadFilesApiResponse apiResponseLocalVar, List files, long petId) + { + bool suppressDefaultLog = false; + AfterUploadFiles(ref suppressDefaultLog, apiResponseLocalVar, files, petId); + if (!suppressDefaultLog) + Logger.LogInformation("{0,-9} | {1} | {2}", (apiResponseLocalVar.DownloadedAt - apiResponseLocalVar.RequestedAt).TotalSeconds, apiResponseLocalVar.StatusCode, apiResponseLocalVar.Path); + } + + /// + /// Processes the server response + /// + /// + /// + /// + /// + partial void AfterUploadFiles(ref bool suppressDefaultLog, IUploadFilesApiResponse apiResponseLocalVar, List files, long petId); + + /// + /// Logs exceptions that occur while retrieving the server response + /// + /// + /// + /// + /// + /// + private void OnErrorUploadFilesDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId) + { + bool suppressDefaultLogLocalVar = false; + OnErrorUploadFiles(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, files, petId); + if (!suppressDefaultLogLocalVar) + Logger.LogError(exceptionLocalVar, "An error occurred while sending the request to the server."); + } + + /// + /// A partial method that gives developers a way to provide customized exception handling + /// + /// + /// + /// + /// + /// + /// + partial void OnErrorUploadFiles(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId); + + /// + /// uploads an images + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + try + { + return await UploadFilesAsync(files, petId, cancellationToken).ConfigureAwait(false); + } + catch (Exception) + { + return null; + } + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + UriBuilder uriBuilderLocalVar = new UriBuilder(); + + try + { + ValidateUploadFiles(files); + + FormatUploadFiles(files, ref petId); + + using (HttpRequestMessage httpRequestMessageLocalVar = new HttpRequestMessage()) + { + uriBuilderLocalVar.Host = HttpClient.BaseAddress.Host; + uriBuilderLocalVar.Port = HttpClient.BaseAddress.Port; + uriBuilderLocalVar.Scheme = HttpClient.BaseAddress.Scheme; + uriBuilderLocalVar.Path = HttpClient.BaseAddress.AbsolutePath == "/" + ? "/pet/{petId}/uploadImages" + : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}/uploadImages"); + uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); + + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); + + httpRequestMessageLocalVar.Content = multipartContentLocalVar; + + List> formParameterLocalVars = new List>(); + + foreach (Org.OpenAPITools.Client.FileParameter fileParameterLocalVar in files) + { + var streamContentLocalVar = new StreamContent(fileParameterLocalVar.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "files", fileParameterLocalVar.FileName ?? "files"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); + + List tokenBaseLocalVars = new List(); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; + + OAuthToken oauthTokenLocalVar1 = (OAuthToken) await OauthTokenProvider.GetAsync(cancellation: cancellationToken).ConfigureAwait(false); + + tokenBaseLocalVars.Add(oauthTokenLocalVar1); + + oauthTokenLocalVar1.UseInHeader(httpRequestMessageLocalVar, ""); + + string[] contentTypes = new string[] { + "multipart/form-data" + }; + + string[] acceptLocalVars = new string[] { + "application/json" + }; + + IEnumerable acceptHeaderValuesLocalVar = ClientUtils.SelectHeaderAcceptArray(acceptLocalVars); + + foreach (var acceptLocalVar in acceptHeaderValuesLocalVar) + httpRequestMessageLocalVar.Headers.Accept.Add(acceptLocalVar); + + httpRequestMessageLocalVar.Method = HttpMethod.Post; + + DateTime requestedAtLocalVar = DateTime.UtcNow; + + using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false)) + { + ILogger apiResponseLoggerLocalVar = LoggerFactory.CreateLogger(); + UploadFilesApiResponse apiResponseLocalVar; + + switch ((int)httpResponseMessageLocalVar.StatusCode) { + default: { + string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + apiResponseLocalVar = new(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/pet/{petId}/uploadImages", requestedAtLocalVar, _jsonSerializerOptions); + + break; + } + } + + AfterUploadFilesDefaultImplementation(apiResponseLocalVar, files, petId); + + Events.ExecuteOnUploadFiles(apiResponseLocalVar); + + if (apiResponseLocalVar.StatusCode == (HttpStatusCode) 429) + foreach(TokenBase tokenBaseLocalVar in tokenBaseLocalVars) + tokenBaseLocalVar.BeginRateLimit(); + + return apiResponseLocalVar; + } + } + } + catch(Exception e) + { + OnErrorUploadFilesDefaultImplementation(e, "/pet/{petId}/uploadImages", uriBuilderLocalVar.Path, files, petId); + Events.ExecuteOnErrorUploadFiles(e); + throw; + } + } + + /// + /// The + /// + public partial class UploadFilesApiResponse : Org.OpenAPITools.Client.ApiResponse, IUploadFilesApiResponse + { + /// + /// The logger + /// + public ILogger Logger { get; } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, string rawContent, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, rawContent, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, System.IO.Stream contentStream, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, contentStream, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + partial void OnCreated(global::System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage); + + /// + /// Returns true if the response is 200 Ok + /// + /// + public bool IsOk => 200 == (int)StatusCode; + + /// + /// Deserializes the response if the response is 200 Ok + /// + /// + public Org.OpenAPITools.Model.ApiResponse Ok() + { + // This logic may be modified with the AsModel.mustache template + return IsOk + ? System.Text.Json.JsonSerializer.Deserialize(RawContent, _jsonSerializerOptions) + : null; + } + + /// + /// Returns true if the response is 200 Ok and the deserialized response is not null + /// + /// + /// + public bool TryOk([NotNullWhen(true)]out Org.OpenAPITools.Model.ApiResponse result) + { + result = null; + + try + { + result = Ok(); + } catch (Exception e) + { + OnDeserializationErrorDefaultImplementation(e, (HttpStatusCode)200); + } + + return result != null; + } + + private void OnDeserializationErrorDefaultImplementation(Exception exception, HttpStatusCode httpStatusCode) + { + bool suppressDefaultLog = false; + OnDeserializationError(ref suppressDefaultLog, exception, httpStatusCode); + if (!suppressDefaultLog) + Logger.LogError(exception, "An error occurred while deserializing the {code} response.", httpStatusCode); + } + + partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); + } } } diff --git a/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..6150dbcf4774 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,40 @@ +// +/* + * OpenAPI Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/ManualPetstoreTests/OpenAPIClient-generichost-manual-tests/MultipartContentTypeTests.cs b/samples/client/petstore/csharp/generichost/net8/ManualPetstoreTests/OpenAPIClient-generichost-manual-tests/MultipartContentTypeTests.cs new file mode 100644 index 000000000000..11b7f610913a --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/ManualPetstoreTests/OpenAPIClient-generichost-manual-tests/MultipartContentTypeTests.cs @@ -0,0 +1,302 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Org.OpenAPITools.Api; +using Org.OpenAPITools.Client; +using Org.OpenAPITools.Extensions; +using System.Net; +using System.Net.Http.Headers; + +namespace OpenAPIClient_generichost_manual_tests +{ + /// + /// Tests that multipart/form-data requests preserve the boundary in their Content-Type header. + /// Regression test for https://github.com/OpenAPITools/openapi-generator/issues/21384 + /// + [TestClass] + public sealed class MultipartContentTypeTests + { + /// + /// Captures the outgoing HttpRequestMessage and returns a minimal fake response, + /// so tests can inspect what the generated client actually sends without a real server. + /// + private sealed class CapturingHandler : HttpMessageHandler + { + public HttpRequestMessage? CapturedRequest { get; private set; } + public string? CapturedContentType { get; private set; } + public string? CapturedBody { get; private set; } + + protected override async Task SendAsync( + HttpRequestMessage request, CancellationToken cancellationToken) + { + CapturedRequest = request; + CapturedContentType = request.Content?.Headers.ContentType?.ToString(); + CapturedBody = request.Content is not null + ? await request.Content.ReadAsStringAsync(cancellationToken) + : null; + + var response = new HttpResponseMessage(HttpStatusCode.OK) + { + Content = new StringContent( + """{"code":200,"type":"ok","message":"ok"}""", + System.Text.Encoding.UTF8, + "application/json") + }; + + return response; + } + } + + private IHost _host = null!; + private CapturingHandler _capturingHandler = null!; + + [TestInitialize] + public void Setup() + { + _capturingHandler = new CapturingHandler(); + + IHostBuilder hostBuilder = Host.CreateDefaultBuilder(Array.Empty()) + .ConfigureApi((context, services, options) => + { + options.AddTokens(new ApiKeyToken("test-key", ClientUtils.ApiKeyHeader.Api_key, timeout: TimeSpan.FromSeconds(1))); + options.AddTokens(new BearerToken("test-bearer", timeout: TimeSpan.FromSeconds(1))); + options.AddTokens(new BasicToken("user", "pass", timeout: TimeSpan.FromSeconds(1))); + options.AddTokens(new OAuthToken("test-oauth", timeout: TimeSpan.FromSeconds(1))); + + HttpSigningConfiguration signingConfig = new("", "", null, + new List(), System.Security.Cryptography.HashAlgorithmName.SHA256, "", 0); + options.AddTokens(new HttpSignatureToken(signingConfig, timeout: TimeSpan.FromSeconds(1))); + + options.AddApiHttpClients( + client: c => c.BaseAddress = new Uri("http://localhost/"), + builder: b => b.ConfigurePrimaryHttpMessageHandler(() => _capturingHandler)); + }); + + _host = hostBuilder.Build(); + } + + [TestCleanup] + public void Cleanup() + { + _host.Dispose(); + _capturingHandler.Dispose(); + } + + [TestMethod] + public async Task UploadFile_SingleOptionalFile_ContentTypeHasBoundary() + { + var petApi = _host.Services.GetRequiredService(); + using var stream = new MemoryStream(new byte[] { 1, 2, 3 }); + + await petApi.UploadFileAsync(petId: 1, file: new Option(new FileParameter(stream))); + + Assert.IsNotNull(_capturingHandler.CapturedContentType, + "Content-Type header should not be null for a multipart/form-data request."); + StringAssert.Contains(_capturingHandler.CapturedContentType, "multipart/form-data", + "Content-Type should be multipart/form-data."); + StringAssert.Contains(_capturingHandler.CapturedContentType, "boundary=", + "Content-Type must include a boundary parameter so the server can parse the body."); + } + + [TestMethod] + public async Task UploadFile_SingleOptionalFile_BodyContainsFileWithCorrectFieldName() + { + var petApi = _host.Services.GetRequiredService(); + using var stream = new MemoryStream(new byte[] { 1, 2, 3 }); + + await petApi.UploadFileAsync(petId: 1, file: new Option(new FileParameter(stream))); + + Assert.IsNotNull(_capturingHandler.CapturedBody, "Body should not be null."); + // .NET's MultipartFormDataContent writes unquoted names: name=file (valid per RFC 7578) + StringAssert.Contains(_capturingHandler.CapturedBody, "name=file", + "Multipart part should use the field name 'file' as defined in the spec."); + } + + [TestMethod] + public async Task UploadFiles_MultipleRequiredFiles_ContentTypeHasBoundary() + { + var petApi = _host.Services.GetRequiredService(); + using var stream1 = new MemoryStream(new byte[] { 1, 2, 3 }); + using var stream2 = new MemoryStream(new byte[] { 4, 5, 6 }); + + await petApi.UploadFilesAsync( + files: new List { new FileParameter(stream1), new FileParameter(stream2) }, + petId: 1); + + Assert.IsNotNull(_capturingHandler.CapturedContentType, + "Content-Type header should not be null for a multipart/form-data request."); + StringAssert.Contains(_capturingHandler.CapturedContentType, "multipart/form-data", + "Content-Type should be multipart/form-data."); + StringAssert.Contains(_capturingHandler.CapturedContentType, "boundary=", + "Content-Type must include a boundary parameter so the server can parse the body."); + } + + [TestMethod] + public async Task UploadFiles_MultipleRequiredFiles_BodyContainsBothFilesWithCorrectFieldName() + { + var petApi = _host.Services.GetRequiredService(); + using var stream1 = new MemoryStream(new byte[] { 10, 20, 30 }); + using var stream2 = new MemoryStream(new byte[] { 40, 50, 60 }); + + await petApi.UploadFilesAsync( + files: new List { new FileParameter(stream1), new FileParameter(stream2) }, + petId: 1); + + Assert.IsNotNull(_capturingHandler.CapturedBody, "Body should not be null."); + + // Count Content-Disposition headers for the "files" field. Each stream must appear as + // its own named part. Matching the full header prefix avoids false positives from + // "filename=files" which also contains "name=files" as a substring. + var parts = _capturingHandler.CapturedBody!.Split("Content-Disposition: form-data; name=files"); + Assert.AreEqual(3, parts.Length, + "Body should contain exactly two parts named 'files' (one per stream), " + + $"but found {parts.Length - 1}. Body:\n{_capturingHandler.CapturedBody}"); + } + + /// + /// Covers issue #21384: multipart/form-data with only text form fields (no file) + /// must still include the boundary in Content-Type so the server can parse the body. + /// Uses UploadFileAsync with only the optional additionalMetadata text field, no file. + /// + [TestMethod] + public async Task UploadFile_TextFieldOnly_NoFile_ContentTypeHasBoundary() + { + var petApi = _host.Services.GetRequiredService(); + + await petApi.UploadFileAsync( + petId: 1, + additionalMetadata: new Option("some metadata")); + + Assert.IsNotNull(_capturingHandler.CapturedContentType, + "Content-Type header should not be null for a multipart/form-data request."); + StringAssert.Contains(_capturingHandler.CapturedContentType, "multipart/form-data", + "Content-Type should be multipart/form-data."); + StringAssert.Contains(_capturingHandler.CapturedContentType, "boundary=", + "Content-Type must include a boundary parameter so the server can parse the body."); + } + + [TestMethod] + public async Task UploadFile_TextFieldOnly_NoFile_BodyContainsTextValue() + { + var petApi = _host.Services.GetRequiredService(); + + await petApi.UploadFileAsync( + petId: 1, + additionalMetadata: new Option("testmetadata")); + + Assert.IsNotNull(_capturingHandler.CapturedBody, "Body should not be null."); + StringAssert.Contains(_capturingHandler.CapturedBody, "testmetadata", + "Body should contain the additionalMetadata value."); + } + + /// + /// Covers the case where an optional file and an optional text field are both supplied. + /// Ensures that adding text alongside a file does not strip the boundary. + /// + [TestMethod] + public async Task UploadFile_WithBothFileAndText_ContentTypeHasBoundary() + { + var petApi = _host.Services.GetRequiredService(); + using var stream = new MemoryStream(new byte[] { 1, 2, 3 }); + + await petApi.UploadFileAsync( + petId: 1, + file: new Option(new FileParameter(stream)), + additionalMetadata: new Option("testmetadata")); + + Assert.IsNotNull(_capturingHandler.CapturedContentType, + "Content-Type header should not be null."); + StringAssert.Contains(_capturingHandler.CapturedContentType, "multipart/form-data", + "Content-Type should be multipart/form-data."); + StringAssert.Contains(_capturingHandler.CapturedContentType, "boundary=", + "Content-Type must include a boundary parameter."); + } + + [TestMethod] + public async Task UploadFile_WithBothFileAndText_BodyContainsBothFields() + { + var petApi = _host.Services.GetRequiredService(); + using var stream = new MemoryStream(new byte[] { 1, 2, 3 }); + + await petApi.UploadFileAsync( + petId: 1, + file: new Option(new FileParameter(stream)), + additionalMetadata: new Option("testmetadata")); + + Assert.IsNotNull(_capturingHandler.CapturedBody, "Body should not be null."); + StringAssert.Contains(_capturingHandler.CapturedBody, "name=file", + "Body should contain a part named 'file'."); + StringAssert.Contains(_capturingHandler.CapturedBody, "testmetadata", + "Body should contain the additionalMetadata value."); + } + + /// + /// Covers UploadFileWithRequiredFile: a required (non-optional) binary file param. + /// Tests the required-file code path in the template, which differs from optional files. + /// + [TestMethod] + public async Task UploadFileWithRequiredFile_RequiredFileOnly_ContentTypeHasBoundary() + { + var petApi = _host.Services.GetRequiredService(); + using var stream = new MemoryStream(new byte[] { 7, 8, 9 }); + + await petApi.UploadFileWithRequiredFileAsync(petId: 1, requiredFile: new FileParameter(stream)); + + Assert.IsNotNull(_capturingHandler.CapturedContentType, + "Content-Type header should not be null."); + StringAssert.Contains(_capturingHandler.CapturedContentType, "multipart/form-data", + "Content-Type should be multipart/form-data."); + StringAssert.Contains(_capturingHandler.CapturedContentType, "boundary=", + "Content-Type must include a boundary parameter."); + } + + [TestMethod] + public async Task UploadFileWithRequiredFile_RequiredFileOnly_BodyContainsCorrectFieldName() + { + var petApi = _host.Services.GetRequiredService(); + using var stream = new MemoryStream(new byte[] { 7, 8, 9 }); + + await petApi.UploadFileWithRequiredFileAsync(petId: 1, requiredFile: new FileParameter(stream)); + + Assert.IsNotNull(_capturingHandler.CapturedBody, "Body should not be null."); + StringAssert.Contains(_capturingHandler.CapturedBody, "name=requiredFile", + "Multipart part should use the field name 'requiredFile' as defined in the spec."); + } + + [TestMethod] + public async Task UploadFileWithRequiredFile_WithTextAndFile_ContentTypeHasBoundary() + { + var petApi = _host.Services.GetRequiredService(); + using var stream = new MemoryStream(new byte[] { 7, 8, 9 }); + + await petApi.UploadFileWithRequiredFileAsync( + petId: 1, + requiredFile: new FileParameter(stream), + additionalMetadata: new Option("testmetadata")); + + Assert.IsNotNull(_capturingHandler.CapturedContentType, + "Content-Type header should not be null."); + StringAssert.Contains(_capturingHandler.CapturedContentType, "multipart/form-data", + "Content-Type should be multipart/form-data."); + StringAssert.Contains(_capturingHandler.CapturedContentType, "boundary=", + "Adding text fields alongside binary fields must not strip the boundary."); + } + + [TestMethod] + public async Task UploadFileWithRequiredFile_WithTextAndFile_BodyContainsBothFields() + { + var petApi = _host.Services.GetRequiredService(); + using var stream = new MemoryStream(new byte[] { 7, 8, 9 }); + + await petApi.UploadFileWithRequiredFileAsync( + petId: 1, + requiredFile: new FileParameter(stream), + additionalMetadata: new Option("testmetadata")); + + Assert.IsNotNull(_capturingHandler.CapturedBody, "Body should not be null."); + StringAssert.Contains(_capturingHandler.CapturedBody, "name=requiredFile", + "Body should contain a part named 'requiredFile'."); + StringAssert.Contains(_capturingHandler.CapturedBody, "testmetadata", + "Body should contain the additionalMetadata value."); + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/.openapi-generator/FILES index ab28c754b4b1..a3e02b328e0a 100644 --- a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/.openapi-generator/FILES @@ -140,6 +140,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/HttpSigningConfiguration.cs src/Org.OpenAPITools/Client/HttpSigningToken.cs diff --git a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/api/openapi.yaml index d8106a5755fc..ca451f3fb832 100644 --- a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/api/openapi.yaml @@ -331,6 +331,40 @@ paths: summary: uploads an image tags: - pet + /pet/{petId}/uploadImages: + post: + description: "" + operationId: uploadFiles + parameters: + - description: ID of pet to update + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + multipart/form-data: + schema: + $ref: "#/components/schemas/uploadFiles_request" + required: true + responses: + "200": + content: + application/json: + schema: + $ref: "#/components/schemas/ApiResponse" + description: successful operation + security: + - petstore_auth: + - write:pets + - read:pets + summary: uploads an images + tags: + - pet /store/inventory: get: description: Returns a map of status codes to quantities @@ -2924,6 +2958,16 @@ components: format: binary type: string type: object + uploadFiles_request: + properties: + files: + items: + format: binary + type: string + type: array + required: + - files + type: object testEnumParameters_request: properties: enum_form_string_array: diff --git a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/docs/apis/PetApi.md b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/docs/apis/PetApi.md index 2826ea00f728..b42ee516b313 100644 --- a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/docs/apis/PetApi.md +++ b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/docs/apis/PetApi.md @@ -13,6 +13,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* | [**UpdatePetWithForm**](PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data | | [**UploadFile**](PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image | | [**UploadFileWithRequiredFile**](PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) | +| [**UploadFiles**](PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images | # **AddPet** @@ -341,3 +342,38 @@ uploads an image (required) [[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + +# **UploadFiles** +> ApiResponse UploadFiles (List files, long petId) + +uploads an images + + +### Parameters + +| Name | Type | Description | Notes | +|------|------|-------------|-------| +| **files** | **List<System.IO.Stream>** | | | +| **petId** | **long** | ID of pet to update | | + +### Return type + +[**ApiResponse**](ApiResponse.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: multipart/form-data + - **Accept**: application/json + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | + +[[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + diff --git a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs index 406dbc964a6d..d207bb93dc69 100644 --- a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs @@ -196,7 +196,7 @@ public async Task TestEndpointParametersAsyncTest() string patternWithoutDelimiter = default!; byte[] varByte = default!; double varDouble = default!; - Client.Option binary = default!; + Client.Option binary = default!; Client.Option callback = default!; Client.Option date = default!; Client.Option dateTime = default!; diff --git a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 49e7b21b53c2..6bb1f953987c 100644 --- a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools.Test/Api/PetApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools.Test/Api/PetApiTests.cs @@ -137,7 +137,7 @@ public async Task UploadFileAsyncTest() { long petId = default!; Client.Option additionalMetadata = default!; - Client.Option file = default!; + Client.Option file = default!; var response = await _instance.UploadFileAsync(petId, additionalMetadata, file); var model = response.Ok(); Assert.IsType(model); @@ -150,11 +150,24 @@ public async Task UploadFileAsyncTest() public async Task UploadFileWithRequiredFileAsyncTest() { long petId = default!; - System.IO.Stream requiredFile = default!; + Org.OpenAPITools.Client.FileParameter requiredFile = default!; Client.Option additionalMetadata = default!; var response = await _instance.UploadFileWithRequiredFileAsync(petId, requiredFile, additionalMetadata); var model = response.Ok(); Assert.IsType(model); } + + /// + /// Test UploadFiles + /// + [Fact (Skip = "not implemented")] + public async Task UploadFilesAsyncTest() + { + List files = default!; + long petId = default!; + var response = await _instance.UploadFilesAsync(files, petId); + var model = response.Ok(); + Assert.IsType(model); + } } } diff --git a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Api/DefaultApi.cs index 2391c7e1ee03..46b798fe32ca 100644 --- a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Api/DefaultApi.cs +++ b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Api/DefaultApi.cs @@ -766,15 +766,12 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + List> formParameterLocalVars = new List>(); - httpRequestMessageLocalVar.Content = multipartContentLocalVar; + formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); - List> formParameterLocalVars = new List>(); - - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -782,11 +779,6 @@ public async Task GetCountryAsync(string country, System "application/x-www-form-urlencoded" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Api/FakeApi.cs b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Api/FakeApi.cs index 262a94ef2520..54a1c8c85360 100644 --- a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Api/FakeApi.cs +++ b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Api/FakeApi.cs @@ -332,7 +332,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <> - Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -356,7 +356,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <?> - Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// To test enum parameters @@ -4082,7 +4082,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); + partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); /// /// Validates the request parameters @@ -4094,7 +4094,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) + private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) { if (patternWithoutDelimiter == null) throw new ArgumentNullException(nameof(patternWithoutDelimiter)); @@ -4133,7 +4133,7 @@ private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte /// /// /// - private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLog = false; AfterTestEndpointParameters(ref suppressDefaultLog, apiResponseLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4160,7 +4160,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Logs exceptions that occur while retrieving the server response @@ -4182,7 +4182,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLogLocalVar = false; OnErrorTestEndpointParameters(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4211,7 +4211,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// /// /// - partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -4232,7 +4232,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -4264,7 +4264,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -4283,51 +4283,48 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + List> formParameterLocalVars = new List>(); - httpRequestMessageLocalVar.Content = multipartContentLocalVar; + formParameterLocalVars.Add(new KeyValuePair("number", ClientUtils.ParameterToString(number))); - List> formParameterLocalVars = new List>(); + formParameterLocalVars.Add(new KeyValuePair("pattern_without_delimiter", ClientUtils.ParameterToString(patternWithoutDelimiter))); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + formParameterLocalVars.Add(new KeyValuePair("byte", ClientUtils.ParameterToString(varByte))); - formParameterLocalVars.Add(new KeyValuePair("number", ClientUtils.ParameterToString(number))); - - formParameterLocalVars.Add(new KeyValuePair("pattern_without_delimiter", ClientUtils.ParameterToString(patternWithoutDelimiter))); - - formParameterLocalVars.Add(new KeyValuePair("byte", ClientUtils.ParameterToString(varByte))); - - formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); + formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.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."); if (callback.IsSet) - formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); + formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); if (date.IsSet) - formParameterLocalVars.Add(new KeyValuePair("date", ClientUtils.ParameterToString(date.Value))); + formParameterLocalVars.Add(new KeyValuePair("date", ClientUtils.ParameterToString(date.Value))); if (dateTime.IsSet) - formParameterLocalVars.Add(new KeyValuePair("dateTime", ClientUtils.ParameterToString(dateTime.Value))); + formParameterLocalVars.Add(new KeyValuePair("dateTime", ClientUtils.ParameterToString(dateTime.Value))); if (int32.IsSet) - formParameterLocalVars.Add(new KeyValuePair("int32", ClientUtils.ParameterToString(int32.Value))); + formParameterLocalVars.Add(new KeyValuePair("int32", ClientUtils.ParameterToString(int32.Value))); if (int64.IsSet) - formParameterLocalVars.Add(new KeyValuePair("int64", ClientUtils.ParameterToString(int64.Value))); + formParameterLocalVars.Add(new KeyValuePair("int64", ClientUtils.ParameterToString(int64.Value))); if (integer.IsSet) - formParameterLocalVars.Add(new KeyValuePair("integer", ClientUtils.ParameterToString(integer.Value))); + formParameterLocalVars.Add(new KeyValuePair("integer", ClientUtils.ParameterToString(integer.Value))); if (password.IsSet) - formParameterLocalVars.Add(new KeyValuePair("password", ClientUtils.ParameterToString(password.Value))); + formParameterLocalVars.Add(new KeyValuePair("password", ClientUtils.ParameterToString(password.Value))); if (varFloat.IsSet) - formParameterLocalVars.Add(new KeyValuePair("float", ClientUtils.ParameterToString(varFloat.Value))); + formParameterLocalVars.Add(new KeyValuePair("float", ClientUtils.ParameterToString(varFloat.Value))); if (varString.IsSet) - formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4342,11 +4339,6 @@ public async Task TestEndpointParametersAsyn "application/x-www-form-urlencoded" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -4639,17 +4631,16 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); + List> formParameterLocalVars = new List>(); - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - - List> formParameterLocalVars = new List>(); - - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (enumFormString.IsSet) - formParameterLocalVars.Add(new KeyValuePair("enum_form_string", ClientUtils.ParameterToString(enumFormString.Value))); + if (enumFormString.IsSet) + formParameterLocalVars.Add(new KeyValuePair("enum_form_string", ClientUtils.ParameterToString(enumFormString.Value))); if (enumFormStringArray.IsSet) - formParameterLocalVars.Add(new KeyValuePair("enum_form_string_array", ClientUtils.ParameterToString(enumFormStringArray.Value))); + formParameterLocalVars.Add(new KeyValuePair("enum_form_string_array", ClientUtils.ParameterToString(enumFormStringArray.Value))); + + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4657,11 +4648,6 @@ public async Task TestEnumParametersAsync(Option "application/x-www-form-urlencoded" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Get; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -5548,17 +5534,14 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; + List> formParameterLocalVars = new List>(); - List> formParameterLocalVars = new List>(); + formParameterLocalVars.Add(new KeyValuePair("param", ClientUtils.ParameterToString(param))); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + formParameterLocalVars.Add(new KeyValuePair("param2", ClientUtils.ParameterToString(param2))); - formParameterLocalVars.Add(new KeyValuePair("param", ClientUtils.ParameterToString(param))); - - formParameterLocalVars.Add(new KeyValuePair("param2", ClientUtils.ParameterToString(param2))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -5566,11 +5549,6 @@ public async Task TestJsonFormDataAsync(string par "application/x-www-form-urlencoded" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Get; DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Api/PetApi.cs b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Api/PetApi.cs index 2d7e4dab0b84..c5de9cd55ad1 100644 --- a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Api/PetApi.cs +++ b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Api/PetApi.cs @@ -218,7 +218,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image @@ -231,7 +231,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <?> - Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -245,7 +245,7 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -258,7 +258,32 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <?> - Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <?> + Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); } /// @@ -417,6 +442,18 @@ public interface IUploadFileWithRequiredFileApiResponse : Org.OpenAPITools.Clien bool IsOk { get; } } + /// + /// The + /// + public interface IUploadFilesApiResponse : Org.OpenAPITools.Client.IApiResponse, IOk + { + /// + /// Returns true if the response is 200 Ok + /// + /// + bool IsOk { get; } + } + /// /// Represents a collection of functions to interact with the API endpoints /// @@ -601,6 +638,26 @@ internal void ExecuteOnErrorUploadFileWithRequiredFile(Exception exception) { OnErrorUploadFileWithRequiredFile?.Invoke(this, new ExceptionEventArgs(exception)); } + + /// + /// The event raised after the server response + /// + public event EventHandler? OnUploadFiles; + + /// + /// The event raised after an error querying the server + /// + public event EventHandler? OnErrorUploadFiles; + + internal void ExecuteOnUploadFiles(PetApi.UploadFilesApiResponse apiResponse) + { + OnUploadFiles?.Invoke(this, new ApiResponseEventArgs(apiResponse)); + } + + internal void ExecuteOnErrorUploadFiles(Exception exception) + { + OnErrorUploadFiles?.Invoke(this, new ExceptionEventArgs(exception)); + } } /// @@ -2332,17 +2389,16 @@ public async Task UpdatePetWithFormAsync(long pet : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - - List> formParameterLocalVars = new List>(); + List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (name.IsSet) - formParameterLocalVars.Add(new KeyValuePair("name", ClientUtils.ParameterToString(name.Value))); + if (name.IsSet) + formParameterLocalVars.Add(new KeyValuePair("name", ClientUtils.ParameterToString(name.Value))); if (status.IsSet) - formParameterLocalVars.Add(new KeyValuePair("status", ClientUtils.ParameterToString(status.Value))); + formParameterLocalVars.Add(new KeyValuePair("status", ClientUtils.ParameterToString(status.Value))); + + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2357,11 +2413,6 @@ public async Task UpdatePetWithFormAsync(long pet "application/x-www-form-urlencoded" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -2461,7 +2512,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); + partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); /// /// Validates the request parameters @@ -2469,7 +2520,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFile(Option additionalMetadata, Option file) + private void ValidateUploadFile(Option additionalMetadata, Option file) { if (additionalMetadata.IsSet && additionalMetadata.Value == null) throw new ArgumentNullException(nameof(additionalMetadata)); @@ -2485,7 +2536,7 @@ private void ValidateUploadFile(Option additionalMetadata, Option /// /// - private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) + private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLog = false; AfterUploadFile(ref suppressDefaultLog, apiResponseLocalVar, petId, additionalMetadata, file); @@ -2501,7 +2552,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); + partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); /// /// Logs exceptions that occur while retrieving the server response @@ -2512,7 +2563,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) + private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, additionalMetadata, file); @@ -2530,7 +2581,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// /// /// - partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); + partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); /// /// uploads an image @@ -2540,7 +2591,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2561,7 +2612,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2581,17 +2632,23 @@ public async Task UploadFileAsync(long petId, Option> formParameterLocalVars = new List>(); + List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (additionalMetadata.IsSet) - formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + if (additionalMetadata.IsSet) + formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); if (file.IsSet) - multipartContentLocalVar.Add(new StreamContent(file.Value)); + { + var streamContentLocalVar = new StreamContent(file.Value.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "file", file.Value.FileName ?? "file"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2606,11 +2663,6 @@ public async Task UploadFileAsync(long petId, Option additionalMetadata); + partial void FormatUploadFileWithRequiredFile(ref long petId, ref Org.OpenAPITools.Client.FileParameter requiredFile, ref Option additionalMetadata); /// /// Validates the request parameters @@ -2759,7 +2811,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, Option additionalMetadata) + private void ValidateUploadFileWithRequiredFile(Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { if (requiredFile == null) throw new ArgumentNullException(nameof(requiredFile)); @@ -2775,7 +2827,7 @@ private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, O /// /// /// - private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLog = false; AfterUploadFileWithRequiredFile(ref suppressDefaultLog, apiResponseLocalVar, petId, requiredFile, additionalMetadata); @@ -2791,7 +2843,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// Logs exceptions that occur while retrieving the server response @@ -2802,7 +2854,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFileWithRequiredFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, requiredFile, additionalMetadata); @@ -2820,7 +2872,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// /// /// - partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// uploads an image (required) @@ -2830,7 +2882,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2851,7 +2903,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2871,16 +2923,22 @@ public async Task UploadFileWithRequired : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/{petId}/uploadImageWithRequiredFile"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); + List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); multipartContentLocalVar.Add(new StreamContent(requiredFile)); + { + var streamContentLocalVar = new StreamContent(requiredFile.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile", requiredFile.FileName ?? "requiredFile"); + } if (additionalMetadata.IsSet) - formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2895,11 +2953,6 @@ public async Task UploadFileWithRequired "multipart/form-data" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - string[] acceptLocalVars = new string[] { "application/json", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" @@ -3040,5 +3093,283 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } + + partial void FormatUploadFiles(List files, ref long petId); + + /// + /// Validates the request parameters + /// + /// + /// + private void ValidateUploadFiles(List files) + { + if (files == null) + throw new ArgumentNullException(nameof(files)); + } + + /// + /// Processes the server response + /// + /// + /// + /// + private void AfterUploadFilesDefaultImplementation(IUploadFilesApiResponse apiResponseLocalVar, List files, long petId) + { + bool suppressDefaultLog = false; + AfterUploadFiles(ref suppressDefaultLog, apiResponseLocalVar, files, petId); + if (!suppressDefaultLog) + Logger.LogInformation("{0,-9} | {1} | {2}", (apiResponseLocalVar.DownloadedAt - apiResponseLocalVar.RequestedAt).TotalSeconds, apiResponseLocalVar.StatusCode, apiResponseLocalVar.Path); + } + + /// + /// Processes the server response + /// + /// + /// + /// + /// + partial void AfterUploadFiles(ref bool suppressDefaultLog, IUploadFilesApiResponse apiResponseLocalVar, List files, long petId); + + /// + /// Logs exceptions that occur while retrieving the server response + /// + /// + /// + /// + /// + /// + private void OnErrorUploadFilesDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId) + { + bool suppressDefaultLogLocalVar = false; + OnErrorUploadFiles(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, files, petId); + if (!suppressDefaultLogLocalVar) + Logger.LogError(exceptionLocalVar, "An error occurred while sending the request to the server."); + } + + /// + /// A partial method that gives developers a way to provide customized exception handling + /// + /// + /// + /// + /// + /// + /// + partial void OnErrorUploadFiles(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId); + + /// + /// uploads an images + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + try + { + return await UploadFilesAsync(files, petId, cancellationToken).ConfigureAwait(false); + } + catch (Exception) + { + return null; + } + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + UriBuilder uriBuilderLocalVar = new UriBuilder(); + + try + { + ValidateUploadFiles(files); + + FormatUploadFiles(files, ref petId); + + using (HttpRequestMessage httpRequestMessageLocalVar = new HttpRequestMessage()) + { + uriBuilderLocalVar.Host = HttpClient.BaseAddress!.Host; + uriBuilderLocalVar.Port = HttpClient.BaseAddress.Port; + uriBuilderLocalVar.Scheme = HttpClient.BaseAddress.Scheme; + uriBuilderLocalVar.Path = HttpClient.BaseAddress.AbsolutePath == "/" + ? "/pet/{petId}/uploadImages" + : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}/uploadImages"); + uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); + + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); + + httpRequestMessageLocalVar.Content = multipartContentLocalVar; + + List> formParameterLocalVars = new List>(); + + foreach (Org.OpenAPITools.Client.FileParameter fileParameterLocalVar in files) + { + var streamContentLocalVar = new StreamContent(fileParameterLocalVar.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "files", fileParameterLocalVar.FileName ?? "files"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); + + List tokenBaseLocalVars = new List(); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; + + OAuthToken oauthTokenLocalVar1 = (OAuthToken) await OauthTokenProvider.GetAsync(cancellation: cancellationToken).ConfigureAwait(false); + + tokenBaseLocalVars.Add(oauthTokenLocalVar1); + + oauthTokenLocalVar1.UseInHeader(httpRequestMessageLocalVar, ""); + + string[] contentTypes = new string[] { + "multipart/form-data" + }; + + string[] acceptLocalVars = new string[] { + "application/json" + }; + + IEnumerable acceptHeaderValuesLocalVar = ClientUtils.SelectHeaderAcceptArray(acceptLocalVars); + + foreach (var acceptLocalVar in acceptHeaderValuesLocalVar) + httpRequestMessageLocalVar.Headers.Accept.Add(acceptLocalVar); + + httpRequestMessageLocalVar.Method = HttpMethod.Post; + + DateTime requestedAtLocalVar = DateTime.UtcNow; + + using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false)) + { + ILogger apiResponseLoggerLocalVar = LoggerFactory.CreateLogger(); + UploadFilesApiResponse apiResponseLocalVar; + + switch ((int)httpResponseMessageLocalVar.StatusCode) { + default: { + string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + apiResponseLocalVar = new(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/pet/{petId}/uploadImages", requestedAtLocalVar, _jsonSerializerOptions); + + break; + } + } + + AfterUploadFilesDefaultImplementation(apiResponseLocalVar, files, petId); + + Events.ExecuteOnUploadFiles(apiResponseLocalVar); + + if (apiResponseLocalVar.StatusCode == (HttpStatusCode) 429) + foreach(TokenBase tokenBaseLocalVar in tokenBaseLocalVars) + tokenBaseLocalVar.BeginRateLimit(); + + return apiResponseLocalVar; + } + } + } + catch(Exception e) + { + OnErrorUploadFilesDefaultImplementation(e, "/pet/{petId}/uploadImages", uriBuilderLocalVar.Path, files, petId); + Events.ExecuteOnErrorUploadFiles(e); + throw; + } + } + + /// + /// The + /// + public partial class UploadFilesApiResponse : Org.OpenAPITools.Client.ApiResponse, IUploadFilesApiResponse + { + /// + /// The logger + /// + public ILogger Logger { get; } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, string rawContent, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, rawContent, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, System.IO.Stream contentStream, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, contentStream, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + partial void OnCreated(global::System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage); + + /// + /// Returns true if the response is 200 Ok + /// + /// + public bool IsOk => 200 == (int)StatusCode; + + /// + /// Deserializes the response if the response is 200 Ok + /// + /// + public Org.OpenAPITools.Model.ApiResponse? Ok() + { + // This logic may be modified with the AsModel.mustache template + return IsOk + ? System.Text.Json.JsonSerializer.Deserialize(RawContent, _jsonSerializerOptions) + : null; + } + + /// + /// Returns true if the response is 200 Ok and the deserialized response is not null + /// + /// + /// + public bool TryOk([NotNullWhen(true)]out Org.OpenAPITools.Model.ApiResponse? result) + { + result = null; + + try + { + result = Ok(); + } catch (Exception e) + { + OnDeserializationErrorDefaultImplementation(e, (HttpStatusCode)200); + } + + return result != null; + } + + private void OnDeserializationErrorDefaultImplementation(Exception exception, HttpStatusCode httpStatusCode) + { + bool suppressDefaultLog = false; + OnDeserializationError(ref suppressDefaultLog, exception, httpStatusCode); + if (!suppressDefaultLog) + Logger.LogError(exception, "An error occurred while deserializing the {code} response.", httpStatusCode); + } + + partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); + } } } diff --git a/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..77779fe7d75a --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,42 @@ +// +/* + * OpenAPI Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +#nullable enable + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string? FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string? fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/OneOf/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net8/OneOf/.openapi-generator/FILES index a36efde4422e..cfb76c7ed0ac 100644 --- a/samples/client/petstore/csharp/generichost/net8/OneOf/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net8/OneOf/.openapi-generator/FILES @@ -26,6 +26,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 diff --git a/samples/client/petstore/csharp/generichost/net8/OneOf/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net8/OneOf/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..e629f4afdaec --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/OneOf/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,42 @@ +// +/* + * fruity + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 0.0.1 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +#nullable enable + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string? FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string? fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/Petstore/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net8/Petstore/.openapi-generator/FILES index ab28c754b4b1..a3e02b328e0a 100644 --- a/samples/client/petstore/csharp/generichost/net8/Petstore/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net8/Petstore/.openapi-generator/FILES @@ -140,6 +140,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/HttpSigningConfiguration.cs src/Org.OpenAPITools/Client/HttpSigningToken.cs diff --git a/samples/client/petstore/csharp/generichost/net8/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net8/Petstore/api/openapi.yaml index d8106a5755fc..ca451f3fb832 100644 --- a/samples/client/petstore/csharp/generichost/net8/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net8/Petstore/api/openapi.yaml @@ -331,6 +331,40 @@ paths: summary: uploads an image tags: - pet + /pet/{petId}/uploadImages: + post: + description: "" + operationId: uploadFiles + parameters: + - description: ID of pet to update + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + multipart/form-data: + schema: + $ref: "#/components/schemas/uploadFiles_request" + required: true + responses: + "200": + content: + application/json: + schema: + $ref: "#/components/schemas/ApiResponse" + description: successful operation + security: + - petstore_auth: + - write:pets + - read:pets + summary: uploads an images + tags: + - pet /store/inventory: get: description: Returns a map of status codes to quantities @@ -2924,6 +2958,16 @@ components: format: binary type: string type: object + uploadFiles_request: + properties: + files: + items: + format: binary + type: string + type: array + required: + - files + type: object testEnumParameters_request: properties: enum_form_string_array: diff --git a/samples/client/petstore/csharp/generichost/net8/Petstore/docs/apis/PetApi.md b/samples/client/petstore/csharp/generichost/net8/Petstore/docs/apis/PetApi.md index 2826ea00f728..b42ee516b313 100644 --- a/samples/client/petstore/csharp/generichost/net8/Petstore/docs/apis/PetApi.md +++ b/samples/client/petstore/csharp/generichost/net8/Petstore/docs/apis/PetApi.md @@ -13,6 +13,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* | [**UpdatePetWithForm**](PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data | | [**UploadFile**](PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image | | [**UploadFileWithRequiredFile**](PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) | +| [**UploadFiles**](PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images | # **AddPet** @@ -341,3 +342,38 @@ uploads an image (required) [[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + +# **UploadFiles** +> ApiResponse UploadFiles (List files, long petId) + +uploads an images + + +### Parameters + +| Name | Type | Description | Notes | +|------|------|-------------|-------| +| **files** | **List<System.IO.Stream>** | | | +| **petId** | **long** | ID of pet to update | | + +### Return type + +[**ApiResponse**](ApiResponse.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: multipart/form-data + - **Accept**: application/json + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | + +[[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + diff --git a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs index 66769b3aee6a..fed093fb206f 100644 --- a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs @@ -196,7 +196,7 @@ public async Task TestEndpointParametersAsyncTest() string patternWithoutDelimiter = default; byte[] varByte = default; double varDouble = default; - Client.Option binary = default; + Client.Option binary = default; Client.Option callback = default; Client.Option date = default; Client.Option dateTime = default; diff --git a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 215e88093797..e9b05337bb59 100644 --- a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools.Test/Api/PetApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools.Test/Api/PetApiTests.cs @@ -137,7 +137,7 @@ public async Task UploadFileAsyncTest() { long petId = default; Client.Option additionalMetadata = default; - Client.Option file = default; + Client.Option file = default; var response = await _instance.UploadFileAsync(petId, additionalMetadata, file); var model = response.Ok(); Assert.IsType(model); @@ -150,11 +150,24 @@ public async Task UploadFileAsyncTest() public async Task UploadFileWithRequiredFileAsyncTest() { long petId = default; - System.IO.Stream requiredFile = default; + Org.OpenAPITools.Client.FileParameter requiredFile = default; Client.Option additionalMetadata = default; var response = await _instance.UploadFileWithRequiredFileAsync(petId, requiredFile, additionalMetadata); var model = response.Ok(); Assert.IsType(model); } + + /// + /// Test UploadFiles + /// + [Fact (Skip = "not implemented")] + public async Task UploadFilesAsyncTest() + { + List files = default; + long petId = default; + var response = await _instance.UploadFilesAsync(files, petId); + var model = response.Ok(); + Assert.IsType(model); + } } } diff --git a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs index 3c26a27185e6..44d52e7e1090 100644 --- a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs +++ b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs @@ -764,27 +764,19 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Api/FakeApi.cs b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Api/FakeApi.cs index 01aaf0ccbd85..482421f8c4ea 100644 --- a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Api/FakeApi.cs +++ b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Api/FakeApi.cs @@ -330,7 +330,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <> - Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -354,7 +354,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <> - Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// To test enum parameters @@ -4080,7 +4080,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); + partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); /// /// Validates the request parameters @@ -4092,7 +4092,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) + private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) { if (patternWithoutDelimiter == null) throw new ArgumentNullException(nameof(patternWithoutDelimiter)); @@ -4131,7 +4131,7 @@ private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte /// /// /// - private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLog = false; AfterTestEndpointParameters(ref suppressDefaultLog, apiResponseLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4158,7 +4158,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Logs exceptions that occur while retrieving the server response @@ -4180,7 +4180,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLogLocalVar = false; OnErrorTestEndpointParameters(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4209,7 +4209,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// /// /// - partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -4230,7 +4230,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -4262,7 +4262,7 @@ public async Task TestEndpointParametersOrDe /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -4281,14 +4281,8 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("number", ClientUtils.ParameterToString(number))); formParameterLocalVars.Add(new KeyValuePair("pattern_without_delimiter", ClientUtils.ParameterToString(patternWithoutDelimiter))); @@ -4298,7 +4292,7 @@ public async Task TestEndpointParametersAsyn formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.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."); if (callback.IsSet) formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); @@ -4327,6 +4321,9 @@ public async Task TestEndpointParametersAsyn if (varString.IsSet) formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4340,11 +4337,6 @@ public async Task TestEndpointParametersAsyn "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -4637,29 +4629,23 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (enumFormString.IsSet) + if (enumFormString.IsSet) formParameterLocalVars.Add(new KeyValuePair("enum_form_string", ClientUtils.ParameterToString(enumFormString.Value))); if (enumFormStringArray.IsSet) formParameterLocalVars.Add(new KeyValuePair("enum_form_string_array", ClientUtils.ParameterToString(enumFormStringArray.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Get; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -5546,29 +5532,21 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("param", ClientUtils.ParameterToString(param))); formParameterLocalVars.Add(new KeyValuePair("param2", ClientUtils.ParameterToString(param2))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Get; DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Api/PetApi.cs b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Api/PetApi.cs index a1817e3df697..da4dfd225bc4 100644 --- a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Api/PetApi.cs +++ b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Api/PetApi.cs @@ -216,7 +216,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image @@ -229,7 +229,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -243,7 +243,7 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -256,7 +256,32 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); } /// @@ -415,6 +440,18 @@ public interface IUploadFileWithRequiredFileApiResponse : Org.OpenAPITools.Clien bool IsOk { get; } } + /// + /// The + /// + public interface IUploadFilesApiResponse : Org.OpenAPITools.Client.IApiResponse, IOk + { + /// + /// Returns true if the response is 200 Ok + /// + /// + bool IsOk { get; } + } + /// /// Represents a collection of functions to interact with the API endpoints /// @@ -599,6 +636,26 @@ internal void ExecuteOnErrorUploadFileWithRequiredFile(Exception exception) { OnErrorUploadFileWithRequiredFile?.Invoke(this, new ExceptionEventArgs(exception)); } + + /// + /// The event raised after the server response + /// + public event EventHandler OnUploadFiles; + + /// + /// The event raised after an error querying the server + /// + public event EventHandler OnErrorUploadFiles; + + internal void ExecuteOnUploadFiles(PetApi.UploadFilesApiResponse apiResponse) + { + OnUploadFiles?.Invoke(this, new ApiResponseEventArgs(apiResponse)); + } + + internal void ExecuteOnErrorUploadFiles(Exception exception) + { + OnErrorUploadFiles?.Invoke(this, new ExceptionEventArgs(exception)); + } } /// @@ -2330,18 +2387,17 @@ public async Task UpdatePetWithFormAsync(long pet : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (name.IsSet) + if (name.IsSet) formParameterLocalVars.Add(new KeyValuePair("name", ClientUtils.ParameterToString(name.Value))); if (status.IsSet) formParameterLocalVars.Add(new KeyValuePair("status", ClientUtils.ParameterToString(status.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2355,11 +2411,6 @@ public async Task UpdatePetWithFormAsync(long pet "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -2459,7 +2510,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); + partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); /// /// Validates the request parameters @@ -2467,7 +2518,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFile(Option additionalMetadata, Option file) + private void ValidateUploadFile(Option additionalMetadata, Option file) { if (additionalMetadata.IsSet && additionalMetadata.Value == null) throw new ArgumentNullException(nameof(additionalMetadata)); @@ -2483,7 +2534,7 @@ private void ValidateUploadFile(Option additionalMetadata, Option /// /// - private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) + private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLog = false; AfterUploadFile(ref suppressDefaultLog, apiResponseLocalVar, petId, additionalMetadata, file); @@ -2499,7 +2550,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); + partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); /// /// Logs exceptions that occur while retrieving the server response @@ -2510,7 +2561,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) + private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, additionalMetadata, file); @@ -2528,7 +2579,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// /// /// - partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); + partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); /// /// uploads an image @@ -2538,7 +2589,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2559,7 +2610,7 @@ public async Task UploadFileOrDefaultAsync(long petId, O /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2579,17 +2630,23 @@ public async Task UploadFileAsync(long petId, Option> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (additionalMetadata.IsSet) + if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); if (file.IsSet) - multipartContentLocalVar.Add(new StreamContent(file.Value)); + { + var streamContentLocalVar = new StreamContent(file.Value.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "file", file.Value.FileName ?? "file"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2604,11 +2661,6 @@ public async Task UploadFileAsync(long petId, Option additionalMetadata); + partial void FormatUploadFileWithRequiredFile(ref long petId, ref Org.OpenAPITools.Client.FileParameter requiredFile, ref Option additionalMetadata); /// /// Validates the request parameters @@ -2757,7 +2809,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, Option additionalMetadata) + private void ValidateUploadFileWithRequiredFile(Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { if (requiredFile == null) throw new ArgumentNullException(nameof(requiredFile)); @@ -2773,7 +2825,7 @@ private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, O /// /// /// - private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLog = false; AfterUploadFileWithRequiredFile(ref suppressDefaultLog, apiResponseLocalVar, petId, requiredFile, additionalMetadata); @@ -2789,7 +2841,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// Logs exceptions that occur while retrieving the server response @@ -2800,7 +2852,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFileWithRequiredFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, requiredFile, additionalMetadata); @@ -2818,7 +2870,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// /// /// - partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// uploads an image (required) @@ -2828,7 +2880,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2849,7 +2901,7 @@ public async Task UploadFileWithRequired /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2869,17 +2921,23 @@ public async Task UploadFileWithRequired : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/{petId}/uploadImageWithRequiredFile"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); multipartContentLocalVar.Add(new StreamContent(requiredFile)); + { + var streamContentLocalVar = new StreamContent(requiredFile.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile", requiredFile.FileName ?? "requiredFile"); + } if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2893,11 +2951,6 @@ public async Task UploadFileWithRequired "multipart/form-data" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - string[] acceptLocalVars = new string[] { "application/json", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" @@ -3038,5 +3091,283 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } + + partial void FormatUploadFiles(List files, ref long petId); + + /// + /// Validates the request parameters + /// + /// + /// + private void ValidateUploadFiles(List files) + { + if (files == null) + throw new ArgumentNullException(nameof(files)); + } + + /// + /// Processes the server response + /// + /// + /// + /// + private void AfterUploadFilesDefaultImplementation(IUploadFilesApiResponse apiResponseLocalVar, List files, long petId) + { + bool suppressDefaultLog = false; + AfterUploadFiles(ref suppressDefaultLog, apiResponseLocalVar, files, petId); + if (!suppressDefaultLog) + Logger.LogInformation("{0,-9} | {1} | {2}", (apiResponseLocalVar.DownloadedAt - apiResponseLocalVar.RequestedAt).TotalSeconds, apiResponseLocalVar.StatusCode, apiResponseLocalVar.Path); + } + + /// + /// Processes the server response + /// + /// + /// + /// + /// + partial void AfterUploadFiles(ref bool suppressDefaultLog, IUploadFilesApiResponse apiResponseLocalVar, List files, long petId); + + /// + /// Logs exceptions that occur while retrieving the server response + /// + /// + /// + /// + /// + /// + private void OnErrorUploadFilesDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId) + { + bool suppressDefaultLogLocalVar = false; + OnErrorUploadFiles(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, files, petId); + if (!suppressDefaultLogLocalVar) + Logger.LogError(exceptionLocalVar, "An error occurred while sending the request to the server."); + } + + /// + /// A partial method that gives developers a way to provide customized exception handling + /// + /// + /// + /// + /// + /// + /// + partial void OnErrorUploadFiles(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId); + + /// + /// uploads an images + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + try + { + return await UploadFilesAsync(files, petId, cancellationToken).ConfigureAwait(false); + } + catch (Exception) + { + return null; + } + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + UriBuilder uriBuilderLocalVar = new UriBuilder(); + + try + { + ValidateUploadFiles(files); + + FormatUploadFiles(files, ref petId); + + using (HttpRequestMessage httpRequestMessageLocalVar = new HttpRequestMessage()) + { + uriBuilderLocalVar.Host = HttpClient.BaseAddress.Host; + uriBuilderLocalVar.Port = HttpClient.BaseAddress.Port; + uriBuilderLocalVar.Scheme = HttpClient.BaseAddress.Scheme; + uriBuilderLocalVar.Path = HttpClient.BaseAddress.AbsolutePath == "/" + ? "/pet/{petId}/uploadImages" + : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}/uploadImages"); + uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); + + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); + + httpRequestMessageLocalVar.Content = multipartContentLocalVar; + + List> formParameterLocalVars = new List>(); + + foreach (Org.OpenAPITools.Client.FileParameter fileParameterLocalVar in files) + { + var streamContentLocalVar = new StreamContent(fileParameterLocalVar.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "files", fileParameterLocalVar.FileName ?? "files"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); + + List tokenBaseLocalVars = new List(); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; + + OAuthToken oauthTokenLocalVar1 = (OAuthToken) await OauthTokenProvider.GetAsync(cancellation: cancellationToken).ConfigureAwait(false); + + tokenBaseLocalVars.Add(oauthTokenLocalVar1); + + oauthTokenLocalVar1.UseInHeader(httpRequestMessageLocalVar, ""); + + string[] contentTypes = new string[] { + "multipart/form-data" + }; + + string[] acceptLocalVars = new string[] { + "application/json" + }; + + IEnumerable acceptHeaderValuesLocalVar = ClientUtils.SelectHeaderAcceptArray(acceptLocalVars); + + foreach (var acceptLocalVar in acceptHeaderValuesLocalVar) + httpRequestMessageLocalVar.Headers.Accept.Add(acceptLocalVar); + + httpRequestMessageLocalVar.Method = HttpMethod.Post; + + DateTime requestedAtLocalVar = DateTime.UtcNow; + + using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false)) + { + ILogger apiResponseLoggerLocalVar = LoggerFactory.CreateLogger(); + UploadFilesApiResponse apiResponseLocalVar; + + switch ((int)httpResponseMessageLocalVar.StatusCode) { + default: { + string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + apiResponseLocalVar = new(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/pet/{petId}/uploadImages", requestedAtLocalVar, _jsonSerializerOptions); + + break; + } + } + + AfterUploadFilesDefaultImplementation(apiResponseLocalVar, files, petId); + + Events.ExecuteOnUploadFiles(apiResponseLocalVar); + + if (apiResponseLocalVar.StatusCode == (HttpStatusCode) 429) + foreach(TokenBase tokenBaseLocalVar in tokenBaseLocalVars) + tokenBaseLocalVar.BeginRateLimit(); + + return apiResponseLocalVar; + } + } + } + catch(Exception e) + { + OnErrorUploadFilesDefaultImplementation(e, "/pet/{petId}/uploadImages", uriBuilderLocalVar.Path, files, petId); + Events.ExecuteOnErrorUploadFiles(e); + throw; + } + } + + /// + /// The + /// + public partial class UploadFilesApiResponse : Org.OpenAPITools.Client.ApiResponse, IUploadFilesApiResponse + { + /// + /// The logger + /// + public ILogger Logger { get; } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, string rawContent, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, rawContent, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, System.IO.Stream contentStream, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, contentStream, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + partial void OnCreated(global::System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage); + + /// + /// Returns true if the response is 200 Ok + /// + /// + public bool IsOk => 200 == (int)StatusCode; + + /// + /// Deserializes the response if the response is 200 Ok + /// + /// + public Org.OpenAPITools.Model.ApiResponse Ok() + { + // This logic may be modified with the AsModel.mustache template + return IsOk + ? System.Text.Json.JsonSerializer.Deserialize(RawContent, _jsonSerializerOptions) + : null; + } + + /// + /// Returns true if the response is 200 Ok and the deserialized response is not null + /// + /// + /// + public bool TryOk([NotNullWhen(true)]out Org.OpenAPITools.Model.ApiResponse result) + { + result = null; + + try + { + result = Ok(); + } catch (Exception e) + { + OnDeserializationErrorDefaultImplementation(e, (HttpStatusCode)200); + } + + return result != null; + } + + private void OnDeserializationErrorDefaultImplementation(Exception exception, HttpStatusCode httpStatusCode) + { + bool suppressDefaultLog = false; + OnDeserializationError(ref suppressDefaultLog, exception, httpStatusCode); + if (!suppressDefaultLog) + Logger.LogError(exception, "An error occurred while deserializing the {code} response.", httpStatusCode); + } + + partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); + } } } diff --git a/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..6150dbcf4774 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,40 @@ +// +/* + * OpenAPI Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/.openapi-generator/FILES index ab28c754b4b1..a3e02b328e0a 100644 --- a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/.openapi-generator/FILES @@ -140,6 +140,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/HttpSigningConfiguration.cs src/Org.OpenAPITools/Client/HttpSigningToken.cs diff --git a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/api/openapi.yaml index d8106a5755fc..ca451f3fb832 100644 --- a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/api/openapi.yaml @@ -331,6 +331,40 @@ paths: summary: uploads an image tags: - pet + /pet/{petId}/uploadImages: + post: + description: "" + operationId: uploadFiles + parameters: + - description: ID of pet to update + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + multipart/form-data: + schema: + $ref: "#/components/schemas/uploadFiles_request" + required: true + responses: + "200": + content: + application/json: + schema: + $ref: "#/components/schemas/ApiResponse" + description: successful operation + security: + - petstore_auth: + - write:pets + - read:pets + summary: uploads an images + tags: + - pet /store/inventory: get: description: Returns a map of status codes to quantities @@ -2924,6 +2958,16 @@ components: format: binary type: string type: object + uploadFiles_request: + properties: + files: + items: + format: binary + type: string + type: array + required: + - files + type: object testEnumParameters_request: properties: enum_form_string_array: diff --git a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/docs/apis/PetApi.md b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/docs/apis/PetApi.md index 2826ea00f728..b42ee516b313 100644 --- a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/docs/apis/PetApi.md +++ b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/docs/apis/PetApi.md @@ -13,6 +13,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* | [**UpdatePetWithForm**](PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data | | [**UploadFile**](PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image | | [**UploadFileWithRequiredFile**](PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) | +| [**UploadFiles**](PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images | # **AddPet** @@ -341,3 +342,38 @@ uploads an image (required) [[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + +# **UploadFiles** +> ApiResponse UploadFiles (List files, long petId) + +uploads an images + + +### Parameters + +| Name | Type | Description | Notes | +|------|------|-------------|-------| +| **files** | **List<System.IO.Stream>** | | | +| **petId** | **long** | ID of pet to update | | + +### Return type + +[**ApiResponse**](ApiResponse.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: multipart/form-data + - **Accept**: application/json + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | + +[[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + diff --git a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs index 406dbc964a6d..d207bb93dc69 100644 --- a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs @@ -196,7 +196,7 @@ public async Task TestEndpointParametersAsyncTest() string patternWithoutDelimiter = default!; byte[] varByte = default!; double varDouble = default!; - Client.Option binary = default!; + Client.Option binary = default!; Client.Option callback = default!; Client.Option date = default!; Client.Option dateTime = default!; diff --git a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 49e7b21b53c2..6bb1f953987c 100644 --- a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools.Test/Api/PetApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools.Test/Api/PetApiTests.cs @@ -137,7 +137,7 @@ public async Task UploadFileAsyncTest() { long petId = default!; Client.Option additionalMetadata = default!; - Client.Option file = default!; + Client.Option file = default!; var response = await _instance.UploadFileAsync(petId, additionalMetadata, file); var model = response.Ok(); Assert.IsType(model); @@ -150,11 +150,24 @@ public async Task UploadFileAsyncTest() public async Task UploadFileWithRequiredFileAsyncTest() { long petId = default!; - System.IO.Stream requiredFile = default!; + Org.OpenAPITools.Client.FileParameter requiredFile = default!; Client.Option additionalMetadata = default!; var response = await _instance.UploadFileWithRequiredFileAsync(petId, requiredFile, additionalMetadata); var model = response.Ok(); Assert.IsType(model); } + + /// + /// Test UploadFiles + /// + [Fact (Skip = "not implemented")] + public async Task UploadFilesAsyncTest() + { + List files = default!; + long petId = default!; + var response = await _instance.UploadFilesAsync(files, petId); + var model = response.Ok(); + Assert.IsType(model); + } } } diff --git a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Api/DefaultApi.cs index 2391c7e1ee03..46b798fe32ca 100644 --- a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Api/DefaultApi.cs +++ b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Api/DefaultApi.cs @@ -766,15 +766,12 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + List> formParameterLocalVars = new List>(); - httpRequestMessageLocalVar.Content = multipartContentLocalVar; + formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); - List> formParameterLocalVars = new List>(); - - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -782,11 +779,6 @@ public async Task GetCountryAsync(string country, System "application/x-www-form-urlencoded" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Api/FakeApi.cs b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Api/FakeApi.cs index 262a94ef2520..54a1c8c85360 100644 --- a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Api/FakeApi.cs +++ b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Api/FakeApi.cs @@ -332,7 +332,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <> - Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -356,7 +356,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <?> - Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// To test enum parameters @@ -4082,7 +4082,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); + partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); /// /// Validates the request parameters @@ -4094,7 +4094,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) + private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) { if (patternWithoutDelimiter == null) throw new ArgumentNullException(nameof(patternWithoutDelimiter)); @@ -4133,7 +4133,7 @@ private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte /// /// /// - private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLog = false; AfterTestEndpointParameters(ref suppressDefaultLog, apiResponseLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4160,7 +4160,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Logs exceptions that occur while retrieving the server response @@ -4182,7 +4182,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLogLocalVar = false; OnErrorTestEndpointParameters(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4211,7 +4211,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// /// /// - partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -4232,7 +4232,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -4264,7 +4264,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -4283,51 +4283,48 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + List> formParameterLocalVars = new List>(); - httpRequestMessageLocalVar.Content = multipartContentLocalVar; + formParameterLocalVars.Add(new KeyValuePair("number", ClientUtils.ParameterToString(number))); - List> formParameterLocalVars = new List>(); + formParameterLocalVars.Add(new KeyValuePair("pattern_without_delimiter", ClientUtils.ParameterToString(patternWithoutDelimiter))); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + formParameterLocalVars.Add(new KeyValuePair("byte", ClientUtils.ParameterToString(varByte))); - formParameterLocalVars.Add(new KeyValuePair("number", ClientUtils.ParameterToString(number))); - - formParameterLocalVars.Add(new KeyValuePair("pattern_without_delimiter", ClientUtils.ParameterToString(patternWithoutDelimiter))); - - formParameterLocalVars.Add(new KeyValuePair("byte", ClientUtils.ParameterToString(varByte))); - - formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); + formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.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."); if (callback.IsSet) - formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); + formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); if (date.IsSet) - formParameterLocalVars.Add(new KeyValuePair("date", ClientUtils.ParameterToString(date.Value))); + formParameterLocalVars.Add(new KeyValuePair("date", ClientUtils.ParameterToString(date.Value))); if (dateTime.IsSet) - formParameterLocalVars.Add(new KeyValuePair("dateTime", ClientUtils.ParameterToString(dateTime.Value))); + formParameterLocalVars.Add(new KeyValuePair("dateTime", ClientUtils.ParameterToString(dateTime.Value))); if (int32.IsSet) - formParameterLocalVars.Add(new KeyValuePair("int32", ClientUtils.ParameterToString(int32.Value))); + formParameterLocalVars.Add(new KeyValuePair("int32", ClientUtils.ParameterToString(int32.Value))); if (int64.IsSet) - formParameterLocalVars.Add(new KeyValuePair("int64", ClientUtils.ParameterToString(int64.Value))); + formParameterLocalVars.Add(new KeyValuePair("int64", ClientUtils.ParameterToString(int64.Value))); if (integer.IsSet) - formParameterLocalVars.Add(new KeyValuePair("integer", ClientUtils.ParameterToString(integer.Value))); + formParameterLocalVars.Add(new KeyValuePair("integer", ClientUtils.ParameterToString(integer.Value))); if (password.IsSet) - formParameterLocalVars.Add(new KeyValuePair("password", ClientUtils.ParameterToString(password.Value))); + formParameterLocalVars.Add(new KeyValuePair("password", ClientUtils.ParameterToString(password.Value))); if (varFloat.IsSet) - formParameterLocalVars.Add(new KeyValuePair("float", ClientUtils.ParameterToString(varFloat.Value))); + formParameterLocalVars.Add(new KeyValuePair("float", ClientUtils.ParameterToString(varFloat.Value))); if (varString.IsSet) - formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4342,11 +4339,6 @@ public async Task TestEndpointParametersAsyn "application/x-www-form-urlencoded" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -4639,17 +4631,16 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); + List> formParameterLocalVars = new List>(); - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - - List> formParameterLocalVars = new List>(); - - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (enumFormString.IsSet) - formParameterLocalVars.Add(new KeyValuePair("enum_form_string", ClientUtils.ParameterToString(enumFormString.Value))); + if (enumFormString.IsSet) + formParameterLocalVars.Add(new KeyValuePair("enum_form_string", ClientUtils.ParameterToString(enumFormString.Value))); if (enumFormStringArray.IsSet) - formParameterLocalVars.Add(new KeyValuePair("enum_form_string_array", ClientUtils.ParameterToString(enumFormStringArray.Value))); + formParameterLocalVars.Add(new KeyValuePair("enum_form_string_array", ClientUtils.ParameterToString(enumFormStringArray.Value))); + + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4657,11 +4648,6 @@ public async Task TestEnumParametersAsync(Option "application/x-www-form-urlencoded" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Get; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -5548,17 +5534,14 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; + List> formParameterLocalVars = new List>(); - List> formParameterLocalVars = new List>(); + formParameterLocalVars.Add(new KeyValuePair("param", ClientUtils.ParameterToString(param))); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + formParameterLocalVars.Add(new KeyValuePair("param2", ClientUtils.ParameterToString(param2))); - formParameterLocalVars.Add(new KeyValuePair("param", ClientUtils.ParameterToString(param))); - - formParameterLocalVars.Add(new KeyValuePair("param2", ClientUtils.ParameterToString(param2))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -5566,11 +5549,6 @@ public async Task TestJsonFormDataAsync(string par "application/x-www-form-urlencoded" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Get; DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Api/PetApi.cs b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Api/PetApi.cs index 2d7e4dab0b84..c5de9cd55ad1 100644 --- a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Api/PetApi.cs +++ b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Api/PetApi.cs @@ -218,7 +218,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image @@ -231,7 +231,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <?> - Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -245,7 +245,7 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -258,7 +258,32 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <?> - Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <?> + Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); } /// @@ -417,6 +442,18 @@ public interface IUploadFileWithRequiredFileApiResponse : Org.OpenAPITools.Clien bool IsOk { get; } } + /// + /// The + /// + public interface IUploadFilesApiResponse : Org.OpenAPITools.Client.IApiResponse, IOk + { + /// + /// Returns true if the response is 200 Ok + /// + /// + bool IsOk { get; } + } + /// /// Represents a collection of functions to interact with the API endpoints /// @@ -601,6 +638,26 @@ internal void ExecuteOnErrorUploadFileWithRequiredFile(Exception exception) { OnErrorUploadFileWithRequiredFile?.Invoke(this, new ExceptionEventArgs(exception)); } + + /// + /// The event raised after the server response + /// + public event EventHandler? OnUploadFiles; + + /// + /// The event raised after an error querying the server + /// + public event EventHandler? OnErrorUploadFiles; + + internal void ExecuteOnUploadFiles(PetApi.UploadFilesApiResponse apiResponse) + { + OnUploadFiles?.Invoke(this, new ApiResponseEventArgs(apiResponse)); + } + + internal void ExecuteOnErrorUploadFiles(Exception exception) + { + OnErrorUploadFiles?.Invoke(this, new ExceptionEventArgs(exception)); + } } /// @@ -2332,17 +2389,16 @@ public async Task UpdatePetWithFormAsync(long pet : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - - List> formParameterLocalVars = new List>(); + List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (name.IsSet) - formParameterLocalVars.Add(new KeyValuePair("name", ClientUtils.ParameterToString(name.Value))); + if (name.IsSet) + formParameterLocalVars.Add(new KeyValuePair("name", ClientUtils.ParameterToString(name.Value))); if (status.IsSet) - formParameterLocalVars.Add(new KeyValuePair("status", ClientUtils.ParameterToString(status.Value))); + formParameterLocalVars.Add(new KeyValuePair("status", ClientUtils.ParameterToString(status.Value))); + + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2357,11 +2413,6 @@ public async Task UpdatePetWithFormAsync(long pet "application/x-www-form-urlencoded" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -2461,7 +2512,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); + partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); /// /// Validates the request parameters @@ -2469,7 +2520,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFile(Option additionalMetadata, Option file) + private void ValidateUploadFile(Option additionalMetadata, Option file) { if (additionalMetadata.IsSet && additionalMetadata.Value == null) throw new ArgumentNullException(nameof(additionalMetadata)); @@ -2485,7 +2536,7 @@ private void ValidateUploadFile(Option additionalMetadata, Option /// /// - private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) + private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLog = false; AfterUploadFile(ref suppressDefaultLog, apiResponseLocalVar, petId, additionalMetadata, file); @@ -2501,7 +2552,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); + partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); /// /// Logs exceptions that occur while retrieving the server response @@ -2512,7 +2563,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) + private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, additionalMetadata, file); @@ -2530,7 +2581,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// /// /// - partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); + partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); /// /// uploads an image @@ -2540,7 +2591,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2561,7 +2612,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2581,17 +2632,23 @@ public async Task UploadFileAsync(long petId, Option> formParameterLocalVars = new List>(); + List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (additionalMetadata.IsSet) - formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + if (additionalMetadata.IsSet) + formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); if (file.IsSet) - multipartContentLocalVar.Add(new StreamContent(file.Value)); + { + var streamContentLocalVar = new StreamContent(file.Value.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "file", file.Value.FileName ?? "file"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2606,11 +2663,6 @@ public async Task UploadFileAsync(long petId, Option additionalMetadata); + partial void FormatUploadFileWithRequiredFile(ref long petId, ref Org.OpenAPITools.Client.FileParameter requiredFile, ref Option additionalMetadata); /// /// Validates the request parameters @@ -2759,7 +2811,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, Option additionalMetadata) + private void ValidateUploadFileWithRequiredFile(Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { if (requiredFile == null) throw new ArgumentNullException(nameof(requiredFile)); @@ -2775,7 +2827,7 @@ private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, O /// /// /// - private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLog = false; AfterUploadFileWithRequiredFile(ref suppressDefaultLog, apiResponseLocalVar, petId, requiredFile, additionalMetadata); @@ -2791,7 +2843,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// Logs exceptions that occur while retrieving the server response @@ -2802,7 +2854,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFileWithRequiredFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, requiredFile, additionalMetadata); @@ -2820,7 +2872,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// /// /// - partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// uploads an image (required) @@ -2830,7 +2882,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2851,7 +2903,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2871,16 +2923,22 @@ public async Task UploadFileWithRequired : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/{petId}/uploadImageWithRequiredFile"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); + List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); multipartContentLocalVar.Add(new StreamContent(requiredFile)); + { + var streamContentLocalVar = new StreamContent(requiredFile.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile", requiredFile.FileName ?? "requiredFile"); + } if (additionalMetadata.IsSet) - formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2895,11 +2953,6 @@ public async Task UploadFileWithRequired "multipart/form-data" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - string[] acceptLocalVars = new string[] { "application/json", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" @@ -3040,5 +3093,283 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } + + partial void FormatUploadFiles(List files, ref long petId); + + /// + /// Validates the request parameters + /// + /// + /// + private void ValidateUploadFiles(List files) + { + if (files == null) + throw new ArgumentNullException(nameof(files)); + } + + /// + /// Processes the server response + /// + /// + /// + /// + private void AfterUploadFilesDefaultImplementation(IUploadFilesApiResponse apiResponseLocalVar, List files, long petId) + { + bool suppressDefaultLog = false; + AfterUploadFiles(ref suppressDefaultLog, apiResponseLocalVar, files, petId); + if (!suppressDefaultLog) + Logger.LogInformation("{0,-9} | {1} | {2}", (apiResponseLocalVar.DownloadedAt - apiResponseLocalVar.RequestedAt).TotalSeconds, apiResponseLocalVar.StatusCode, apiResponseLocalVar.Path); + } + + /// + /// Processes the server response + /// + /// + /// + /// + /// + partial void AfterUploadFiles(ref bool suppressDefaultLog, IUploadFilesApiResponse apiResponseLocalVar, List files, long petId); + + /// + /// Logs exceptions that occur while retrieving the server response + /// + /// + /// + /// + /// + /// + private void OnErrorUploadFilesDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId) + { + bool suppressDefaultLogLocalVar = false; + OnErrorUploadFiles(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, files, petId); + if (!suppressDefaultLogLocalVar) + Logger.LogError(exceptionLocalVar, "An error occurred while sending the request to the server."); + } + + /// + /// A partial method that gives developers a way to provide customized exception handling + /// + /// + /// + /// + /// + /// + /// + partial void OnErrorUploadFiles(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId); + + /// + /// uploads an images + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + try + { + return await UploadFilesAsync(files, petId, cancellationToken).ConfigureAwait(false); + } + catch (Exception) + { + return null; + } + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + UriBuilder uriBuilderLocalVar = new UriBuilder(); + + try + { + ValidateUploadFiles(files); + + FormatUploadFiles(files, ref petId); + + using (HttpRequestMessage httpRequestMessageLocalVar = new HttpRequestMessage()) + { + uriBuilderLocalVar.Host = HttpClient.BaseAddress!.Host; + uriBuilderLocalVar.Port = HttpClient.BaseAddress.Port; + uriBuilderLocalVar.Scheme = HttpClient.BaseAddress.Scheme; + uriBuilderLocalVar.Path = HttpClient.BaseAddress.AbsolutePath == "/" + ? "/pet/{petId}/uploadImages" + : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}/uploadImages"); + uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); + + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); + + httpRequestMessageLocalVar.Content = multipartContentLocalVar; + + List> formParameterLocalVars = new List>(); + + foreach (Org.OpenAPITools.Client.FileParameter fileParameterLocalVar in files) + { + var streamContentLocalVar = new StreamContent(fileParameterLocalVar.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "files", fileParameterLocalVar.FileName ?? "files"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); + + List tokenBaseLocalVars = new List(); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; + + OAuthToken oauthTokenLocalVar1 = (OAuthToken) await OauthTokenProvider.GetAsync(cancellation: cancellationToken).ConfigureAwait(false); + + tokenBaseLocalVars.Add(oauthTokenLocalVar1); + + oauthTokenLocalVar1.UseInHeader(httpRequestMessageLocalVar, ""); + + string[] contentTypes = new string[] { + "multipart/form-data" + }; + + string[] acceptLocalVars = new string[] { + "application/json" + }; + + IEnumerable acceptHeaderValuesLocalVar = ClientUtils.SelectHeaderAcceptArray(acceptLocalVars); + + foreach (var acceptLocalVar in acceptHeaderValuesLocalVar) + httpRequestMessageLocalVar.Headers.Accept.Add(acceptLocalVar); + + httpRequestMessageLocalVar.Method = HttpMethod.Post; + + DateTime requestedAtLocalVar = DateTime.UtcNow; + + using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false)) + { + ILogger apiResponseLoggerLocalVar = LoggerFactory.CreateLogger(); + UploadFilesApiResponse apiResponseLocalVar; + + switch ((int)httpResponseMessageLocalVar.StatusCode) { + default: { + string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + apiResponseLocalVar = new(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/pet/{petId}/uploadImages", requestedAtLocalVar, _jsonSerializerOptions); + + break; + } + } + + AfterUploadFilesDefaultImplementation(apiResponseLocalVar, files, petId); + + Events.ExecuteOnUploadFiles(apiResponseLocalVar); + + if (apiResponseLocalVar.StatusCode == (HttpStatusCode) 429) + foreach(TokenBase tokenBaseLocalVar in tokenBaseLocalVars) + tokenBaseLocalVar.BeginRateLimit(); + + return apiResponseLocalVar; + } + } + } + catch(Exception e) + { + OnErrorUploadFilesDefaultImplementation(e, "/pet/{petId}/uploadImages", uriBuilderLocalVar.Path, files, petId); + Events.ExecuteOnErrorUploadFiles(e); + throw; + } + } + + /// + /// The + /// + public partial class UploadFilesApiResponse : Org.OpenAPITools.Client.ApiResponse, IUploadFilesApiResponse + { + /// + /// The logger + /// + public ILogger Logger { get; } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, string rawContent, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, rawContent, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, System.IO.Stream contentStream, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, contentStream, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + partial void OnCreated(global::System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage); + + /// + /// Returns true if the response is 200 Ok + /// + /// + public bool IsOk => 200 == (int)StatusCode; + + /// + /// Deserializes the response if the response is 200 Ok + /// + /// + public Org.OpenAPITools.Model.ApiResponse? Ok() + { + // This logic may be modified with the AsModel.mustache template + return IsOk + ? System.Text.Json.JsonSerializer.Deserialize(RawContent, _jsonSerializerOptions) + : null; + } + + /// + /// Returns true if the response is 200 Ok and the deserialized response is not null + /// + /// + /// + public bool TryOk([NotNullWhen(true)]out Org.OpenAPITools.Model.ApiResponse? result) + { + result = null; + + try + { + result = Ok(); + } catch (Exception e) + { + OnDeserializationErrorDefaultImplementation(e, (HttpStatusCode)200); + } + + return result != null; + } + + private void OnDeserializationErrorDefaultImplementation(Exception exception, HttpStatusCode httpStatusCode) + { + bool suppressDefaultLog = false; + OnDeserializationError(ref suppressDefaultLog, exception, httpStatusCode); + if (!suppressDefaultLog) + Logger.LogError(exception, "An error occurred while deserializing the {code} response.", httpStatusCode); + } + + partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); + } } } diff --git a/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..77779fe7d75a --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,42 @@ +// +/* + * OpenAPI Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +#nullable enable + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string? FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string? fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net8/UseDateTimeForDate/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net8/UseDateTimeForDate/.openapi-generator/FILES index 5abbcf46f35c..e28da391730f 100644 --- a/samples/client/petstore/csharp/generichost/net8/UseDateTimeForDate/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net8/UseDateTimeForDate/.openapi-generator/FILES @@ -21,6 +21,7 @@ src/Org.OpenAPITools/Client/CookieContainer.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 diff --git a/samples/client/petstore/csharp/generichost/net8/UseDateTimeForDate/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net8/UseDateTimeForDate/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..11da1d925144 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net8/UseDateTimeForDate/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,42 @@ +// +/* + * OpenAPI Dates + * + * Thic spec contains endpoints with dates in different formats + * + * The version of the OpenAPI document: 1.0.0 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +#nullable enable + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string? FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string? fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/AllOf/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net9/AllOf/.openapi-generator/FILES index b9ab612bd8b5..46a8286dea29 100644 --- a/samples/client/petstore/csharp/generichost/net9/AllOf/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net9/AllOf/.openapi-generator/FILES @@ -25,6 +25,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 diff --git a/samples/client/petstore/csharp/generichost/net9/AllOf/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net9/AllOf/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..1913a3a0f2d9 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/AllOf/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,42 @@ +// +/* + * Example + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +#nullable enable + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string? FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string? fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/AnyOf/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net9/AnyOf/.openapi-generator/FILES index dc42a5d47091..072cc8408121 100644 --- a/samples/client/petstore/csharp/generichost/net9/AnyOf/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net9/AnyOf/.openapi-generator/FILES @@ -25,6 +25,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 diff --git a/samples/client/petstore/csharp/generichost/net9/AnyOf/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net9/AnyOf/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..e629f4afdaec --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/AnyOf/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,42 @@ +// +/* + * fruity + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 0.0.1 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +#nullable enable + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string? FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string? fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/AnyOfNoCompare/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net9/AnyOfNoCompare/.openapi-generator/FILES index dc42a5d47091..072cc8408121 100644 --- a/samples/client/petstore/csharp/generichost/net9/AnyOfNoCompare/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net9/AnyOfNoCompare/.openapi-generator/FILES @@ -25,6 +25,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 diff --git a/samples/client/petstore/csharp/generichost/net9/AnyOfNoCompare/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net9/AnyOfNoCompare/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..e629f4afdaec --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/AnyOfNoCompare/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,42 @@ +// +/* + * fruity + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 0.0.1 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +#nullable enable + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string? FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string? fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/FormModels/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net9/FormModels/.openapi-generator/FILES index a9823b3075fd..737d53400248 100644 --- a/samples/client/petstore/csharp/generichost/net9/FormModels/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/.openapi-generator/FILES @@ -165,6 +165,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/HttpSigningConfiguration.cs src/Org.OpenAPITools/Client/HttpSigningToken.cs diff --git a/samples/client/petstore/csharp/generichost/net9/FormModels/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net9/FormModels/api/openapi.yaml index a9ab8dd51c13..7017affc0b9c 100644 --- a/samples/client/petstore/csharp/generichost/net9/FormModels/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/api/openapi.yaml @@ -326,6 +326,40 @@ paths: summary: uploads an image tags: - pet + /pet/{petId}/uploadImages: + post: + description: "" + operationId: uploadFiles + parameters: + - description: ID of pet to update + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + multipart/form-data: + schema: + $ref: "#/components/schemas/uploadFiles_request" + required: true + responses: + "200": + content: + application/json: + schema: + $ref: "#/components/schemas/ApiResponse" + description: successful operation + security: + - petstore_auth: + - write:pets + - read:pets + summary: uploads an images + tags: + - pet /store/inventory: get: description: Returns a map of status codes to quantities @@ -2748,6 +2782,16 @@ components: format: binary type: string type: object + uploadFiles_request: + properties: + files: + items: + format: binary + type: string + type: array + required: + - files + type: object testEnumParameters_request_enum_form_string_array_inner: default: $ enum: diff --git a/samples/client/petstore/csharp/generichost/net9/FormModels/docs/apis/PetApi.md b/samples/client/petstore/csharp/generichost/net9/FormModels/docs/apis/PetApi.md index e32c1e31e089..59d4ef8e6df0 100644 --- a/samples/client/petstore/csharp/generichost/net9/FormModels/docs/apis/PetApi.md +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/docs/apis/PetApi.md @@ -13,6 +13,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* | [**UpdatePetWithForm**](PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data | | [**UploadFile**](PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image | | [**UploadFileWithRequiredFile**](PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) | +| [**UploadFiles**](PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images | # **AddPet** @@ -341,3 +342,38 @@ uploads an image (required) [[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + +# **UploadFiles** +> ApiResponse UploadFiles (List files, long petId) + +uploads an images + + +### Parameters + +| Name | Type | Description | Notes | +|------|------|-------------|-------| +| **files** | **List<System.IO.Stream>** | | | +| **petId** | **long** | ID of pet to update | | + +### Return type + +[**ApiResponse**](ApiResponse.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: multipart/form-data + - **Accept**: application/json + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | + +[[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + diff --git a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs index 495d785314c5..1924842cdbef 100644 --- a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs @@ -196,7 +196,7 @@ public async Task TestEndpointParametersAsyncTest() string patternWithoutDelimiter = default; byte[] varByte = default; double varDouble = default; - Client.Option binary = default; + Client.Option binary = default; Client.Option callback = default; Client.Option date = default; Client.Option dateTime = default; diff --git a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 1f1d7f6c4576..a4aa8f3e245d 100644 --- a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools.Test/Api/PetApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools.Test/Api/PetApiTests.cs @@ -137,7 +137,7 @@ public async Task UploadFileAsyncTest() { long petId = default; Client.Option additionalMetadata = default; - Client.Option file = default; + Client.Option file = default; var response = await _instance.UploadFileAsync(petId, additionalMetadata, file); var model = response.Ok(); Assert.IsType(model); @@ -150,11 +150,24 @@ public async Task UploadFileAsyncTest() public async Task UploadFileWithRequiredFileAsyncTest() { long petId = default; - System.IO.Stream requiredFile = default; + Org.OpenAPITools.Client.FileParameter requiredFile = default; Client.Option additionalMetadata = default; var response = await _instance.UploadFileWithRequiredFileAsync(petId, requiredFile, additionalMetadata); var model = response.Ok(); Assert.IsType(model); } + + /// + /// Test UploadFiles + /// + [Fact (Skip = "not implemented")] + public async Task UploadFilesAsyncTest() + { + List files = default; + long petId = default; + var response = await _instance.UploadFilesAsync(files, petId); + var model = response.Ok(); + Assert.IsType(model); + } } } diff --git a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Api/DefaultApi.cs index 3c26a27185e6..44d52e7e1090 100644 --- a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Api/DefaultApi.cs +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Api/DefaultApi.cs @@ -764,27 +764,19 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Api/FakeApi.cs b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Api/FakeApi.cs index 2a332dbf1eb9..0070617289e6 100644 --- a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Api/FakeApi.cs +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Api/FakeApi.cs @@ -330,7 +330,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <> - Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -354,7 +354,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <> - Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// To test enum parameters @@ -4080,7 +4080,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); + partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); /// /// Validates the request parameters @@ -4092,7 +4092,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) + private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) { if (patternWithoutDelimiter == null) throw new ArgumentNullException(nameof(patternWithoutDelimiter)); @@ -4131,7 +4131,7 @@ private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte /// /// /// - private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLog = false; AfterTestEndpointParameters(ref suppressDefaultLog, apiResponseLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4158,7 +4158,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Logs exceptions that occur while retrieving the server response @@ -4180,7 +4180,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLogLocalVar = false; OnErrorTestEndpointParameters(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4209,7 +4209,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// /// /// - partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -4230,7 +4230,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -4262,7 +4262,7 @@ public async Task TestEndpointParametersOrDe /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -4281,14 +4281,8 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("number", ClientUtils.ParameterToString(number))); formParameterLocalVars.Add(new KeyValuePair("pattern_without_delimiter", ClientUtils.ParameterToString(patternWithoutDelimiter))); @@ -4298,7 +4292,7 @@ public async Task TestEndpointParametersAsyn formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.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."); if (callback.IsSet) formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); @@ -4327,6 +4321,9 @@ public async Task TestEndpointParametersAsyn if (varString.IsSet) formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4340,11 +4337,6 @@ public async Task TestEndpointParametersAsyn "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -4625,29 +4617,23 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (enumFormString.IsSet) + if (enumFormString.IsSet) formParameterLocalVars.Add(new KeyValuePair("enum_form_string", ClientUtils.ParameterToString(enumFormString.Value))); if (enumFormStringArray.IsSet) formParameterLocalVars.Add(new KeyValuePair("enum_form_string_array", ClientUtils.ParameterToString(enumFormStringArray.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Get; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -5534,29 +5520,21 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("param", ClientUtils.ParameterToString(param))); formParameterLocalVars.Add(new KeyValuePair("param2", ClientUtils.ParameterToString(param2))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Get; DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Api/PetApi.cs b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Api/PetApi.cs index d07d16c30828..fd403446d9a6 100644 --- a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Api/PetApi.cs +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Api/PetApi.cs @@ -216,7 +216,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image @@ -229,7 +229,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -243,7 +243,7 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -256,7 +256,32 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); } /// @@ -415,6 +440,18 @@ public interface IUploadFileWithRequiredFileApiResponse : Org.OpenAPITools.Clien bool IsOk { get; } } + /// + /// The + /// + public interface IUploadFilesApiResponse : Org.OpenAPITools.Client.IApiResponse, IOk + { + /// + /// Returns true if the response is 200 Ok + /// + /// + bool IsOk { get; } + } + /// /// Represents a collection of functions to interact with the API endpoints /// @@ -599,6 +636,26 @@ internal void ExecuteOnErrorUploadFileWithRequiredFile(Exception exception) { OnErrorUploadFileWithRequiredFile?.Invoke(this, new ExceptionEventArgs(exception)); } + + /// + /// The event raised after the server response + /// + public event EventHandler OnUploadFiles; + + /// + /// The event raised after an error querying the server + /// + public event EventHandler OnErrorUploadFiles; + + internal void ExecuteOnUploadFiles(PetApi.UploadFilesApiResponse apiResponse) + { + OnUploadFiles?.Invoke(this, new ApiResponseEventArgs(apiResponse)); + } + + internal void ExecuteOnErrorUploadFiles(Exception exception) + { + OnErrorUploadFiles?.Invoke(this, new ExceptionEventArgs(exception)); + } } /// @@ -2330,18 +2387,17 @@ public async Task UpdatePetWithFormAsync(long pet : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (name.IsSet) + if (name.IsSet) formParameterLocalVars.Add(new KeyValuePair("name", ClientUtils.ParameterToString(name.Value))); if (status.IsSet) formParameterLocalVars.Add(new KeyValuePair("status", ClientUtils.ParameterToString(status.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2355,11 +2411,6 @@ public async Task UpdatePetWithFormAsync(long pet "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -2459,7 +2510,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); + partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); /// /// Validates the request parameters @@ -2467,7 +2518,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFile(Option additionalMetadata, Option file) + private void ValidateUploadFile(Option additionalMetadata, Option file) { if (additionalMetadata.IsSet && additionalMetadata.Value == null) throw new ArgumentNullException(nameof(additionalMetadata)); @@ -2483,7 +2534,7 @@ private void ValidateUploadFile(Option additionalMetadata, Option /// /// - private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) + private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLog = false; AfterUploadFile(ref suppressDefaultLog, apiResponseLocalVar, petId, additionalMetadata, file); @@ -2499,7 +2550,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); + partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); /// /// Logs exceptions that occur while retrieving the server response @@ -2510,7 +2561,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) + private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, additionalMetadata, file); @@ -2528,7 +2579,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// /// /// - partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); + partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); /// /// uploads an image @@ -2538,7 +2589,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2559,7 +2610,7 @@ public async Task UploadFileOrDefaultAsync(long petId, O /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2579,17 +2630,23 @@ public async Task UploadFileAsync(long petId, Option> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (additionalMetadata.IsSet) + if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); if (file.IsSet) - multipartContentLocalVar.Add(new StreamContent(file.Value)); + { + var streamContentLocalVar = new StreamContent(file.Value.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "file", file.Value.FileName ?? "file"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2604,11 +2661,6 @@ public async Task UploadFileAsync(long petId, Option additionalMetadata); + partial void FormatUploadFileWithRequiredFile(ref long petId, ref Org.OpenAPITools.Client.FileParameter requiredFile, ref Option additionalMetadata); /// /// Validates the request parameters @@ -2757,7 +2809,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, Option additionalMetadata) + private void ValidateUploadFileWithRequiredFile(Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { if (requiredFile == null) throw new ArgumentNullException(nameof(requiredFile)); @@ -2773,7 +2825,7 @@ private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, O /// /// /// - private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLog = false; AfterUploadFileWithRequiredFile(ref suppressDefaultLog, apiResponseLocalVar, petId, requiredFile, additionalMetadata); @@ -2789,7 +2841,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// Logs exceptions that occur while retrieving the server response @@ -2800,7 +2852,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFileWithRequiredFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, requiredFile, additionalMetadata); @@ -2818,7 +2870,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// /// /// - partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// uploads an image (required) @@ -2828,7 +2880,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2849,7 +2901,7 @@ public async Task UploadFileWithRequired /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2869,17 +2921,23 @@ public async Task UploadFileWithRequired : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/{petId}/uploadImageWithRequiredFile"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); multipartContentLocalVar.Add(new StreamContent(requiredFile)); + { + var streamContentLocalVar = new StreamContent(requiredFile.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile", requiredFile.FileName ?? "requiredFile"); + } if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2893,11 +2951,6 @@ public async Task UploadFileWithRequired "multipart/form-data" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - string[] acceptLocalVars = new string[] { "application/json", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" @@ -3038,5 +3091,283 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } + + partial void FormatUploadFiles(List files, ref long petId); + + /// + /// Validates the request parameters + /// + /// + /// + private void ValidateUploadFiles(List files) + { + if (files == null) + throw new ArgumentNullException(nameof(files)); + } + + /// + /// Processes the server response + /// + /// + /// + /// + private void AfterUploadFilesDefaultImplementation(IUploadFilesApiResponse apiResponseLocalVar, List files, long petId) + { + bool suppressDefaultLog = false; + AfterUploadFiles(ref suppressDefaultLog, apiResponseLocalVar, files, petId); + if (!suppressDefaultLog) + Logger.LogInformation("{0,-9} | {1} | {2}", (apiResponseLocalVar.DownloadedAt - apiResponseLocalVar.RequestedAt).TotalSeconds, apiResponseLocalVar.StatusCode, apiResponseLocalVar.Path); + } + + /// + /// Processes the server response + /// + /// + /// + /// + /// + partial void AfterUploadFiles(ref bool suppressDefaultLog, IUploadFilesApiResponse apiResponseLocalVar, List files, long petId); + + /// + /// Logs exceptions that occur while retrieving the server response + /// + /// + /// + /// + /// + /// + private void OnErrorUploadFilesDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId) + { + bool suppressDefaultLogLocalVar = false; + OnErrorUploadFiles(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, files, petId); + if (!suppressDefaultLogLocalVar) + Logger.LogError(exceptionLocalVar, "An error occurred while sending the request to the server."); + } + + /// + /// A partial method that gives developers a way to provide customized exception handling + /// + /// + /// + /// + /// + /// + /// + partial void OnErrorUploadFiles(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId); + + /// + /// uploads an images + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + try + { + return await UploadFilesAsync(files, petId, cancellationToken).ConfigureAwait(false); + } + catch (Exception) + { + return null; + } + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + UriBuilder uriBuilderLocalVar = new UriBuilder(); + + try + { + ValidateUploadFiles(files); + + FormatUploadFiles(files, ref petId); + + using (HttpRequestMessage httpRequestMessageLocalVar = new HttpRequestMessage()) + { + uriBuilderLocalVar.Host = HttpClient.BaseAddress.Host; + uriBuilderLocalVar.Port = HttpClient.BaseAddress.Port; + uriBuilderLocalVar.Scheme = HttpClient.BaseAddress.Scheme; + uriBuilderLocalVar.Path = HttpClient.BaseAddress.AbsolutePath == "/" + ? "/pet/{petId}/uploadImages" + : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}/uploadImages"); + uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); + + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); + + httpRequestMessageLocalVar.Content = multipartContentLocalVar; + + List> formParameterLocalVars = new List>(); + + foreach (Org.OpenAPITools.Client.FileParameter fileParameterLocalVar in files) + { + var streamContentLocalVar = new StreamContent(fileParameterLocalVar.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "files", fileParameterLocalVar.FileName ?? "files"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); + + List tokenBaseLocalVars = new List(); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; + + OAuthToken oauthTokenLocalVar1 = (OAuthToken) await OauthTokenProvider.GetAsync(cancellation: cancellationToken).ConfigureAwait(false); + + tokenBaseLocalVars.Add(oauthTokenLocalVar1); + + oauthTokenLocalVar1.UseInHeader(httpRequestMessageLocalVar, ""); + + string[] contentTypes = new string[] { + "multipart/form-data" + }; + + string[] acceptLocalVars = new string[] { + "application/json" + }; + + IEnumerable acceptHeaderValuesLocalVar = ClientUtils.SelectHeaderAcceptArray(acceptLocalVars); + + foreach (var acceptLocalVar in acceptHeaderValuesLocalVar) + httpRequestMessageLocalVar.Headers.Accept.Add(acceptLocalVar); + + httpRequestMessageLocalVar.Method = HttpMethod.Post; + + DateTime requestedAtLocalVar = DateTime.UtcNow; + + using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false)) + { + ILogger apiResponseLoggerLocalVar = LoggerFactory.CreateLogger(); + UploadFilesApiResponse apiResponseLocalVar; + + switch ((int)httpResponseMessageLocalVar.StatusCode) { + default: { + string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + apiResponseLocalVar = new(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/pet/{petId}/uploadImages", requestedAtLocalVar, _jsonSerializerOptions); + + break; + } + } + + AfterUploadFilesDefaultImplementation(apiResponseLocalVar, files, petId); + + Events.ExecuteOnUploadFiles(apiResponseLocalVar); + + if (apiResponseLocalVar.StatusCode == (HttpStatusCode) 429) + foreach(TokenBase tokenBaseLocalVar in tokenBaseLocalVars) + tokenBaseLocalVar.BeginRateLimit(); + + return apiResponseLocalVar; + } + } + } + catch(Exception e) + { + OnErrorUploadFilesDefaultImplementation(e, "/pet/{petId}/uploadImages", uriBuilderLocalVar.Path, files, petId); + Events.ExecuteOnErrorUploadFiles(e); + throw; + } + } + + /// + /// The + /// + public partial class UploadFilesApiResponse : Org.OpenAPITools.Client.ApiResponse, IUploadFilesApiResponse + { + /// + /// The logger + /// + public ILogger Logger { get; } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, string rawContent, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, rawContent, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, System.IO.Stream contentStream, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, contentStream, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + partial void OnCreated(global::System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage); + + /// + /// Returns true if the response is 200 Ok + /// + /// + public bool IsOk => 200 == (int)StatusCode; + + /// + /// Deserializes the response if the response is 200 Ok + /// + /// + public Org.OpenAPITools.Model.ApiResponse Ok() + { + // This logic may be modified with the AsModel.mustache template + return IsOk + ? System.Text.Json.JsonSerializer.Deserialize(RawContent, _jsonSerializerOptions) + : null; + } + + /// + /// Returns true if the response is 200 Ok and the deserialized response is not null + /// + /// + /// + public bool TryOk([NotNullWhen(true)]out Org.OpenAPITools.Model.ApiResponse result) + { + result = null; + + try + { + result = Ok(); + } catch (Exception e) + { + OnDeserializationErrorDefaultImplementation(e, (HttpStatusCode)200); + } + + return result != null; + } + + private void OnDeserializationErrorDefaultImplementation(Exception exception, HttpStatusCode httpStatusCode) + { + bool suppressDefaultLog = false; + OnDeserializationError(ref suppressDefaultLog, exception, httpStatusCode); + if (!suppressDefaultLog) + Logger.LogError(exception, "An error occurred while deserializing the {code} response.", httpStatusCode); + } + + partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); + } } } diff --git a/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..6150dbcf4774 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,40 @@ +// +/* + * OpenAPI Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/.openapi-generator/FILES index ab28c754b4b1..a3e02b328e0a 100644 --- a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/.openapi-generator/FILES @@ -140,6 +140,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/HttpSigningConfiguration.cs src/Org.OpenAPITools/Client/HttpSigningToken.cs diff --git a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/api/openapi.yaml index d8106a5755fc..ca451f3fb832 100644 --- a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/api/openapi.yaml @@ -331,6 +331,40 @@ paths: summary: uploads an image tags: - pet + /pet/{petId}/uploadImages: + post: + description: "" + operationId: uploadFiles + parameters: + - description: ID of pet to update + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + multipart/form-data: + schema: + $ref: "#/components/schemas/uploadFiles_request" + required: true + responses: + "200": + content: + application/json: + schema: + $ref: "#/components/schemas/ApiResponse" + description: successful operation + security: + - petstore_auth: + - write:pets + - read:pets + summary: uploads an images + tags: + - pet /store/inventory: get: description: Returns a map of status codes to quantities @@ -2924,6 +2958,16 @@ components: format: binary type: string type: object + uploadFiles_request: + properties: + files: + items: + format: binary + type: string + type: array + required: + - files + type: object testEnumParameters_request: properties: enum_form_string_array: diff --git a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/docs/apis/PetApi.md b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/docs/apis/PetApi.md index 2826ea00f728..b42ee516b313 100644 --- a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/docs/apis/PetApi.md +++ b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/docs/apis/PetApi.md @@ -13,6 +13,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* | [**UpdatePetWithForm**](PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data | | [**UploadFile**](PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image | | [**UploadFileWithRequiredFile**](PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) | +| [**UploadFiles**](PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images | # **AddPet** @@ -341,3 +342,38 @@ uploads an image (required) [[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + +# **UploadFiles** +> ApiResponse UploadFiles (List files, long petId) + +uploads an images + + +### Parameters + +| Name | Type | Description | Notes | +|------|------|-------------|-------| +| **files** | **List<System.IO.Stream>** | | | +| **petId** | **long** | ID of pet to update | | + +### Return type + +[**ApiResponse**](ApiResponse.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: multipart/form-data + - **Accept**: application/json + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | + +[[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + diff --git a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs index 406dbc964a6d..d207bb93dc69 100644 --- a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs @@ -196,7 +196,7 @@ public async Task TestEndpointParametersAsyncTest() string patternWithoutDelimiter = default!; byte[] varByte = default!; double varDouble = default!; - Client.Option binary = default!; + Client.Option binary = default!; Client.Option callback = default!; Client.Option date = default!; Client.Option dateTime = default!; diff --git a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 49e7b21b53c2..6bb1f953987c 100644 --- a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools.Test/Api/PetApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools.Test/Api/PetApiTests.cs @@ -137,7 +137,7 @@ public async Task UploadFileAsyncTest() { long petId = default!; Client.Option additionalMetadata = default!; - Client.Option file = default!; + Client.Option file = default!; var response = await _instance.UploadFileAsync(petId, additionalMetadata, file); var model = response.Ok(); Assert.IsType(model); @@ -150,11 +150,24 @@ public async Task UploadFileAsyncTest() public async Task UploadFileWithRequiredFileAsyncTest() { long petId = default!; - System.IO.Stream requiredFile = default!; + Org.OpenAPITools.Client.FileParameter requiredFile = default!; Client.Option additionalMetadata = default!; var response = await _instance.UploadFileWithRequiredFileAsync(petId, requiredFile, additionalMetadata); var model = response.Ok(); Assert.IsType(model); } + + /// + /// Test UploadFiles + /// + [Fact (Skip = "not implemented")] + public async Task UploadFilesAsyncTest() + { + List files = default!; + long petId = default!; + var response = await _instance.UploadFilesAsync(files, petId); + var model = response.Ok(); + Assert.IsType(model); + } } } diff --git a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Api/DefaultApi.cs index 2391c7e1ee03..46b798fe32ca 100644 --- a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Api/DefaultApi.cs +++ b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Api/DefaultApi.cs @@ -766,15 +766,12 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + List> formParameterLocalVars = new List>(); - httpRequestMessageLocalVar.Content = multipartContentLocalVar; + formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); - List> formParameterLocalVars = new List>(); - - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -782,11 +779,6 @@ public async Task GetCountryAsync(string country, System "application/x-www-form-urlencoded" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Api/FakeApi.cs b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Api/FakeApi.cs index 262a94ef2520..54a1c8c85360 100644 --- a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Api/FakeApi.cs +++ b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Api/FakeApi.cs @@ -332,7 +332,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <> - Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -356,7 +356,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <?> - Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// To test enum parameters @@ -4082,7 +4082,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); + partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); /// /// Validates the request parameters @@ -4094,7 +4094,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) + private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) { if (patternWithoutDelimiter == null) throw new ArgumentNullException(nameof(patternWithoutDelimiter)); @@ -4133,7 +4133,7 @@ private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte /// /// /// - private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLog = false; AfterTestEndpointParameters(ref suppressDefaultLog, apiResponseLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4160,7 +4160,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Logs exceptions that occur while retrieving the server response @@ -4182,7 +4182,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLogLocalVar = false; OnErrorTestEndpointParameters(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4211,7 +4211,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// /// /// - partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -4232,7 +4232,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -4264,7 +4264,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -4283,51 +4283,48 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + List> formParameterLocalVars = new List>(); - httpRequestMessageLocalVar.Content = multipartContentLocalVar; + formParameterLocalVars.Add(new KeyValuePair("number", ClientUtils.ParameterToString(number))); - List> formParameterLocalVars = new List>(); + formParameterLocalVars.Add(new KeyValuePair("pattern_without_delimiter", ClientUtils.ParameterToString(patternWithoutDelimiter))); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + formParameterLocalVars.Add(new KeyValuePair("byte", ClientUtils.ParameterToString(varByte))); - formParameterLocalVars.Add(new KeyValuePair("number", ClientUtils.ParameterToString(number))); - - formParameterLocalVars.Add(new KeyValuePair("pattern_without_delimiter", ClientUtils.ParameterToString(patternWithoutDelimiter))); - - formParameterLocalVars.Add(new KeyValuePair("byte", ClientUtils.ParameterToString(varByte))); - - formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); + formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.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."); if (callback.IsSet) - formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); + formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); if (date.IsSet) - formParameterLocalVars.Add(new KeyValuePair("date", ClientUtils.ParameterToString(date.Value))); + formParameterLocalVars.Add(new KeyValuePair("date", ClientUtils.ParameterToString(date.Value))); if (dateTime.IsSet) - formParameterLocalVars.Add(new KeyValuePair("dateTime", ClientUtils.ParameterToString(dateTime.Value))); + formParameterLocalVars.Add(new KeyValuePair("dateTime", ClientUtils.ParameterToString(dateTime.Value))); if (int32.IsSet) - formParameterLocalVars.Add(new KeyValuePair("int32", ClientUtils.ParameterToString(int32.Value))); + formParameterLocalVars.Add(new KeyValuePair("int32", ClientUtils.ParameterToString(int32.Value))); if (int64.IsSet) - formParameterLocalVars.Add(new KeyValuePair("int64", ClientUtils.ParameterToString(int64.Value))); + formParameterLocalVars.Add(new KeyValuePair("int64", ClientUtils.ParameterToString(int64.Value))); if (integer.IsSet) - formParameterLocalVars.Add(new KeyValuePair("integer", ClientUtils.ParameterToString(integer.Value))); + formParameterLocalVars.Add(new KeyValuePair("integer", ClientUtils.ParameterToString(integer.Value))); if (password.IsSet) - formParameterLocalVars.Add(new KeyValuePair("password", ClientUtils.ParameterToString(password.Value))); + formParameterLocalVars.Add(new KeyValuePair("password", ClientUtils.ParameterToString(password.Value))); if (varFloat.IsSet) - formParameterLocalVars.Add(new KeyValuePair("float", ClientUtils.ParameterToString(varFloat.Value))); + formParameterLocalVars.Add(new KeyValuePair("float", ClientUtils.ParameterToString(varFloat.Value))); if (varString.IsSet) - formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4342,11 +4339,6 @@ public async Task TestEndpointParametersAsyn "application/x-www-form-urlencoded" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -4639,17 +4631,16 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); + List> formParameterLocalVars = new List>(); - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - - List> formParameterLocalVars = new List>(); - - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (enumFormString.IsSet) - formParameterLocalVars.Add(new KeyValuePair("enum_form_string", ClientUtils.ParameterToString(enumFormString.Value))); + if (enumFormString.IsSet) + formParameterLocalVars.Add(new KeyValuePair("enum_form_string", ClientUtils.ParameterToString(enumFormString.Value))); if (enumFormStringArray.IsSet) - formParameterLocalVars.Add(new KeyValuePair("enum_form_string_array", ClientUtils.ParameterToString(enumFormStringArray.Value))); + formParameterLocalVars.Add(new KeyValuePair("enum_form_string_array", ClientUtils.ParameterToString(enumFormStringArray.Value))); + + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4657,11 +4648,6 @@ public async Task TestEnumParametersAsync(Option "application/x-www-form-urlencoded" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Get; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -5548,17 +5534,14 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; + List> formParameterLocalVars = new List>(); - List> formParameterLocalVars = new List>(); + formParameterLocalVars.Add(new KeyValuePair("param", ClientUtils.ParameterToString(param))); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + formParameterLocalVars.Add(new KeyValuePair("param2", ClientUtils.ParameterToString(param2))); - formParameterLocalVars.Add(new KeyValuePair("param", ClientUtils.ParameterToString(param))); - - formParameterLocalVars.Add(new KeyValuePair("param2", ClientUtils.ParameterToString(param2))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -5566,11 +5549,6 @@ public async Task TestJsonFormDataAsync(string par "application/x-www-form-urlencoded" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Get; DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Api/PetApi.cs b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Api/PetApi.cs index 2d7e4dab0b84..c5de9cd55ad1 100644 --- a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Api/PetApi.cs +++ b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Api/PetApi.cs @@ -218,7 +218,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image @@ -231,7 +231,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <?> - Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -245,7 +245,7 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -258,7 +258,32 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <?> - Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <?> + Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); } /// @@ -417,6 +442,18 @@ public interface IUploadFileWithRequiredFileApiResponse : Org.OpenAPITools.Clien bool IsOk { get; } } + /// + /// The + /// + public interface IUploadFilesApiResponse : Org.OpenAPITools.Client.IApiResponse, IOk + { + /// + /// Returns true if the response is 200 Ok + /// + /// + bool IsOk { get; } + } + /// /// Represents a collection of functions to interact with the API endpoints /// @@ -601,6 +638,26 @@ internal void ExecuteOnErrorUploadFileWithRequiredFile(Exception exception) { OnErrorUploadFileWithRequiredFile?.Invoke(this, new ExceptionEventArgs(exception)); } + + /// + /// The event raised after the server response + /// + public event EventHandler? OnUploadFiles; + + /// + /// The event raised after an error querying the server + /// + public event EventHandler? OnErrorUploadFiles; + + internal void ExecuteOnUploadFiles(PetApi.UploadFilesApiResponse apiResponse) + { + OnUploadFiles?.Invoke(this, new ApiResponseEventArgs(apiResponse)); + } + + internal void ExecuteOnErrorUploadFiles(Exception exception) + { + OnErrorUploadFiles?.Invoke(this, new ExceptionEventArgs(exception)); + } } /// @@ -2332,17 +2389,16 @@ public async Task UpdatePetWithFormAsync(long pet : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - - List> formParameterLocalVars = new List>(); + List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (name.IsSet) - formParameterLocalVars.Add(new KeyValuePair("name", ClientUtils.ParameterToString(name.Value))); + if (name.IsSet) + formParameterLocalVars.Add(new KeyValuePair("name", ClientUtils.ParameterToString(name.Value))); if (status.IsSet) - formParameterLocalVars.Add(new KeyValuePair("status", ClientUtils.ParameterToString(status.Value))); + formParameterLocalVars.Add(new KeyValuePair("status", ClientUtils.ParameterToString(status.Value))); + + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2357,11 +2413,6 @@ public async Task UpdatePetWithFormAsync(long pet "application/x-www-form-urlencoded" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -2461,7 +2512,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); + partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); /// /// Validates the request parameters @@ -2469,7 +2520,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFile(Option additionalMetadata, Option file) + private void ValidateUploadFile(Option additionalMetadata, Option file) { if (additionalMetadata.IsSet && additionalMetadata.Value == null) throw new ArgumentNullException(nameof(additionalMetadata)); @@ -2485,7 +2536,7 @@ private void ValidateUploadFile(Option additionalMetadata, Option /// /// - private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) + private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLog = false; AfterUploadFile(ref suppressDefaultLog, apiResponseLocalVar, petId, additionalMetadata, file); @@ -2501,7 +2552,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); + partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); /// /// Logs exceptions that occur while retrieving the server response @@ -2512,7 +2563,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) + private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, additionalMetadata, file); @@ -2530,7 +2581,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// /// /// - partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); + partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); /// /// uploads an image @@ -2540,7 +2591,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2561,7 +2612,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2581,17 +2632,23 @@ public async Task UploadFileAsync(long petId, Option> formParameterLocalVars = new List>(); + List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (additionalMetadata.IsSet) - formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + if (additionalMetadata.IsSet) + formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); if (file.IsSet) - multipartContentLocalVar.Add(new StreamContent(file.Value)); + { + var streamContentLocalVar = new StreamContent(file.Value.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "file", file.Value.FileName ?? "file"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2606,11 +2663,6 @@ public async Task UploadFileAsync(long petId, Option additionalMetadata); + partial void FormatUploadFileWithRequiredFile(ref long petId, ref Org.OpenAPITools.Client.FileParameter requiredFile, ref Option additionalMetadata); /// /// Validates the request parameters @@ -2759,7 +2811,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, Option additionalMetadata) + private void ValidateUploadFileWithRequiredFile(Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { if (requiredFile == null) throw new ArgumentNullException(nameof(requiredFile)); @@ -2775,7 +2827,7 @@ private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, O /// /// /// - private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLog = false; AfterUploadFileWithRequiredFile(ref suppressDefaultLog, apiResponseLocalVar, petId, requiredFile, additionalMetadata); @@ -2791,7 +2843,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// Logs exceptions that occur while retrieving the server response @@ -2802,7 +2854,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFileWithRequiredFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, requiredFile, additionalMetadata); @@ -2820,7 +2872,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// /// /// - partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// uploads an image (required) @@ -2830,7 +2882,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2851,7 +2903,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2871,16 +2923,22 @@ public async Task UploadFileWithRequired : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/{petId}/uploadImageWithRequiredFile"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); + List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); multipartContentLocalVar.Add(new StreamContent(requiredFile)); + { + var streamContentLocalVar = new StreamContent(requiredFile.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile", requiredFile.FileName ?? "requiredFile"); + } if (additionalMetadata.IsSet) - formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2895,11 +2953,6 @@ public async Task UploadFileWithRequired "multipart/form-data" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - string[] acceptLocalVars = new string[] { "application/json", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" @@ -3040,5 +3093,283 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } + + partial void FormatUploadFiles(List files, ref long petId); + + /// + /// Validates the request parameters + /// + /// + /// + private void ValidateUploadFiles(List files) + { + if (files == null) + throw new ArgumentNullException(nameof(files)); + } + + /// + /// Processes the server response + /// + /// + /// + /// + private void AfterUploadFilesDefaultImplementation(IUploadFilesApiResponse apiResponseLocalVar, List files, long petId) + { + bool suppressDefaultLog = false; + AfterUploadFiles(ref suppressDefaultLog, apiResponseLocalVar, files, petId); + if (!suppressDefaultLog) + Logger.LogInformation("{0,-9} | {1} | {2}", (apiResponseLocalVar.DownloadedAt - apiResponseLocalVar.RequestedAt).TotalSeconds, apiResponseLocalVar.StatusCode, apiResponseLocalVar.Path); + } + + /// + /// Processes the server response + /// + /// + /// + /// + /// + partial void AfterUploadFiles(ref bool suppressDefaultLog, IUploadFilesApiResponse apiResponseLocalVar, List files, long petId); + + /// + /// Logs exceptions that occur while retrieving the server response + /// + /// + /// + /// + /// + /// + private void OnErrorUploadFilesDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId) + { + bool suppressDefaultLogLocalVar = false; + OnErrorUploadFiles(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, files, petId); + if (!suppressDefaultLogLocalVar) + Logger.LogError(exceptionLocalVar, "An error occurred while sending the request to the server."); + } + + /// + /// A partial method that gives developers a way to provide customized exception handling + /// + /// + /// + /// + /// + /// + /// + partial void OnErrorUploadFiles(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId); + + /// + /// uploads an images + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + try + { + return await UploadFilesAsync(files, petId, cancellationToken).ConfigureAwait(false); + } + catch (Exception) + { + return null; + } + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + UriBuilder uriBuilderLocalVar = new UriBuilder(); + + try + { + ValidateUploadFiles(files); + + FormatUploadFiles(files, ref petId); + + using (HttpRequestMessage httpRequestMessageLocalVar = new HttpRequestMessage()) + { + uriBuilderLocalVar.Host = HttpClient.BaseAddress!.Host; + uriBuilderLocalVar.Port = HttpClient.BaseAddress.Port; + uriBuilderLocalVar.Scheme = HttpClient.BaseAddress.Scheme; + uriBuilderLocalVar.Path = HttpClient.BaseAddress.AbsolutePath == "/" + ? "/pet/{petId}/uploadImages" + : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}/uploadImages"); + uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); + + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); + + httpRequestMessageLocalVar.Content = multipartContentLocalVar; + + List> formParameterLocalVars = new List>(); + + foreach (Org.OpenAPITools.Client.FileParameter fileParameterLocalVar in files) + { + var streamContentLocalVar = new StreamContent(fileParameterLocalVar.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "files", fileParameterLocalVar.FileName ?? "files"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); + + List tokenBaseLocalVars = new List(); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; + + OAuthToken oauthTokenLocalVar1 = (OAuthToken) await OauthTokenProvider.GetAsync(cancellation: cancellationToken).ConfigureAwait(false); + + tokenBaseLocalVars.Add(oauthTokenLocalVar1); + + oauthTokenLocalVar1.UseInHeader(httpRequestMessageLocalVar, ""); + + string[] contentTypes = new string[] { + "multipart/form-data" + }; + + string[] acceptLocalVars = new string[] { + "application/json" + }; + + IEnumerable acceptHeaderValuesLocalVar = ClientUtils.SelectHeaderAcceptArray(acceptLocalVars); + + foreach (var acceptLocalVar in acceptHeaderValuesLocalVar) + httpRequestMessageLocalVar.Headers.Accept.Add(acceptLocalVar); + + httpRequestMessageLocalVar.Method = HttpMethod.Post; + + DateTime requestedAtLocalVar = DateTime.UtcNow; + + using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false)) + { + ILogger apiResponseLoggerLocalVar = LoggerFactory.CreateLogger(); + UploadFilesApiResponse apiResponseLocalVar; + + switch ((int)httpResponseMessageLocalVar.StatusCode) { + default: { + string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + apiResponseLocalVar = new(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/pet/{petId}/uploadImages", requestedAtLocalVar, _jsonSerializerOptions); + + break; + } + } + + AfterUploadFilesDefaultImplementation(apiResponseLocalVar, files, petId); + + Events.ExecuteOnUploadFiles(apiResponseLocalVar); + + if (apiResponseLocalVar.StatusCode == (HttpStatusCode) 429) + foreach(TokenBase tokenBaseLocalVar in tokenBaseLocalVars) + tokenBaseLocalVar.BeginRateLimit(); + + return apiResponseLocalVar; + } + } + } + catch(Exception e) + { + OnErrorUploadFilesDefaultImplementation(e, "/pet/{petId}/uploadImages", uriBuilderLocalVar.Path, files, petId); + Events.ExecuteOnErrorUploadFiles(e); + throw; + } + } + + /// + /// The + /// + public partial class UploadFilesApiResponse : Org.OpenAPITools.Client.ApiResponse, IUploadFilesApiResponse + { + /// + /// The logger + /// + public ILogger Logger { get; } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, string rawContent, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, rawContent, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, System.IO.Stream contentStream, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, contentStream, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + partial void OnCreated(global::System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage); + + /// + /// Returns true if the response is 200 Ok + /// + /// + public bool IsOk => 200 == (int)StatusCode; + + /// + /// Deserializes the response if the response is 200 Ok + /// + /// + public Org.OpenAPITools.Model.ApiResponse? Ok() + { + // This logic may be modified with the AsModel.mustache template + return IsOk + ? System.Text.Json.JsonSerializer.Deserialize(RawContent, _jsonSerializerOptions) + : null; + } + + /// + /// Returns true if the response is 200 Ok and the deserialized response is not null + /// + /// + /// + public bool TryOk([NotNullWhen(true)]out Org.OpenAPITools.Model.ApiResponse? result) + { + result = null; + + try + { + result = Ok(); + } catch (Exception e) + { + OnDeserializationErrorDefaultImplementation(e, (HttpStatusCode)200); + } + + return result != null; + } + + private void OnDeserializationErrorDefaultImplementation(Exception exception, HttpStatusCode httpStatusCode) + { + bool suppressDefaultLog = false; + OnDeserializationError(ref suppressDefaultLog, exception, httpStatusCode); + if (!suppressDefaultLog) + Logger.LogError(exception, "An error occurred while deserializing the {code} response.", httpStatusCode); + } + + partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); + } } } diff --git a/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..77779fe7d75a --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,42 @@ +// +/* + * OpenAPI Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +#nullable enable + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string? FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string? fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/OneOf/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net9/OneOf/.openapi-generator/FILES index a36efde4422e..cfb76c7ed0ac 100644 --- a/samples/client/petstore/csharp/generichost/net9/OneOf/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net9/OneOf/.openapi-generator/FILES @@ -26,6 +26,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 diff --git a/samples/client/petstore/csharp/generichost/net9/OneOf/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net9/OneOf/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..e629f4afdaec --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/OneOf/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,42 @@ +// +/* + * fruity + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 0.0.1 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +#nullable enable + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string? FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string? fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/Petstore/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net9/Petstore/.openapi-generator/FILES index ab28c754b4b1..a3e02b328e0a 100644 --- a/samples/client/petstore/csharp/generichost/net9/Petstore/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net9/Petstore/.openapi-generator/FILES @@ -140,6 +140,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/HttpSigningConfiguration.cs src/Org.OpenAPITools/Client/HttpSigningToken.cs diff --git a/samples/client/petstore/csharp/generichost/net9/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net9/Petstore/api/openapi.yaml index d8106a5755fc..ca451f3fb832 100644 --- a/samples/client/petstore/csharp/generichost/net9/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net9/Petstore/api/openapi.yaml @@ -331,6 +331,40 @@ paths: summary: uploads an image tags: - pet + /pet/{petId}/uploadImages: + post: + description: "" + operationId: uploadFiles + parameters: + - description: ID of pet to update + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + multipart/form-data: + schema: + $ref: "#/components/schemas/uploadFiles_request" + required: true + responses: + "200": + content: + application/json: + schema: + $ref: "#/components/schemas/ApiResponse" + description: successful operation + security: + - petstore_auth: + - write:pets + - read:pets + summary: uploads an images + tags: + - pet /store/inventory: get: description: Returns a map of status codes to quantities @@ -2924,6 +2958,16 @@ components: format: binary type: string type: object + uploadFiles_request: + properties: + files: + items: + format: binary + type: string + type: array + required: + - files + type: object testEnumParameters_request: properties: enum_form_string_array: diff --git a/samples/client/petstore/csharp/generichost/net9/Petstore/docs/apis/PetApi.md b/samples/client/petstore/csharp/generichost/net9/Petstore/docs/apis/PetApi.md index 2826ea00f728..b42ee516b313 100644 --- a/samples/client/petstore/csharp/generichost/net9/Petstore/docs/apis/PetApi.md +++ b/samples/client/petstore/csharp/generichost/net9/Petstore/docs/apis/PetApi.md @@ -13,6 +13,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* | [**UpdatePetWithForm**](PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data | | [**UploadFile**](PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image | | [**UploadFileWithRequiredFile**](PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) | +| [**UploadFiles**](PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images | # **AddPet** @@ -341,3 +342,38 @@ uploads an image (required) [[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + +# **UploadFiles** +> ApiResponse UploadFiles (List files, long petId) + +uploads an images + + +### Parameters + +| Name | Type | Description | Notes | +|------|------|-------------|-------| +| **files** | **List<System.IO.Stream>** | | | +| **petId** | **long** | ID of pet to update | | + +### Return type + +[**ApiResponse**](ApiResponse.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: multipart/form-data + - **Accept**: application/json + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | + +[[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + diff --git a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs index 66769b3aee6a..fed093fb206f 100644 --- a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs @@ -196,7 +196,7 @@ public async Task TestEndpointParametersAsyncTest() string patternWithoutDelimiter = default; byte[] varByte = default; double varDouble = default; - Client.Option binary = default; + Client.Option binary = default; Client.Option callback = default; Client.Option date = default; Client.Option dateTime = default; diff --git a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 215e88093797..e9b05337bb59 100644 --- a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools.Test/Api/PetApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools.Test/Api/PetApiTests.cs @@ -137,7 +137,7 @@ public async Task UploadFileAsyncTest() { long petId = default; Client.Option additionalMetadata = default; - Client.Option file = default; + Client.Option file = default; var response = await _instance.UploadFileAsync(petId, additionalMetadata, file); var model = response.Ok(); Assert.IsType(model); @@ -150,11 +150,24 @@ public async Task UploadFileAsyncTest() public async Task UploadFileWithRequiredFileAsyncTest() { long petId = default; - System.IO.Stream requiredFile = default; + Org.OpenAPITools.Client.FileParameter requiredFile = default; Client.Option additionalMetadata = default; var response = await _instance.UploadFileWithRequiredFileAsync(petId, requiredFile, additionalMetadata); var model = response.Ok(); Assert.IsType(model); } + + /// + /// Test UploadFiles + /// + [Fact (Skip = "not implemented")] + public async Task UploadFilesAsyncTest() + { + List files = default; + long petId = default; + var response = await _instance.UploadFilesAsync(files, petId); + var model = response.Ok(); + Assert.IsType(model); + } } } diff --git a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs index 3c26a27185e6..44d52e7e1090 100644 --- a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs +++ b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs @@ -764,27 +764,19 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Api/FakeApi.cs b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Api/FakeApi.cs index 01aaf0ccbd85..482421f8c4ea 100644 --- a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Api/FakeApi.cs +++ b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Api/FakeApi.cs @@ -330,7 +330,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <> - Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -354,7 +354,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <> - Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// To test enum parameters @@ -4080,7 +4080,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); + partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); /// /// Validates the request parameters @@ -4092,7 +4092,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) + private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) { if (patternWithoutDelimiter == null) throw new ArgumentNullException(nameof(patternWithoutDelimiter)); @@ -4131,7 +4131,7 @@ private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte /// /// /// - private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLog = false; AfterTestEndpointParameters(ref suppressDefaultLog, apiResponseLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4158,7 +4158,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Logs exceptions that occur while retrieving the server response @@ -4180,7 +4180,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLogLocalVar = false; OnErrorTestEndpointParameters(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4209,7 +4209,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// /// /// - partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -4230,7 +4230,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -4262,7 +4262,7 @@ public async Task TestEndpointParametersOrDe /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -4281,14 +4281,8 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("number", ClientUtils.ParameterToString(number))); formParameterLocalVars.Add(new KeyValuePair("pattern_without_delimiter", ClientUtils.ParameterToString(patternWithoutDelimiter))); @@ -4298,7 +4292,7 @@ public async Task TestEndpointParametersAsyn formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.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."); if (callback.IsSet) formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); @@ -4327,6 +4321,9 @@ public async Task TestEndpointParametersAsyn if (varString.IsSet) formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4340,11 +4337,6 @@ public async Task TestEndpointParametersAsyn "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -4637,29 +4629,23 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (enumFormString.IsSet) + if (enumFormString.IsSet) formParameterLocalVars.Add(new KeyValuePair("enum_form_string", ClientUtils.ParameterToString(enumFormString.Value))); if (enumFormStringArray.IsSet) formParameterLocalVars.Add(new KeyValuePair("enum_form_string_array", ClientUtils.ParameterToString(enumFormStringArray.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Get; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -5546,29 +5532,21 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("param", ClientUtils.ParameterToString(param))); formParameterLocalVars.Add(new KeyValuePair("param2", ClientUtils.ParameterToString(param2))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Get; DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Api/PetApi.cs b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Api/PetApi.cs index a1817e3df697..da4dfd225bc4 100644 --- a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Api/PetApi.cs +++ b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Api/PetApi.cs @@ -216,7 +216,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image @@ -229,7 +229,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -243,7 +243,7 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -256,7 +256,32 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); } /// @@ -415,6 +440,18 @@ public interface IUploadFileWithRequiredFileApiResponse : Org.OpenAPITools.Clien bool IsOk { get; } } + /// + /// The + /// + public interface IUploadFilesApiResponse : Org.OpenAPITools.Client.IApiResponse, IOk + { + /// + /// Returns true if the response is 200 Ok + /// + /// + bool IsOk { get; } + } + /// /// Represents a collection of functions to interact with the API endpoints /// @@ -599,6 +636,26 @@ internal void ExecuteOnErrorUploadFileWithRequiredFile(Exception exception) { OnErrorUploadFileWithRequiredFile?.Invoke(this, new ExceptionEventArgs(exception)); } + + /// + /// The event raised after the server response + /// + public event EventHandler OnUploadFiles; + + /// + /// The event raised after an error querying the server + /// + public event EventHandler OnErrorUploadFiles; + + internal void ExecuteOnUploadFiles(PetApi.UploadFilesApiResponse apiResponse) + { + OnUploadFiles?.Invoke(this, new ApiResponseEventArgs(apiResponse)); + } + + internal void ExecuteOnErrorUploadFiles(Exception exception) + { + OnErrorUploadFiles?.Invoke(this, new ExceptionEventArgs(exception)); + } } /// @@ -2330,18 +2387,17 @@ public async Task UpdatePetWithFormAsync(long pet : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (name.IsSet) + if (name.IsSet) formParameterLocalVars.Add(new KeyValuePair("name", ClientUtils.ParameterToString(name.Value))); if (status.IsSet) formParameterLocalVars.Add(new KeyValuePair("status", ClientUtils.ParameterToString(status.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2355,11 +2411,6 @@ public async Task UpdatePetWithFormAsync(long pet "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -2459,7 +2510,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); + partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); /// /// Validates the request parameters @@ -2467,7 +2518,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFile(Option additionalMetadata, Option file) + private void ValidateUploadFile(Option additionalMetadata, Option file) { if (additionalMetadata.IsSet && additionalMetadata.Value == null) throw new ArgumentNullException(nameof(additionalMetadata)); @@ -2483,7 +2534,7 @@ private void ValidateUploadFile(Option additionalMetadata, Option /// /// - private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) + private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLog = false; AfterUploadFile(ref suppressDefaultLog, apiResponseLocalVar, petId, additionalMetadata, file); @@ -2499,7 +2550,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); + partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); /// /// Logs exceptions that occur while retrieving the server response @@ -2510,7 +2561,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) + private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, additionalMetadata, file); @@ -2528,7 +2579,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// /// /// - partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); + partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); /// /// uploads an image @@ -2538,7 +2589,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2559,7 +2610,7 @@ public async Task UploadFileOrDefaultAsync(long petId, O /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2579,17 +2630,23 @@ public async Task UploadFileAsync(long petId, Option> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (additionalMetadata.IsSet) + if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); if (file.IsSet) - multipartContentLocalVar.Add(new StreamContent(file.Value)); + { + var streamContentLocalVar = new StreamContent(file.Value.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "file", file.Value.FileName ?? "file"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2604,11 +2661,6 @@ public async Task UploadFileAsync(long petId, Option additionalMetadata); + partial void FormatUploadFileWithRequiredFile(ref long petId, ref Org.OpenAPITools.Client.FileParameter requiredFile, ref Option additionalMetadata); /// /// Validates the request parameters @@ -2757,7 +2809,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, Option additionalMetadata) + private void ValidateUploadFileWithRequiredFile(Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { if (requiredFile == null) throw new ArgumentNullException(nameof(requiredFile)); @@ -2773,7 +2825,7 @@ private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, O /// /// /// - private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLog = false; AfterUploadFileWithRequiredFile(ref suppressDefaultLog, apiResponseLocalVar, petId, requiredFile, additionalMetadata); @@ -2789,7 +2841,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// Logs exceptions that occur while retrieving the server response @@ -2800,7 +2852,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFileWithRequiredFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, requiredFile, additionalMetadata); @@ -2818,7 +2870,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// /// /// - partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// uploads an image (required) @@ -2828,7 +2880,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2849,7 +2901,7 @@ public async Task UploadFileWithRequired /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2869,17 +2921,23 @@ public async Task UploadFileWithRequired : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/{petId}/uploadImageWithRequiredFile"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); multipartContentLocalVar.Add(new StreamContent(requiredFile)); + { + var streamContentLocalVar = new StreamContent(requiredFile.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile", requiredFile.FileName ?? "requiredFile"); + } if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2893,11 +2951,6 @@ public async Task UploadFileWithRequired "multipart/form-data" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - string[] acceptLocalVars = new string[] { "application/json", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" @@ -3038,5 +3091,283 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } + + partial void FormatUploadFiles(List files, ref long petId); + + /// + /// Validates the request parameters + /// + /// + /// + private void ValidateUploadFiles(List files) + { + if (files == null) + throw new ArgumentNullException(nameof(files)); + } + + /// + /// Processes the server response + /// + /// + /// + /// + private void AfterUploadFilesDefaultImplementation(IUploadFilesApiResponse apiResponseLocalVar, List files, long petId) + { + bool suppressDefaultLog = false; + AfterUploadFiles(ref suppressDefaultLog, apiResponseLocalVar, files, petId); + if (!suppressDefaultLog) + Logger.LogInformation("{0,-9} | {1} | {2}", (apiResponseLocalVar.DownloadedAt - apiResponseLocalVar.RequestedAt).TotalSeconds, apiResponseLocalVar.StatusCode, apiResponseLocalVar.Path); + } + + /// + /// Processes the server response + /// + /// + /// + /// + /// + partial void AfterUploadFiles(ref bool suppressDefaultLog, IUploadFilesApiResponse apiResponseLocalVar, List files, long petId); + + /// + /// Logs exceptions that occur while retrieving the server response + /// + /// + /// + /// + /// + /// + private void OnErrorUploadFilesDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId) + { + bool suppressDefaultLogLocalVar = false; + OnErrorUploadFiles(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, files, petId); + if (!suppressDefaultLogLocalVar) + Logger.LogError(exceptionLocalVar, "An error occurred while sending the request to the server."); + } + + /// + /// A partial method that gives developers a way to provide customized exception handling + /// + /// + /// + /// + /// + /// + /// + partial void OnErrorUploadFiles(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId); + + /// + /// uploads an images + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + try + { + return await UploadFilesAsync(files, petId, cancellationToken).ConfigureAwait(false); + } + catch (Exception) + { + return null; + } + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + UriBuilder uriBuilderLocalVar = new UriBuilder(); + + try + { + ValidateUploadFiles(files); + + FormatUploadFiles(files, ref petId); + + using (HttpRequestMessage httpRequestMessageLocalVar = new HttpRequestMessage()) + { + uriBuilderLocalVar.Host = HttpClient.BaseAddress.Host; + uriBuilderLocalVar.Port = HttpClient.BaseAddress.Port; + uriBuilderLocalVar.Scheme = HttpClient.BaseAddress.Scheme; + uriBuilderLocalVar.Path = HttpClient.BaseAddress.AbsolutePath == "/" + ? "/pet/{petId}/uploadImages" + : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}/uploadImages"); + uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); + + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); + + httpRequestMessageLocalVar.Content = multipartContentLocalVar; + + List> formParameterLocalVars = new List>(); + + foreach (Org.OpenAPITools.Client.FileParameter fileParameterLocalVar in files) + { + var streamContentLocalVar = new StreamContent(fileParameterLocalVar.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "files", fileParameterLocalVar.FileName ?? "files"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); + + List tokenBaseLocalVars = new List(); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; + + OAuthToken oauthTokenLocalVar1 = (OAuthToken) await OauthTokenProvider.GetAsync(cancellation: cancellationToken).ConfigureAwait(false); + + tokenBaseLocalVars.Add(oauthTokenLocalVar1); + + oauthTokenLocalVar1.UseInHeader(httpRequestMessageLocalVar, ""); + + string[] contentTypes = new string[] { + "multipart/form-data" + }; + + string[] acceptLocalVars = new string[] { + "application/json" + }; + + IEnumerable acceptHeaderValuesLocalVar = ClientUtils.SelectHeaderAcceptArray(acceptLocalVars); + + foreach (var acceptLocalVar in acceptHeaderValuesLocalVar) + httpRequestMessageLocalVar.Headers.Accept.Add(acceptLocalVar); + + httpRequestMessageLocalVar.Method = HttpMethod.Post; + + DateTime requestedAtLocalVar = DateTime.UtcNow; + + using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false)) + { + ILogger apiResponseLoggerLocalVar = LoggerFactory.CreateLogger(); + UploadFilesApiResponse apiResponseLocalVar; + + switch ((int)httpResponseMessageLocalVar.StatusCode) { + default: { + string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + apiResponseLocalVar = new(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/pet/{petId}/uploadImages", requestedAtLocalVar, _jsonSerializerOptions); + + break; + } + } + + AfterUploadFilesDefaultImplementation(apiResponseLocalVar, files, petId); + + Events.ExecuteOnUploadFiles(apiResponseLocalVar); + + if (apiResponseLocalVar.StatusCode == (HttpStatusCode) 429) + foreach(TokenBase tokenBaseLocalVar in tokenBaseLocalVars) + tokenBaseLocalVar.BeginRateLimit(); + + return apiResponseLocalVar; + } + } + } + catch(Exception e) + { + OnErrorUploadFilesDefaultImplementation(e, "/pet/{petId}/uploadImages", uriBuilderLocalVar.Path, files, petId); + Events.ExecuteOnErrorUploadFiles(e); + throw; + } + } + + /// + /// The + /// + public partial class UploadFilesApiResponse : Org.OpenAPITools.Client.ApiResponse, IUploadFilesApiResponse + { + /// + /// The logger + /// + public ILogger Logger { get; } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, string rawContent, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, rawContent, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, System.IO.Stream contentStream, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, contentStream, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + partial void OnCreated(global::System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage); + + /// + /// Returns true if the response is 200 Ok + /// + /// + public bool IsOk => 200 == (int)StatusCode; + + /// + /// Deserializes the response if the response is 200 Ok + /// + /// + public Org.OpenAPITools.Model.ApiResponse Ok() + { + // This logic may be modified with the AsModel.mustache template + return IsOk + ? System.Text.Json.JsonSerializer.Deserialize(RawContent, _jsonSerializerOptions) + : null; + } + + /// + /// Returns true if the response is 200 Ok and the deserialized response is not null + /// + /// + /// + public bool TryOk([NotNullWhen(true)]out Org.OpenAPITools.Model.ApiResponse result) + { + result = null; + + try + { + result = Ok(); + } catch (Exception e) + { + OnDeserializationErrorDefaultImplementation(e, (HttpStatusCode)200); + } + + return result != null; + } + + private void OnDeserializationErrorDefaultImplementation(Exception exception, HttpStatusCode httpStatusCode) + { + bool suppressDefaultLog = false; + OnDeserializationError(ref suppressDefaultLog, exception, httpStatusCode); + if (!suppressDefaultLog) + Logger.LogError(exception, "An error occurred while deserializing the {code} response.", httpStatusCode); + } + + partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); + } } } diff --git a/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..6150dbcf4774 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,40 @@ +// +/* + * OpenAPI Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/.openapi-generator/FILES index ab28c754b4b1..a3e02b328e0a 100644 --- a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/.openapi-generator/FILES @@ -140,6 +140,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/HttpSigningConfiguration.cs src/Org.OpenAPITools/Client/HttpSigningToken.cs diff --git a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/api/openapi.yaml b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/api/openapi.yaml index d8106a5755fc..ca451f3fb832 100644 --- a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/api/openapi.yaml @@ -331,6 +331,40 @@ paths: summary: uploads an image tags: - pet + /pet/{petId}/uploadImages: + post: + description: "" + operationId: uploadFiles + parameters: + - description: ID of pet to update + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + multipart/form-data: + schema: + $ref: "#/components/schemas/uploadFiles_request" + required: true + responses: + "200": + content: + application/json: + schema: + $ref: "#/components/schemas/ApiResponse" + description: successful operation + security: + - petstore_auth: + - write:pets + - read:pets + summary: uploads an images + tags: + - pet /store/inventory: get: description: Returns a map of status codes to quantities @@ -2924,6 +2958,16 @@ components: format: binary type: string type: object + uploadFiles_request: + properties: + files: + items: + format: binary + type: string + type: array + required: + - files + type: object testEnumParameters_request: properties: enum_form_string_array: diff --git a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/docs/apis/PetApi.md b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/docs/apis/PetApi.md index 2826ea00f728..b42ee516b313 100644 --- a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/docs/apis/PetApi.md +++ b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/docs/apis/PetApi.md @@ -13,6 +13,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* | [**UpdatePetWithForm**](PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data | | [**UploadFile**](PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image | | [**UploadFileWithRequiredFile**](PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) | +| [**UploadFiles**](PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images | # **AddPet** @@ -341,3 +342,38 @@ uploads an image (required) [[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + +# **UploadFiles** +> ApiResponse UploadFiles (List files, long petId) + +uploads an images + + +### Parameters + +| Name | Type | Description | Notes | +|------|------|-------------|-------| +| **files** | **List<System.IO.Stream>** | | | +| **petId** | **long** | ID of pet to update | | + +### Return type + +[**ApiResponse**](ApiResponse.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: multipart/form-data + - **Accept**: application/json + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | + +[[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + diff --git a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs index 406dbc964a6d..d207bb93dc69 100644 --- a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs @@ -196,7 +196,7 @@ public async Task TestEndpointParametersAsyncTest() string patternWithoutDelimiter = default!; byte[] varByte = default!; double varDouble = default!; - Client.Option binary = default!; + Client.Option binary = default!; Client.Option callback = default!; Client.Option date = default!; Client.Option dateTime = default!; diff --git a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 49e7b21b53c2..6bb1f953987c 100644 --- a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools.Test/Api/PetApiTests.cs +++ b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools.Test/Api/PetApiTests.cs @@ -137,7 +137,7 @@ public async Task UploadFileAsyncTest() { long petId = default!; Client.Option additionalMetadata = default!; - Client.Option file = default!; + Client.Option file = default!; var response = await _instance.UploadFileAsync(petId, additionalMetadata, file); var model = response.Ok(); Assert.IsType(model); @@ -150,11 +150,24 @@ public async Task UploadFileAsyncTest() public async Task UploadFileWithRequiredFileAsyncTest() { long petId = default!; - System.IO.Stream requiredFile = default!; + Org.OpenAPITools.Client.FileParameter requiredFile = default!; Client.Option additionalMetadata = default!; var response = await _instance.UploadFileWithRequiredFileAsync(petId, requiredFile, additionalMetadata); var model = response.Ok(); Assert.IsType(model); } + + /// + /// Test UploadFiles + /// + [Fact (Skip = "not implemented")] + public async Task UploadFilesAsyncTest() + { + List files = default!; + long petId = default!; + var response = await _instance.UploadFilesAsync(files, petId); + var model = response.Ok(); + Assert.IsType(model); + } } } diff --git a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Api/DefaultApi.cs index 2391c7e1ee03..46b798fe32ca 100644 --- a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Api/DefaultApi.cs +++ b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Api/DefaultApi.cs @@ -766,15 +766,12 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + List> formParameterLocalVars = new List>(); - httpRequestMessageLocalVar.Content = multipartContentLocalVar; + formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); - List> formParameterLocalVars = new List>(); - - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -782,11 +779,6 @@ public async Task GetCountryAsync(string country, System "application/x-www-form-urlencoded" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Api/FakeApi.cs b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Api/FakeApi.cs index 262a94ef2520..54a1c8c85360 100644 --- a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Api/FakeApi.cs +++ b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Api/FakeApi.cs @@ -332,7 +332,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <> - Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -356,7 +356,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <?> - Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// To test enum parameters @@ -4082,7 +4082,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); + partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); /// /// Validates the request parameters @@ -4094,7 +4094,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) + private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) { if (patternWithoutDelimiter == null) throw new ArgumentNullException(nameof(patternWithoutDelimiter)); @@ -4133,7 +4133,7 @@ private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte /// /// /// - private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLog = false; AfterTestEndpointParameters(ref suppressDefaultLog, apiResponseLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4160,7 +4160,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Logs exceptions that occur while retrieving the server response @@ -4182,7 +4182,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLogLocalVar = false; OnErrorTestEndpointParameters(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4211,7 +4211,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// /// /// - partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -4232,7 +4232,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -4264,7 +4264,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -4283,51 +4283,48 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + List> formParameterLocalVars = new List>(); - httpRequestMessageLocalVar.Content = multipartContentLocalVar; + formParameterLocalVars.Add(new KeyValuePair("number", ClientUtils.ParameterToString(number))); - List> formParameterLocalVars = new List>(); + formParameterLocalVars.Add(new KeyValuePair("pattern_without_delimiter", ClientUtils.ParameterToString(patternWithoutDelimiter))); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + formParameterLocalVars.Add(new KeyValuePair("byte", ClientUtils.ParameterToString(varByte))); - formParameterLocalVars.Add(new KeyValuePair("number", ClientUtils.ParameterToString(number))); - - formParameterLocalVars.Add(new KeyValuePair("pattern_without_delimiter", ClientUtils.ParameterToString(patternWithoutDelimiter))); - - formParameterLocalVars.Add(new KeyValuePair("byte", ClientUtils.ParameterToString(varByte))); - - formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); + formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.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."); if (callback.IsSet) - formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); + formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); if (date.IsSet) - formParameterLocalVars.Add(new KeyValuePair("date", ClientUtils.ParameterToString(date.Value))); + formParameterLocalVars.Add(new KeyValuePair("date", ClientUtils.ParameterToString(date.Value))); if (dateTime.IsSet) - formParameterLocalVars.Add(new KeyValuePair("dateTime", ClientUtils.ParameterToString(dateTime.Value))); + formParameterLocalVars.Add(new KeyValuePair("dateTime", ClientUtils.ParameterToString(dateTime.Value))); if (int32.IsSet) - formParameterLocalVars.Add(new KeyValuePair("int32", ClientUtils.ParameterToString(int32.Value))); + formParameterLocalVars.Add(new KeyValuePair("int32", ClientUtils.ParameterToString(int32.Value))); if (int64.IsSet) - formParameterLocalVars.Add(new KeyValuePair("int64", ClientUtils.ParameterToString(int64.Value))); + formParameterLocalVars.Add(new KeyValuePair("int64", ClientUtils.ParameterToString(int64.Value))); if (integer.IsSet) - formParameterLocalVars.Add(new KeyValuePair("integer", ClientUtils.ParameterToString(integer.Value))); + formParameterLocalVars.Add(new KeyValuePair("integer", ClientUtils.ParameterToString(integer.Value))); if (password.IsSet) - formParameterLocalVars.Add(new KeyValuePair("password", ClientUtils.ParameterToString(password.Value))); + formParameterLocalVars.Add(new KeyValuePair("password", ClientUtils.ParameterToString(password.Value))); if (varFloat.IsSet) - formParameterLocalVars.Add(new KeyValuePair("float", ClientUtils.ParameterToString(varFloat.Value))); + formParameterLocalVars.Add(new KeyValuePair("float", ClientUtils.ParameterToString(varFloat.Value))); if (varString.IsSet) - formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4342,11 +4339,6 @@ public async Task TestEndpointParametersAsyn "application/x-www-form-urlencoded" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -4639,17 +4631,16 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); + List> formParameterLocalVars = new List>(); - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - - List> formParameterLocalVars = new List>(); - - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (enumFormString.IsSet) - formParameterLocalVars.Add(new KeyValuePair("enum_form_string", ClientUtils.ParameterToString(enumFormString.Value))); + if (enumFormString.IsSet) + formParameterLocalVars.Add(new KeyValuePair("enum_form_string", ClientUtils.ParameterToString(enumFormString.Value))); if (enumFormStringArray.IsSet) - formParameterLocalVars.Add(new KeyValuePair("enum_form_string_array", ClientUtils.ParameterToString(enumFormStringArray.Value))); + formParameterLocalVars.Add(new KeyValuePair("enum_form_string_array", ClientUtils.ParameterToString(enumFormStringArray.Value))); + + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4657,11 +4648,6 @@ public async Task TestEnumParametersAsync(Option "application/x-www-form-urlencoded" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Get; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -5548,17 +5534,14 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; + List> formParameterLocalVars = new List>(); - List> formParameterLocalVars = new List>(); + formParameterLocalVars.Add(new KeyValuePair("param", ClientUtils.ParameterToString(param))); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + formParameterLocalVars.Add(new KeyValuePair("param2", ClientUtils.ParameterToString(param2))); - formParameterLocalVars.Add(new KeyValuePair("param", ClientUtils.ParameterToString(param))); - - formParameterLocalVars.Add(new KeyValuePair("param2", ClientUtils.ParameterToString(param2))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -5566,11 +5549,6 @@ public async Task TestJsonFormDataAsync(string par "application/x-www-form-urlencoded" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Get; DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Api/PetApi.cs b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Api/PetApi.cs index 2d7e4dab0b84..c5de9cd55ad1 100644 --- a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Api/PetApi.cs +++ b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Api/PetApi.cs @@ -218,7 +218,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image @@ -231,7 +231,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <?> - Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -245,7 +245,7 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -258,7 +258,32 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <?> - Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <?> + Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); } /// @@ -417,6 +442,18 @@ public interface IUploadFileWithRequiredFileApiResponse : Org.OpenAPITools.Clien bool IsOk { get; } } + /// + /// The + /// + public interface IUploadFilesApiResponse : Org.OpenAPITools.Client.IApiResponse, IOk + { + /// + /// Returns true if the response is 200 Ok + /// + /// + bool IsOk { get; } + } + /// /// Represents a collection of functions to interact with the API endpoints /// @@ -601,6 +638,26 @@ internal void ExecuteOnErrorUploadFileWithRequiredFile(Exception exception) { OnErrorUploadFileWithRequiredFile?.Invoke(this, new ExceptionEventArgs(exception)); } + + /// + /// The event raised after the server response + /// + public event EventHandler? OnUploadFiles; + + /// + /// The event raised after an error querying the server + /// + public event EventHandler? OnErrorUploadFiles; + + internal void ExecuteOnUploadFiles(PetApi.UploadFilesApiResponse apiResponse) + { + OnUploadFiles?.Invoke(this, new ApiResponseEventArgs(apiResponse)); + } + + internal void ExecuteOnErrorUploadFiles(Exception exception) + { + OnErrorUploadFiles?.Invoke(this, new ExceptionEventArgs(exception)); + } } /// @@ -2332,17 +2389,16 @@ public async Task UpdatePetWithFormAsync(long pet : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - - List> formParameterLocalVars = new List>(); + List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (name.IsSet) - formParameterLocalVars.Add(new KeyValuePair("name", ClientUtils.ParameterToString(name.Value))); + if (name.IsSet) + formParameterLocalVars.Add(new KeyValuePair("name", ClientUtils.ParameterToString(name.Value))); if (status.IsSet) - formParameterLocalVars.Add(new KeyValuePair("status", ClientUtils.ParameterToString(status.Value))); + formParameterLocalVars.Add(new KeyValuePair("status", ClientUtils.ParameterToString(status.Value))); + + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2357,11 +2413,6 @@ public async Task UpdatePetWithFormAsync(long pet "application/x-www-form-urlencoded" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = HttpMethod.Post; DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -2461,7 +2512,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); + partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); /// /// Validates the request parameters @@ -2469,7 +2520,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFile(Option additionalMetadata, Option file) + private void ValidateUploadFile(Option additionalMetadata, Option file) { if (additionalMetadata.IsSet && additionalMetadata.Value == null) throw new ArgumentNullException(nameof(additionalMetadata)); @@ -2485,7 +2536,7 @@ private void ValidateUploadFile(Option additionalMetadata, Option /// /// - private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) + private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLog = false; AfterUploadFile(ref suppressDefaultLog, apiResponseLocalVar, petId, additionalMetadata, file); @@ -2501,7 +2552,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); + partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); /// /// Logs exceptions that occur while retrieving the server response @@ -2512,7 +2563,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) + private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, additionalMetadata, file); @@ -2530,7 +2581,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// /// /// - partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); + partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); /// /// uploads an image @@ -2540,7 +2591,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2561,7 +2612,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2581,17 +2632,23 @@ public async Task UploadFileAsync(long petId, Option> formParameterLocalVars = new List>(); + List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (additionalMetadata.IsSet) - formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + if (additionalMetadata.IsSet) + formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); if (file.IsSet) - multipartContentLocalVar.Add(new StreamContent(file.Value)); + { + var streamContentLocalVar = new StreamContent(file.Value.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "file", file.Value.FileName ?? "file"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2606,11 +2663,6 @@ public async Task UploadFileAsync(long petId, Option additionalMetadata); + partial void FormatUploadFileWithRequiredFile(ref long petId, ref Org.OpenAPITools.Client.FileParameter requiredFile, ref Option additionalMetadata); /// /// Validates the request parameters @@ -2759,7 +2811,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, Option additionalMetadata) + private void ValidateUploadFileWithRequiredFile(Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { if (requiredFile == null) throw new ArgumentNullException(nameof(requiredFile)); @@ -2775,7 +2827,7 @@ private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, O /// /// /// - private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLog = false; AfterUploadFileWithRequiredFile(ref suppressDefaultLog, apiResponseLocalVar, petId, requiredFile, additionalMetadata); @@ -2791,7 +2843,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// Logs exceptions that occur while retrieving the server response @@ -2802,7 +2854,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFileWithRequiredFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, requiredFile, additionalMetadata); @@ -2820,7 +2872,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// /// /// - partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// uploads an image (required) @@ -2830,7 +2882,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2851,7 +2903,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2871,16 +2923,22 @@ public async Task UploadFileWithRequired : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/{petId}/uploadImageWithRequiredFile"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); + List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); multipartContentLocalVar.Add(new StreamContent(requiredFile)); + { + var streamContentLocalVar = new StreamContent(requiredFile.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile", requiredFile.FileName ?? "requiredFile"); + } if (additionalMetadata.IsSet) - formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2895,11 +2953,6 @@ public async Task UploadFileWithRequired "multipart/form-data" }; - string? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - string[] acceptLocalVars = new string[] { "application/json", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" @@ -3040,5 +3093,283 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } + + partial void FormatUploadFiles(List files, ref long petId); + + /// + /// Validates the request parameters + /// + /// + /// + private void ValidateUploadFiles(List files) + { + if (files == null) + throw new ArgumentNullException(nameof(files)); + } + + /// + /// Processes the server response + /// + /// + /// + /// + private void AfterUploadFilesDefaultImplementation(IUploadFilesApiResponse apiResponseLocalVar, List files, long petId) + { + bool suppressDefaultLog = false; + AfterUploadFiles(ref suppressDefaultLog, apiResponseLocalVar, files, petId); + if (!suppressDefaultLog) + Logger.LogInformation("{0,-9} | {1} | {2}", (apiResponseLocalVar.DownloadedAt - apiResponseLocalVar.RequestedAt).TotalSeconds, apiResponseLocalVar.StatusCode, apiResponseLocalVar.Path); + } + + /// + /// Processes the server response + /// + /// + /// + /// + /// + partial void AfterUploadFiles(ref bool suppressDefaultLog, IUploadFilesApiResponse apiResponseLocalVar, List files, long petId); + + /// + /// Logs exceptions that occur while retrieving the server response + /// + /// + /// + /// + /// + /// + private void OnErrorUploadFilesDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId) + { + bool suppressDefaultLogLocalVar = false; + OnErrorUploadFiles(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, files, petId); + if (!suppressDefaultLogLocalVar) + Logger.LogError(exceptionLocalVar, "An error occurred while sending the request to the server."); + } + + /// + /// A partial method that gives developers a way to provide customized exception handling + /// + /// + /// + /// + /// + /// + /// + partial void OnErrorUploadFiles(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId); + + /// + /// uploads an images + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + try + { + return await UploadFilesAsync(files, petId, cancellationToken).ConfigureAwait(false); + } + catch (Exception) + { + return null; + } + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + UriBuilder uriBuilderLocalVar = new UriBuilder(); + + try + { + ValidateUploadFiles(files); + + FormatUploadFiles(files, ref petId); + + using (HttpRequestMessage httpRequestMessageLocalVar = new HttpRequestMessage()) + { + uriBuilderLocalVar.Host = HttpClient.BaseAddress!.Host; + uriBuilderLocalVar.Port = HttpClient.BaseAddress.Port; + uriBuilderLocalVar.Scheme = HttpClient.BaseAddress.Scheme; + uriBuilderLocalVar.Path = HttpClient.BaseAddress.AbsolutePath == "/" + ? "/pet/{petId}/uploadImages" + : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}/uploadImages"); + uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); + + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); + + httpRequestMessageLocalVar.Content = multipartContentLocalVar; + + List> formParameterLocalVars = new List>(); + + foreach (Org.OpenAPITools.Client.FileParameter fileParameterLocalVar in files) + { + var streamContentLocalVar = new StreamContent(fileParameterLocalVar.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "files", fileParameterLocalVar.FileName ?? "files"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); + + List tokenBaseLocalVars = new List(); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; + + OAuthToken oauthTokenLocalVar1 = (OAuthToken) await OauthTokenProvider.GetAsync(cancellation: cancellationToken).ConfigureAwait(false); + + tokenBaseLocalVars.Add(oauthTokenLocalVar1); + + oauthTokenLocalVar1.UseInHeader(httpRequestMessageLocalVar, ""); + + string[] contentTypes = new string[] { + "multipart/form-data" + }; + + string[] acceptLocalVars = new string[] { + "application/json" + }; + + IEnumerable acceptHeaderValuesLocalVar = ClientUtils.SelectHeaderAcceptArray(acceptLocalVars); + + foreach (var acceptLocalVar in acceptHeaderValuesLocalVar) + httpRequestMessageLocalVar.Headers.Accept.Add(acceptLocalVar); + + httpRequestMessageLocalVar.Method = HttpMethod.Post; + + DateTime requestedAtLocalVar = DateTime.UtcNow; + + using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false)) + { + ILogger apiResponseLoggerLocalVar = LoggerFactory.CreateLogger(); + UploadFilesApiResponse apiResponseLocalVar; + + switch ((int)httpResponseMessageLocalVar.StatusCode) { + default: { + string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + apiResponseLocalVar = new(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/pet/{petId}/uploadImages", requestedAtLocalVar, _jsonSerializerOptions); + + break; + } + } + + AfterUploadFilesDefaultImplementation(apiResponseLocalVar, files, petId); + + Events.ExecuteOnUploadFiles(apiResponseLocalVar); + + if (apiResponseLocalVar.StatusCode == (HttpStatusCode) 429) + foreach(TokenBase tokenBaseLocalVar in tokenBaseLocalVars) + tokenBaseLocalVar.BeginRateLimit(); + + return apiResponseLocalVar; + } + } + } + catch(Exception e) + { + OnErrorUploadFilesDefaultImplementation(e, "/pet/{petId}/uploadImages", uriBuilderLocalVar.Path, files, petId); + Events.ExecuteOnErrorUploadFiles(e); + throw; + } + } + + /// + /// The + /// + public partial class UploadFilesApiResponse : Org.OpenAPITools.Client.ApiResponse, IUploadFilesApiResponse + { + /// + /// The logger + /// + public ILogger Logger { get; } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, string rawContent, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, rawContent, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, System.IO.Stream contentStream, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, contentStream, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + partial void OnCreated(global::System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage); + + /// + /// Returns true if the response is 200 Ok + /// + /// + public bool IsOk => 200 == (int)StatusCode; + + /// + /// Deserializes the response if the response is 200 Ok + /// + /// + public Org.OpenAPITools.Model.ApiResponse? Ok() + { + // This logic may be modified with the AsModel.mustache template + return IsOk + ? System.Text.Json.JsonSerializer.Deserialize(RawContent, _jsonSerializerOptions) + : null; + } + + /// + /// Returns true if the response is 200 Ok and the deserialized response is not null + /// + /// + /// + public bool TryOk([NotNullWhen(true)]out Org.OpenAPITools.Model.ApiResponse? result) + { + result = null; + + try + { + result = Ok(); + } catch (Exception e) + { + OnDeserializationErrorDefaultImplementation(e, (HttpStatusCode)200); + } + + return result != null; + } + + private void OnDeserializationErrorDefaultImplementation(Exception exception, HttpStatusCode httpStatusCode) + { + bool suppressDefaultLog = false; + OnDeserializationError(ref suppressDefaultLog, exception, httpStatusCode); + if (!suppressDefaultLog) + Logger.LogError(exception, "An error occurred while deserializing the {code} response.", httpStatusCode); + } + + partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); + } } } diff --git a/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..77779fe7d75a --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,42 @@ +// +/* + * OpenAPI Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +#nullable enable + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string? FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string? fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/net9/UseDateTimeForDate/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/net9/UseDateTimeForDate/.openapi-generator/FILES index 5abbcf46f35c..e28da391730f 100644 --- a/samples/client/petstore/csharp/generichost/net9/UseDateTimeForDate/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/net9/UseDateTimeForDate/.openapi-generator/FILES @@ -21,6 +21,7 @@ src/Org.OpenAPITools/Client/CookieContainer.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 diff --git a/samples/client/petstore/csharp/generichost/net9/UseDateTimeForDate/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/net9/UseDateTimeForDate/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..11da1d925144 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/net9/UseDateTimeForDate/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,42 @@ +// +/* + * OpenAPI Dates + * + * Thic spec contains endpoints with dates in different formats + * + * The version of the OpenAPI document: 1.0.0 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +#nullable enable + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string? FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string? fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/.openapi-generator/FILES b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/.openapi-generator/FILES index a6635c9d8351..82501a149e01 100644 --- a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/.openapi-generator/FILES +++ b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/.openapi-generator/FILES @@ -138,6 +138,7 @@ src/Org.OpenAPITools/Client/CookieContainer.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/HttpSigningConfiguration.cs src/Org.OpenAPITools/Client/HttpSigningToken.cs diff --git a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/api/openapi.yaml index d8106a5755fc..ca451f3fb832 100644 --- a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/api/openapi.yaml @@ -331,6 +331,40 @@ paths: summary: uploads an image tags: - pet + /pet/{petId}/uploadImages: + post: + description: "" + operationId: uploadFiles + parameters: + - description: ID of pet to update + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + multipart/form-data: + schema: + $ref: "#/components/schemas/uploadFiles_request" + required: true + responses: + "200": + content: + application/json: + schema: + $ref: "#/components/schemas/ApiResponse" + description: successful operation + security: + - petstore_auth: + - write:pets + - read:pets + summary: uploads an images + tags: + - pet /store/inventory: get: description: Returns a map of status codes to quantities @@ -2924,6 +2958,16 @@ components: format: binary type: string type: object + uploadFiles_request: + properties: + files: + items: + format: binary + type: string + type: array + required: + - files + type: object testEnumParameters_request: properties: enum_form_string_array: diff --git a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/docs/apis/PetApi.md b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/docs/apis/PetApi.md index 2826ea00f728..b42ee516b313 100644 --- a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/docs/apis/PetApi.md +++ b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/docs/apis/PetApi.md @@ -13,6 +13,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* | [**UpdatePetWithForm**](PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data | | [**UploadFile**](PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image | | [**UploadFileWithRequiredFile**](PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) | +| [**UploadFiles**](PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images | # **AddPet** @@ -341,3 +342,38 @@ uploads an image (required) [[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + +# **UploadFiles** +> ApiResponse UploadFiles (List files, long petId) + +uploads an images + + +### Parameters + +| Name | Type | Description | Notes | +|------|------|-------------|-------| +| **files** | **List<System.IO.Stream>** | | | +| **petId** | **long** | ID of pet to update | | + +### Return type + +[**ApiResponse**](ApiResponse.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: multipart/form-data + - **Accept**: application/json + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | + +[[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + diff --git a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs index ce85f85778ef..6420b47bc8b4 100644 --- a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs +++ b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools.Test/Api/FakeApiTests.cs @@ -196,7 +196,7 @@ public async Task TestEndpointParametersAsyncTest() string patternWithoutDelimiter = default; byte[] varByte = default; double varDouble = default; - Client.Option binary = default; + Client.Option binary = default; Client.Option callback = default; Client.Option date = default; Client.Option dateTime = default; diff --git a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 215e88093797..e9b05337bb59 100644 --- a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools.Test/Api/PetApiTests.cs +++ b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools.Test/Api/PetApiTests.cs @@ -137,7 +137,7 @@ public async Task UploadFileAsyncTest() { long petId = default; Client.Option additionalMetadata = default; - Client.Option file = default; + Client.Option file = default; var response = await _instance.UploadFileAsync(petId, additionalMetadata, file); var model = response.Ok(); Assert.IsType(model); @@ -150,11 +150,24 @@ public async Task UploadFileAsyncTest() public async Task UploadFileWithRequiredFileAsyncTest() { long petId = default; - System.IO.Stream requiredFile = default; + Org.OpenAPITools.Client.FileParameter requiredFile = default; Client.Option additionalMetadata = default; var response = await _instance.UploadFileWithRequiredFileAsync(petId, requiredFile, additionalMetadata); var model = response.Ok(); Assert.IsType(model); } + + /// + /// Test UploadFiles + /// + [Fact (Skip = "not implemented")] + public async Task UploadFilesAsyncTest() + { + List files = default; + long petId = default; + var response = await _instance.UploadFilesAsync(files, petId); + var model = response.Ok(); + Assert.IsType(model); + } } } diff --git a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs index 8f794c9ca7c8..a37b13115c90 100644 --- a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs +++ b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs @@ -762,27 +762,19 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = new HttpMethod("POST"); DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Api/FakeApi.cs b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Api/FakeApi.cs index 0d878f64abf2..33cecd82aa0a 100644 --- a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Api/FakeApi.cs +++ b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Api/FakeApi.cs @@ -329,7 +329,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <> - Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -353,7 +353,7 @@ public interface IFakeApi : IApi /// None (optional) /// Cancellation Token to cancel the request. /// <> - Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); + Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default); /// /// To test enum parameters @@ -4070,7 +4070,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); + partial void FormatTestEndpointParameters(ref decimal number, ref string patternWithoutDelimiter, ref byte[] varByte, ref double varDouble, ref Option binary, ref Option callback, ref Option date, ref Option dateTime, ref Option int32, ref Option int64, ref Option integer, ref Option password, ref Option varFloat, ref Option varString); /// /// Validates the request parameters @@ -4082,7 +4082,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) + private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte[] varByte, Option binary, Option callback, Option password, Option varString) { if (patternWithoutDelimiter == null) throw new ArgumentNullException(nameof(patternWithoutDelimiter)); @@ -4121,7 +4121,7 @@ private void ValidateTestEndpointParameters(string patternWithoutDelimiter, byte /// /// /// - private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLog = false; AfterTestEndpointParameters(ref suppressDefaultLog, apiResponseLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4148,7 +4148,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void AfterTestEndpointParameters(ref bool suppressDefaultLog, ITestEndpointParametersApiResponse apiResponseLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Logs exceptions that occur while retrieving the server response @@ -4170,7 +4170,7 @@ private void AfterTestEndpointParametersDefaultImplementation(ITestEndpointParam /// /// /// - private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) + private void OnErrorTestEndpointParametersDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString) { bool suppressDefaultLogLocalVar = false; OnErrorTestEndpointParameters(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, number, patternWithoutDelimiter, varByte, varDouble, binary, callback, date, dateTime, int32, int64, integer, password, varFloat, varString); @@ -4199,7 +4199,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// /// /// - partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); + partial void OnErrorTestEndpointParameters(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary, Option callback, Option date, Option dateTime, Option int32, Option int64, Option integer, Option password, Option varFloat, Option varString); /// /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -4220,7 +4220,7 @@ private void OnErrorTestEndpointParametersDefaultImplementation(Exception except /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersOrDefaultAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -4252,7 +4252,7 @@ public async Task TestEndpointParametersOrDe /// None (optional) /// Cancellation Token to cancel the request. /// <> - public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) + public async Task TestEndpointParametersAsync(decimal number, string patternWithoutDelimiter, byte[] varByte, double varDouble, Option binary = default, Option callback = default, Option date = default, Option dateTime = default, Option int32 = default, Option int64 = default, Option integer = default, Option password = default, Option varFloat = default, Option varString = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -4271,14 +4271,8 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("number", ClientUtils.ParameterToString(number))); formParameterLocalVars.Add(new KeyValuePair("pattern_without_delimiter", ClientUtils.ParameterToString(patternWithoutDelimiter))); @@ -4288,7 +4282,7 @@ public async Task TestEndpointParametersAsyn formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.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."); if (callback.IsSet) formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); @@ -4317,6 +4311,9 @@ public async Task TestEndpointParametersAsyn if (varString.IsSet) formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4330,11 +4327,6 @@ public async Task TestEndpointParametersAsyn "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = new HttpMethod("POST"); DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -4627,29 +4619,23 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (enumFormString.IsSet) + if (enumFormString.IsSet) formParameterLocalVars.Add(new KeyValuePair("enum_form_string", ClientUtils.ParameterToString(enumFormString.Value))); if (enumFormStringArray.IsSet) formParameterLocalVars.Add(new KeyValuePair("enum_form_string_array", ClientUtils.ParameterToString(enumFormStringArray.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = new HttpMethod("GET"); DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -5535,29 +5521,21 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("param", ClientUtils.ParameterToString(param))); formParameterLocalVars.Add(new KeyValuePair("param2", ClientUtils.ParameterToString(param2))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = new HttpMethod("GET"); DateTime requestedAtLocalVar = DateTime.UtcNow; diff --git a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Api/PetApi.cs b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Api/PetApi.cs index 00c695ffd700..bbe2532cf740 100644 --- a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Api/PetApi.cs +++ b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Api/PetApi.cs @@ -215,7 +215,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image @@ -228,7 +228,7 @@ public interface IPetApi : IApi /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -242,7 +242,7 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); /// /// uploads an image (required) @@ -255,7 +255,32 @@ public interface IPetApi : IApi /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default); } /// @@ -414,6 +439,18 @@ public interface IUploadFileWithRequiredFileApiResponse : Org.OpenAPITools.Clien bool IsOk { get; } } + /// + /// The + /// + public interface IUploadFilesApiResponse : Org.OpenAPITools.Client.IApiResponse, IOk + { + /// + /// Returns true if the response is 200 Ok + /// + /// + bool IsOk { get; } + } + /// /// Represents a collection of functions to interact with the API endpoints /// @@ -598,6 +635,26 @@ internal void ExecuteOnErrorUploadFileWithRequiredFile(Exception exception) { OnErrorUploadFileWithRequiredFile?.Invoke(this, new ExceptionEventArgs(exception)); } + + /// + /// The event raised after the server response + /// + public event EventHandler OnUploadFiles; + + /// + /// The event raised after an error querying the server + /// + public event EventHandler OnErrorUploadFiles; + + internal void ExecuteOnUploadFiles(PetApi.UploadFilesApiResponse apiResponse) + { + OnUploadFiles?.Invoke(this, new ApiResponseEventArgs(apiResponse)); + } + + internal void ExecuteOnErrorUploadFiles(Exception exception) + { + OnErrorUploadFiles?.Invoke(this, new ExceptionEventArgs(exception)); + } } /// @@ -2325,18 +2382,17 @@ public async Task UpdatePetWithFormAsync(long pet : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); - - httpRequestMessageLocalVar.Content = multipartContentLocalVar; - List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (name.IsSet) + if (name.IsSet) formParameterLocalVars.Add(new KeyValuePair("name", ClientUtils.ParameterToString(name.Value))); if (status.IsSet) formParameterLocalVars.Add(new KeyValuePair("status", ClientUtils.ParameterToString(status.Value))); + if (formParameterLocalVars.Count > 0) + httpRequestMessageLocalVar.Content = new FormUrlEncodedContent(formParameterLocalVars); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2350,11 +2406,6 @@ public async Task UpdatePetWithFormAsync(long pet "application/x-www-form-urlencoded" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - httpRequestMessageLocalVar.Method = new HttpMethod("POST"); DateTime requestedAtLocalVar = DateTime.UtcNow; @@ -2454,7 +2505,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } - partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); + partial void FormatUploadFile(ref long petId, ref Option additionalMetadata, ref Option file); /// /// Validates the request parameters @@ -2462,7 +2513,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFile(Option additionalMetadata, Option file) + private void ValidateUploadFile(Option additionalMetadata, Option file) { if (additionalMetadata.IsSet && additionalMetadata.Value == null) throw new ArgumentNullException(nameof(additionalMetadata)); @@ -2478,7 +2529,7 @@ private void ValidateUploadFile(Option additionalMetadata, Option /// /// - private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) + private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLog = false; AfterUploadFile(ref suppressDefaultLog, apiResponseLocalVar, petId, additionalMetadata, file); @@ -2494,7 +2545,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); + partial void AfterUploadFile(ref bool suppressDefaultLog, IUploadFileApiResponse apiResponseLocalVar, long petId, Option additionalMetadata, Option file); /// /// Logs exceptions that occur while retrieving the server response @@ -2505,7 +2556,7 @@ private void AfterUploadFileDefaultImplementation(IUploadFileApiResponse apiResp /// /// /// - private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) + private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, additionalMetadata, file); @@ -2523,7 +2574,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// /// /// - partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); + partial void OnErrorUploadFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Option additionalMetadata, Option file); /// /// uploads an image @@ -2533,7 +2584,7 @@ private void OnErrorUploadFileDefaultImplementation(Exception exceptionLocalVar, /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileOrDefaultAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2554,7 +2605,7 @@ public async Task UploadFileOrDefaultAsync(long petId, O /// file to upload (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileAsync(long petId, Option additionalMetadata = default, Option file = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2574,17 +2625,23 @@ public async Task UploadFileAsync(long petId, Option> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); if (additionalMetadata.IsSet) + if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); if (file.IsSet) - multipartContentLocalVar.Add(new StreamContent(file.Value)); + { + var streamContentLocalVar = new StreamContent(file.Value.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "file", file.Value.FileName ?? "file"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2599,11 +2656,6 @@ public async Task UploadFileAsync(long petId, Option additionalMetadata); + partial void FormatUploadFileWithRequiredFile(ref long petId, ref Org.OpenAPITools.Client.FileParameter requiredFile, ref Option additionalMetadata); /// /// Validates the request parameters @@ -2751,7 +2803,7 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht /// /// /// - private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, Option additionalMetadata) + private void ValidateUploadFileWithRequiredFile(Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { if (requiredFile == null) throw new ArgumentNullException(nameof(requiredFile)); @@ -2767,7 +2819,7 @@ private void ValidateUploadFileWithRequiredFile(System.IO.Stream requiredFile, O /// /// /// - private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLog = false; AfterUploadFileWithRequiredFile(ref suppressDefaultLog, apiResponseLocalVar, petId, requiredFile, additionalMetadata); @@ -2783,7 +2835,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void AfterUploadFileWithRequiredFile(ref bool suppressDefaultLog, IUploadFileWithRequiredFileApiResponse apiResponseLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// Logs exceptions that occur while retrieving the server response @@ -2794,7 +2846,7 @@ private void AfterUploadFileWithRequiredFileDefaultImplementation(IUploadFileWit /// /// /// - private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata) + private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata) { bool suppressDefaultLogLocalVar = false; OnErrorUploadFileWithRequiredFile(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, petId, requiredFile, additionalMetadata); @@ -2812,7 +2864,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// /// /// - partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, System.IO.Stream requiredFile, Option additionalMetadata); + partial void OnErrorUploadFileWithRequiredFile(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata); /// /// uploads an image (required) @@ -2822,7 +2874,7 @@ private void OnErrorUploadFileWithRequiredFileDefaultImplementation(Exception ex /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileOrDefaultAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { try { @@ -2843,7 +2895,7 @@ public async Task UploadFileWithRequired /// Additional data to pass to server (optional) /// Cancellation Token to cancel the request. /// <> - public async Task UploadFileWithRequiredFileAsync(long petId, System.IO.Stream requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) + public async Task UploadFileWithRequiredFileAsync(long petId, Org.OpenAPITools.Client.FileParameter requiredFile, Option additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default) { UriBuilder uriBuilderLocalVar = new UriBuilder(); @@ -2863,17 +2915,23 @@ public async Task UploadFileWithRequired : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/{petId}/uploadImageWithRequiredFile"); uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); multipartContentLocalVar.Add(new StreamContent(requiredFile)); + { + var streamContentLocalVar = new StreamContent(requiredFile.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile", requiredFile.FileName ?? "requiredFile"); + } if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2887,11 +2945,6 @@ public async Task UploadFileWithRequired "multipart/form-data" }; - string contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); - - if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) - httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); - string[] acceptLocalVars = new string[] { "application/json", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" @@ -3031,5 +3084,282 @@ private void OnDeserializationErrorDefaultImplementation(Exception exception, Ht partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); } + + partial void FormatUploadFiles(List files, ref long petId); + + /// + /// Validates the request parameters + /// + /// + /// + private void ValidateUploadFiles(List files) + { + if (files == null) + throw new ArgumentNullException(nameof(files)); + } + + /// + /// Processes the server response + /// + /// + /// + /// + private void AfterUploadFilesDefaultImplementation(IUploadFilesApiResponse apiResponseLocalVar, List files, long petId) + { + bool suppressDefaultLog = false; + AfterUploadFiles(ref suppressDefaultLog, apiResponseLocalVar, files, petId); + if (!suppressDefaultLog) + Logger.LogInformation("{0,-9} | {1} | {2}", (apiResponseLocalVar.DownloadedAt - apiResponseLocalVar.RequestedAt).TotalSeconds, apiResponseLocalVar.StatusCode, apiResponseLocalVar.Path); + } + + /// + /// Processes the server response + /// + /// + /// + /// + /// + partial void AfterUploadFiles(ref bool suppressDefaultLog, IUploadFilesApiResponse apiResponseLocalVar, List files, long petId); + + /// + /// Logs exceptions that occur while retrieving the server response + /// + /// + /// + /// + /// + /// + private void OnErrorUploadFilesDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId) + { + bool suppressDefaultLogLocalVar = false; + OnErrorUploadFiles(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, files, petId); + if (!suppressDefaultLogLocalVar) + Logger.LogError(exceptionLocalVar, "An error occurred while sending the request to the server."); + } + + /// + /// A partial method that gives developers a way to provide customized exception handling + /// + /// + /// + /// + /// + /// + /// + partial void OnErrorUploadFiles(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, List files, long petId); + + /// + /// uploads an images + /// + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesOrDefaultAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + try + { + return await UploadFilesAsync(files, petId, cancellationToken).ConfigureAwait(false); + } + catch (Exception) + { + return null; + } + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// + /// ID of pet to update + /// Cancellation Token to cancel the request. + /// <> + public async Task UploadFilesAsync(List files, long petId, System.Threading.CancellationToken cancellationToken = default) + { + UriBuilder uriBuilderLocalVar = new UriBuilder(); + + try + { + ValidateUploadFiles(files); + + FormatUploadFiles(files, ref petId); + + using (HttpRequestMessage httpRequestMessageLocalVar = new HttpRequestMessage()) + { + uriBuilderLocalVar.Host = HttpClient.BaseAddress.Host; + uriBuilderLocalVar.Port = HttpClient.BaseAddress.Port; + uriBuilderLocalVar.Scheme = HttpClient.BaseAddress.Scheme; + uriBuilderLocalVar.Path = HttpClient.BaseAddress.AbsolutePath == "/" + ? "/pet/{petId}/uploadImages" + : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/pet/{petId}/uploadImages"); + uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpetId%7D", Uri.EscapeDataString(petId.ToString())); + + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); + + httpRequestMessageLocalVar.Content = multipartContentLocalVar; + + List> formParameterLocalVars = new List>(); + + foreach (Org.OpenAPITools.Client.FileParameter fileParameterLocalVar in files) + { + var streamContentLocalVar = new StreamContent(fileParameterLocalVar.Content); + multipartContentLocalVar.Add(streamContentLocalVar, "files", fileParameterLocalVar.FileName ?? "files"); + } + + foreach (var formParamLocalVar in formParameterLocalVars) + multipartContentLocalVar.Add(new StringContent(formParamLocalVar.Value ?? string.Empty), formParamLocalVar.Key); + + List tokenBaseLocalVars = new List(); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; + + OAuthToken oauthTokenLocalVar1 = (OAuthToken) await OauthTokenProvider.GetAsync(cancellation: cancellationToken).ConfigureAwait(false); + + tokenBaseLocalVars.Add(oauthTokenLocalVar1); + + oauthTokenLocalVar1.UseInHeader(httpRequestMessageLocalVar, ""); + + string[] contentTypes = new string[] { + "multipart/form-data" + }; + + string[] acceptLocalVars = new string[] { + "application/json" + }; + + IEnumerable acceptHeaderValuesLocalVar = ClientUtils.SelectHeaderAcceptArray(acceptLocalVars); + + foreach (var acceptLocalVar in acceptHeaderValuesLocalVar) + httpRequestMessageLocalVar.Headers.Accept.Add(acceptLocalVar); + httpRequestMessageLocalVar.Method = new HttpMethod("POST"); + + DateTime requestedAtLocalVar = DateTime.UtcNow; + + using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false)) + { + ILogger apiResponseLoggerLocalVar = LoggerFactory.CreateLogger(); + UploadFilesApiResponse apiResponseLocalVar; + + switch ((int)httpResponseMessageLocalVar.StatusCode) { + default: { + string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync().ConfigureAwait(false); + apiResponseLocalVar = new UploadFilesApiResponse(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/pet/{petId}/uploadImages", requestedAtLocalVar, _jsonSerializerOptions); + + break; + } + } + + AfterUploadFilesDefaultImplementation(apiResponseLocalVar, files, petId); + + Events.ExecuteOnUploadFiles(apiResponseLocalVar); + + if (apiResponseLocalVar.StatusCode == (HttpStatusCode) 429) + foreach(TokenBase tokenBaseLocalVar in tokenBaseLocalVars) + tokenBaseLocalVar.BeginRateLimit(); + + return apiResponseLocalVar; + } + } + } + catch(Exception e) + { + OnErrorUploadFilesDefaultImplementation(e, "/pet/{petId}/uploadImages", uriBuilderLocalVar.Path, files, petId); + Events.ExecuteOnErrorUploadFiles(e); + throw; + } + } + + /// + /// The + /// + public partial class UploadFilesApiResponse : Org.OpenAPITools.Client.ApiResponse, IUploadFilesApiResponse + { + /// + /// The logger + /// + public ILogger Logger { get; } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, string rawContent, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, rawContent, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + /// + /// The + /// + /// + /// + /// + /// + /// + /// + /// + public UploadFilesApiResponse(ILogger logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, System.IO.Stream contentStream, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, contentStream, path, requestedAt, jsonSerializerOptions) + { + Logger = logger; + OnCreated(httpRequestMessage, httpResponseMessage); + } + + partial void OnCreated(global::System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage); + + /// + /// Returns true if the response is 200 Ok + /// + /// + public bool IsOk => 200 == (int)StatusCode; + + /// + /// Deserializes the response if the response is 200 Ok + /// + /// + public Org.OpenAPITools.Model.ApiResponse Ok() + { + // This logic may be modified with the AsModel.mustache template + return IsOk + ? System.Text.Json.JsonSerializer.Deserialize(RawContent, _jsonSerializerOptions) + : default; + } + + /// + /// Returns true if the response is 200 Ok and the deserialized response is not null + /// + /// + /// + public bool TryOk(out Org.OpenAPITools.Model.ApiResponse result) + { + result = null; + + try + { + result = Ok(); + } catch (Exception e) + { + OnDeserializationErrorDefaultImplementation(e, (HttpStatusCode)200); + } + + return result != null; + } + + private void OnDeserializationErrorDefaultImplementation(Exception exception, HttpStatusCode httpStatusCode) + { + bool suppressDefaultLog = false; + OnDeserializationError(ref suppressDefaultLog, exception, httpStatusCode); + if (!suppressDefaultLog) + Logger.LogError(exception, "An error occurred while deserializing the {code} response.", httpStatusCode); + } + + partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode); + } } } diff --git a/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Client/FileParameter.cs new file mode 100644 index 000000000000..6150dbcf4774 --- /dev/null +++ b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Client/FileParameter.cs @@ -0,0 +1,40 @@ +// +/* + * OpenAPI Petstore + * + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +namespace Org.OpenAPITools.Client +{ + /// + /// Represents a file to be uploaded as part of a multipart/form-data request. + /// + public sealed class FileParameter + { + /// + /// The file content stream. + /// + public global::System.IO.Stream Content { get; } + + /// + /// The filename sent in the Content-Disposition header. + /// When null the parameter name from the spec is used as a fallback. + /// + public string FileName { get; } + + /// + /// Creates a new . + /// + /// The file content stream. + /// Optional filename for the Content-Disposition header. + public FileParameter(global::System.IO.Stream content, string fileName = null) + { + Content = content; + FileName = fileName; + } + } +} diff --git a/samples/client/petstore/csharp/httpclient/net10/Petstore/README.md b/samples/client/petstore/csharp/httpclient/net10/Petstore/README.md index 73a7b83f20ce..1797a4d9ca09 100644 --- a/samples/client/petstore/csharp/httpclient/net10/Petstore/README.md +++ b/samples/client/petstore/csharp/httpclient/net10/Petstore/README.md @@ -178,6 +178,7 @@ Class | Method | HTTP request | Description *PetApi* | [**UpdatePetWithForm**](docs/PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data *PetApi* | [**UploadFile**](docs/PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image *PetApi* | [**UploadFileWithRequiredFile**](docs/PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) +*PetApi* | [**UploadFiles**](docs/PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images *StoreApi* | [**DeleteOrder**](docs/StoreApi.md#deleteorder) | **DELETE** /store/order/{order_id} | Delete purchase order by ID *StoreApi* | [**GetInventory**](docs/StoreApi.md#getinventory) | **GET** /store/inventory | Returns pet inventories by status *StoreApi* | [**GetOrderById**](docs/StoreApi.md#getorderbyid) | **GET** /store/order/{order_id} | Find purchase order by ID diff --git a/samples/client/petstore/csharp/httpclient/net10/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/httpclient/net10/Petstore/api/openapi.yaml index d8106a5755fc..ca451f3fb832 100644 --- a/samples/client/petstore/csharp/httpclient/net10/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/httpclient/net10/Petstore/api/openapi.yaml @@ -331,6 +331,40 @@ paths: summary: uploads an image tags: - pet + /pet/{petId}/uploadImages: + post: + description: "" + operationId: uploadFiles + parameters: + - description: ID of pet to update + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + multipart/form-data: + schema: + $ref: "#/components/schemas/uploadFiles_request" + required: true + responses: + "200": + content: + application/json: + schema: + $ref: "#/components/schemas/ApiResponse" + description: successful operation + security: + - petstore_auth: + - write:pets + - read:pets + summary: uploads an images + tags: + - pet /store/inventory: get: description: Returns a map of status codes to quantities @@ -2924,6 +2958,16 @@ components: format: binary type: string type: object + uploadFiles_request: + properties: + files: + items: + format: binary + type: string + type: array + required: + - files + type: object testEnumParameters_request: properties: enum_form_string_array: diff --git a/samples/client/petstore/csharp/httpclient/net10/Petstore/docs/PetApi.md b/samples/client/petstore/csharp/httpclient/net10/Petstore/docs/PetApi.md index e8c203c040bd..934a829307a0 100644 --- a/samples/client/petstore/csharp/httpclient/net10/Petstore/docs/PetApi.md +++ b/samples/client/petstore/csharp/httpclient/net10/Petstore/docs/PetApi.md @@ -13,6 +13,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* | [**UpdatePetWithForm**](PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data | | [**UploadFile**](PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image | | [**UploadFileWithRequiredFile**](PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) | +| [**UploadFiles**](PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images | # **AddPet** @@ -896,3 +897,101 @@ catch (ApiException e) [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + +# **UploadFiles** +> ApiResponse UploadFiles (long petId, List files) + +uploads an images + +### Example +```csharp +using System.Collections.Generic; +using System.Diagnostics; +using System.Net.Http; +using Org.OpenAPITools.Api; +using Org.OpenAPITools.Client; +using Org.OpenAPITools.Model; + +namespace Example +{ + public class UploadFilesExample + { + public static void Main() + { + Configuration config = new Configuration(); + config.BasePath = "http://petstore.swagger.io:80/v2"; + // Configure OAuth2 access token for authorization: petstore_auth + config.AccessToken = "YOUR_ACCESS_TOKEN"; + + // create instances of HttpClient, HttpClientHandler to be reused later with different Api classes + HttpClient httpClient = new HttpClient(); + HttpClientHandler httpClientHandler = new HttpClientHandler(); + var apiInstance = new PetApi(httpClient, config, httpClientHandler); + var petId = 789L; // long | ID of pet to update + var files = new List(); // List | + + try + { + // uploads an images + ApiResponse result = apiInstance.UploadFiles(petId, files); + Debug.WriteLine(result); + } + catch (ApiException e) + { + Debug.Print("Exception when calling PetApi.UploadFiles: " + e.Message); + Debug.Print("Status Code: " + e.ErrorCode); + Debug.Print(e.StackTrace); + } + } + } +} +``` + +#### Using the UploadFilesWithHttpInfo variant +This returns an ApiResponse object which contains the response data, status code and headers. + +```csharp +try +{ + // uploads an images + ApiResponse response = apiInstance.UploadFilesWithHttpInfo(petId, files); + Debug.Write("Status Code: " + response.StatusCode); + Debug.Write("Response Headers: " + response.Headers); + Debug.Write("Response Body: " + response.Data); +} +catch (ApiException e) +{ + Debug.Print("Exception when calling PetApi.UploadFilesWithHttpInfo: " + e.Message); + Debug.Print("Status Code: " + e.ErrorCode); + Debug.Print(e.StackTrace); +} +``` + +### Parameters + +| Name | Type | Description | Notes | +|------|------|-------------|-------| +| **petId** | **long** | ID of pet to update | | +| **files** | **List<FileParameter>** | | | + +### Return type + +[**ApiResponse**](ApiResponse.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: multipart/form-data + - **Accept**: application/json + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/samples/client/petstore/csharp/httpclient/net10/Petstore/src/Org.OpenAPITools/Api/PetApi.cs b/samples/client/petstore/csharp/httpclient/net10/Petstore/src/Org.OpenAPITools/Api/PetApi.cs index c76f3f3b7dfe..c84a19eb0d8e 100644 --- a/samples/client/petstore/csharp/httpclient/net10/Petstore/src/Org.OpenAPITools/Api/PetApi.cs +++ b/samples/client/petstore/csharp/httpclient/net10/Petstore/src/Org.OpenAPITools/Api/PetApi.cs @@ -214,6 +214,26 @@ public interface IPetApiSync : IApiAccessor /// Additional data to pass to server (optional) /// ApiResponse of ApiResponse ApiResponse UploadFileWithRequiredFileWithHttpInfo(long petId, FileParameter requiredFile, string? additionalMetadata = default); + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// ApiResponse + ApiResponse UploadFiles(long petId, List files); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// ApiResponse of ApiResponse + ApiResponse UploadFilesWithHttpInfo(long petId, List files); #endregion Synchronous Operations } @@ -446,6 +466,31 @@ public interface IPetApiAsync : IApiAccessor /// Cancellation Token to cancel the request. /// Task of ApiResponse (ApiResponse) System.Threading.Tasks.Task> UploadFileWithRequiredFileWithHttpInfoAsync(long petId, FileParameter requiredFile, string? additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Cancellation Token to cancel the request. + /// Task of ApiResponse + System.Threading.Tasks.Task UploadFilesAsync(long petId, List files, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Cancellation Token to cancel the request. + /// Task of ApiResponse (ApiResponse) + System.Threading.Tasks.Task> UploadFilesWithHttpInfoAsync(long petId, List files, System.Threading.CancellationToken cancellationToken = default); #endregion Asynchronous Operations } @@ -1994,5 +2039,140 @@ public async System.Threading.Tasks.Task UploadFileWithRequiredFile return localVarResponse; } + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// ApiResponse + public ApiResponse UploadFiles(long petId, List files) + { + Org.OpenAPITools.Client.ApiResponse localVarResponse = UploadFilesWithHttpInfo(petId, files); + return localVarResponse.Data; + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// ApiResponse of ApiResponse + public Org.OpenAPITools.Client.ApiResponse UploadFilesWithHttpInfo(long petId, List files) + { + // verify the required parameter 'files' is set + if (files == null) + throw new Org.OpenAPITools.Client.ApiException(400, "Missing required parameter 'files' when calling PetApi->UploadFiles"); + + Org.OpenAPITools.Client.RequestOptions localVarRequestOptions = new Org.OpenAPITools.Client.RequestOptions(); + + string[] _contentTypes = new string[] { + "multipart/form-data" + }; + + // to determine the Accept header + string[] _accepts = new string[] { + "application/json" + }; + + var localVarContentType = Org.OpenAPITools.Client.ClientUtils.SelectHeaderContentType(_contentTypes); + if (localVarContentType != null) localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType); + + var localVarAccept = Org.OpenAPITools.Client.ClientUtils.SelectHeaderAccept(_accepts); + if (localVarAccept != null) localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept); + + localVarRequestOptions.PathParameters.Add("petId", Org.OpenAPITools.Client.ClientUtils.ParameterToString(petId)); // path parameter + localVarRequestOptions.FileParameters.Add("files", files); + + // authentication (petstore_auth) required + // oauth required + if (!string.IsNullOrEmpty(this.Configuration.AccessToken) && !localVarRequestOptions.HeaderParameters.ContainsKey("Authorization")) + { + localVarRequestOptions.HeaderParameters.Add("Authorization", "Bearer " + this.Configuration.AccessToken); + } + + // make the HTTP request + var localVarResponse = this.Client.Post("/pet/{petId}/uploadImages", localVarRequestOptions, this.Configuration); + + if (this.ExceptionFactory != null) + { + Exception _exception = this.ExceptionFactory("UploadFiles", localVarResponse); + if (_exception != null) throw _exception; + } + + return localVarResponse; + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Cancellation Token to cancel the request. + /// Task of ApiResponse + public async System.Threading.Tasks.Task UploadFilesAsync(long petId, List files, System.Threading.CancellationToken cancellationToken = default) + { + Org.OpenAPITools.Client.ApiResponse localVarResponse = await UploadFilesWithHttpInfoAsync(petId, files, cancellationToken).ConfigureAwait(false); + return localVarResponse.Data; + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Cancellation Token to cancel the request. + /// Task of ApiResponse (ApiResponse) + public async System.Threading.Tasks.Task> UploadFilesWithHttpInfoAsync(long petId, List files, System.Threading.CancellationToken cancellationToken = default) + { + // verify the required parameter 'files' is set + if (files == null) + throw new Org.OpenAPITools.Client.ApiException(400, "Missing required parameter 'files' when calling PetApi->UploadFiles"); + + + Org.OpenAPITools.Client.RequestOptions localVarRequestOptions = new Org.OpenAPITools.Client.RequestOptions(); + + string[] _contentTypes = new string[] { + "multipart/form-data" + }; + + // to determine the Accept header + string[] _accepts = new string[] { + "application/json" + }; + + + var localVarContentType = Org.OpenAPITools.Client.ClientUtils.SelectHeaderContentType(_contentTypes); + if (localVarContentType != null) localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType); + + var localVarAccept = Org.OpenAPITools.Client.ClientUtils.SelectHeaderAccept(_accepts); + if (localVarAccept != null) localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept); + + localVarRequestOptions.PathParameters.Add("petId", Org.OpenAPITools.Client.ClientUtils.ParameterToString(petId)); // path parameter + localVarRequestOptions.FileParameters.Add("files", files); + + // authentication (petstore_auth) required + // oauth required + if (!string.IsNullOrEmpty(this.Configuration.AccessToken) && !localVarRequestOptions.HeaderParameters.ContainsKey("Authorization")) + { + localVarRequestOptions.HeaderParameters.Add("Authorization", "Bearer " + this.Configuration.AccessToken); + } + + // make the HTTP request + + var localVarResponse = await this.AsynchronousClient.PostAsync("/pet/{petId}/uploadImages", localVarRequestOptions, this.Configuration, cancellationToken).ConfigureAwait(false); + + if (this.ExceptionFactory != null) + { + Exception _exception = this.ExceptionFactory("UploadFiles", localVarResponse); + if (_exception != null) throw _exception; + } + + return localVarResponse; + } + } } diff --git a/samples/client/petstore/csharp/httpclient/net9/Petstore/README.md b/samples/client/petstore/csharp/httpclient/net9/Petstore/README.md index 73a7b83f20ce..1797a4d9ca09 100644 --- a/samples/client/petstore/csharp/httpclient/net9/Petstore/README.md +++ b/samples/client/petstore/csharp/httpclient/net9/Petstore/README.md @@ -178,6 +178,7 @@ Class | Method | HTTP request | Description *PetApi* | [**UpdatePetWithForm**](docs/PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data *PetApi* | [**UploadFile**](docs/PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image *PetApi* | [**UploadFileWithRequiredFile**](docs/PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) +*PetApi* | [**UploadFiles**](docs/PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images *StoreApi* | [**DeleteOrder**](docs/StoreApi.md#deleteorder) | **DELETE** /store/order/{order_id} | Delete purchase order by ID *StoreApi* | [**GetInventory**](docs/StoreApi.md#getinventory) | **GET** /store/inventory | Returns pet inventories by status *StoreApi* | [**GetOrderById**](docs/StoreApi.md#getorderbyid) | **GET** /store/order/{order_id} | Find purchase order by ID diff --git a/samples/client/petstore/csharp/httpclient/net9/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/httpclient/net9/Petstore/api/openapi.yaml index d8106a5755fc..ca451f3fb832 100644 --- a/samples/client/petstore/csharp/httpclient/net9/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/httpclient/net9/Petstore/api/openapi.yaml @@ -331,6 +331,40 @@ paths: summary: uploads an image tags: - pet + /pet/{petId}/uploadImages: + post: + description: "" + operationId: uploadFiles + parameters: + - description: ID of pet to update + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + multipart/form-data: + schema: + $ref: "#/components/schemas/uploadFiles_request" + required: true + responses: + "200": + content: + application/json: + schema: + $ref: "#/components/schemas/ApiResponse" + description: successful operation + security: + - petstore_auth: + - write:pets + - read:pets + summary: uploads an images + tags: + - pet /store/inventory: get: description: Returns a map of status codes to quantities @@ -2924,6 +2958,16 @@ components: format: binary type: string type: object + uploadFiles_request: + properties: + files: + items: + format: binary + type: string + type: array + required: + - files + type: object testEnumParameters_request: properties: enum_form_string_array: diff --git a/samples/client/petstore/csharp/httpclient/net9/Petstore/docs/PetApi.md b/samples/client/petstore/csharp/httpclient/net9/Petstore/docs/PetApi.md index e8c203c040bd..934a829307a0 100644 --- a/samples/client/petstore/csharp/httpclient/net9/Petstore/docs/PetApi.md +++ b/samples/client/petstore/csharp/httpclient/net9/Petstore/docs/PetApi.md @@ -13,6 +13,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* | [**UpdatePetWithForm**](PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data | | [**UploadFile**](PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image | | [**UploadFileWithRequiredFile**](PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) | +| [**UploadFiles**](PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images | # **AddPet** @@ -896,3 +897,101 @@ catch (ApiException e) [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + +# **UploadFiles** +> ApiResponse UploadFiles (long petId, List files) + +uploads an images + +### Example +```csharp +using System.Collections.Generic; +using System.Diagnostics; +using System.Net.Http; +using Org.OpenAPITools.Api; +using Org.OpenAPITools.Client; +using Org.OpenAPITools.Model; + +namespace Example +{ + public class UploadFilesExample + { + public static void Main() + { + Configuration config = new Configuration(); + config.BasePath = "http://petstore.swagger.io:80/v2"; + // Configure OAuth2 access token for authorization: petstore_auth + config.AccessToken = "YOUR_ACCESS_TOKEN"; + + // create instances of HttpClient, HttpClientHandler to be reused later with different Api classes + HttpClient httpClient = new HttpClient(); + HttpClientHandler httpClientHandler = new HttpClientHandler(); + var apiInstance = new PetApi(httpClient, config, httpClientHandler); + var petId = 789L; // long | ID of pet to update + var files = new List(); // List | + + try + { + // uploads an images + ApiResponse result = apiInstance.UploadFiles(petId, files); + Debug.WriteLine(result); + } + catch (ApiException e) + { + Debug.Print("Exception when calling PetApi.UploadFiles: " + e.Message); + Debug.Print("Status Code: " + e.ErrorCode); + Debug.Print(e.StackTrace); + } + } + } +} +``` + +#### Using the UploadFilesWithHttpInfo variant +This returns an ApiResponse object which contains the response data, status code and headers. + +```csharp +try +{ + // uploads an images + ApiResponse response = apiInstance.UploadFilesWithHttpInfo(petId, files); + Debug.Write("Status Code: " + response.StatusCode); + Debug.Write("Response Headers: " + response.Headers); + Debug.Write("Response Body: " + response.Data); +} +catch (ApiException e) +{ + Debug.Print("Exception when calling PetApi.UploadFilesWithHttpInfo: " + e.Message); + Debug.Print("Status Code: " + e.ErrorCode); + Debug.Print(e.StackTrace); +} +``` + +### Parameters + +| Name | Type | Description | Notes | +|------|------|-------------|-------| +| **petId** | **long** | ID of pet to update | | +| **files** | **List<FileParameter>** | | | + +### Return type + +[**ApiResponse**](ApiResponse.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: multipart/form-data + - **Accept**: application/json + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/samples/client/petstore/csharp/httpclient/net9/Petstore/src/Org.OpenAPITools/Api/PetApi.cs b/samples/client/petstore/csharp/httpclient/net9/Petstore/src/Org.OpenAPITools/Api/PetApi.cs index c76f3f3b7dfe..c84a19eb0d8e 100644 --- a/samples/client/petstore/csharp/httpclient/net9/Petstore/src/Org.OpenAPITools/Api/PetApi.cs +++ b/samples/client/petstore/csharp/httpclient/net9/Petstore/src/Org.OpenAPITools/Api/PetApi.cs @@ -214,6 +214,26 @@ public interface IPetApiSync : IApiAccessor /// Additional data to pass to server (optional) /// ApiResponse of ApiResponse ApiResponse UploadFileWithRequiredFileWithHttpInfo(long petId, FileParameter requiredFile, string? additionalMetadata = default); + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// ApiResponse + ApiResponse UploadFiles(long petId, List files); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// ApiResponse of ApiResponse + ApiResponse UploadFilesWithHttpInfo(long petId, List files); #endregion Synchronous Operations } @@ -446,6 +466,31 @@ public interface IPetApiAsync : IApiAccessor /// Cancellation Token to cancel the request. /// Task of ApiResponse (ApiResponse) System.Threading.Tasks.Task> UploadFileWithRequiredFileWithHttpInfoAsync(long petId, FileParameter requiredFile, string? additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Cancellation Token to cancel the request. + /// Task of ApiResponse + System.Threading.Tasks.Task UploadFilesAsync(long petId, List files, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Cancellation Token to cancel the request. + /// Task of ApiResponse (ApiResponse) + System.Threading.Tasks.Task> UploadFilesWithHttpInfoAsync(long petId, List files, System.Threading.CancellationToken cancellationToken = default); #endregion Asynchronous Operations } @@ -1994,5 +2039,140 @@ public async System.Threading.Tasks.Task UploadFileWithRequiredFile return localVarResponse; } + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// ApiResponse + public ApiResponse UploadFiles(long petId, List files) + { + Org.OpenAPITools.Client.ApiResponse localVarResponse = UploadFilesWithHttpInfo(petId, files); + return localVarResponse.Data; + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// ApiResponse of ApiResponse + public Org.OpenAPITools.Client.ApiResponse UploadFilesWithHttpInfo(long petId, List files) + { + // verify the required parameter 'files' is set + if (files == null) + throw new Org.OpenAPITools.Client.ApiException(400, "Missing required parameter 'files' when calling PetApi->UploadFiles"); + + Org.OpenAPITools.Client.RequestOptions localVarRequestOptions = new Org.OpenAPITools.Client.RequestOptions(); + + string[] _contentTypes = new string[] { + "multipart/form-data" + }; + + // to determine the Accept header + string[] _accepts = new string[] { + "application/json" + }; + + var localVarContentType = Org.OpenAPITools.Client.ClientUtils.SelectHeaderContentType(_contentTypes); + if (localVarContentType != null) localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType); + + var localVarAccept = Org.OpenAPITools.Client.ClientUtils.SelectHeaderAccept(_accepts); + if (localVarAccept != null) localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept); + + localVarRequestOptions.PathParameters.Add("petId", Org.OpenAPITools.Client.ClientUtils.ParameterToString(petId)); // path parameter + localVarRequestOptions.FileParameters.Add("files", files); + + // authentication (petstore_auth) required + // oauth required + if (!string.IsNullOrEmpty(this.Configuration.AccessToken) && !localVarRequestOptions.HeaderParameters.ContainsKey("Authorization")) + { + localVarRequestOptions.HeaderParameters.Add("Authorization", "Bearer " + this.Configuration.AccessToken); + } + + // make the HTTP request + var localVarResponse = this.Client.Post("/pet/{petId}/uploadImages", localVarRequestOptions, this.Configuration); + + if (this.ExceptionFactory != null) + { + Exception _exception = this.ExceptionFactory("UploadFiles", localVarResponse); + if (_exception != null) throw _exception; + } + + return localVarResponse; + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Cancellation Token to cancel the request. + /// Task of ApiResponse + public async System.Threading.Tasks.Task UploadFilesAsync(long petId, List files, System.Threading.CancellationToken cancellationToken = default) + { + Org.OpenAPITools.Client.ApiResponse localVarResponse = await UploadFilesWithHttpInfoAsync(petId, files, cancellationToken).ConfigureAwait(false); + return localVarResponse.Data; + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Cancellation Token to cancel the request. + /// Task of ApiResponse (ApiResponse) + public async System.Threading.Tasks.Task> UploadFilesWithHttpInfoAsync(long petId, List files, System.Threading.CancellationToken cancellationToken = default) + { + // verify the required parameter 'files' is set + if (files == null) + throw new Org.OpenAPITools.Client.ApiException(400, "Missing required parameter 'files' when calling PetApi->UploadFiles"); + + + Org.OpenAPITools.Client.RequestOptions localVarRequestOptions = new Org.OpenAPITools.Client.RequestOptions(); + + string[] _contentTypes = new string[] { + "multipart/form-data" + }; + + // to determine the Accept header + string[] _accepts = new string[] { + "application/json" + }; + + + var localVarContentType = Org.OpenAPITools.Client.ClientUtils.SelectHeaderContentType(_contentTypes); + if (localVarContentType != null) localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType); + + var localVarAccept = Org.OpenAPITools.Client.ClientUtils.SelectHeaderAccept(_accepts); + if (localVarAccept != null) localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept); + + localVarRequestOptions.PathParameters.Add("petId", Org.OpenAPITools.Client.ClientUtils.ParameterToString(petId)); // path parameter + localVarRequestOptions.FileParameters.Add("files", files); + + // authentication (petstore_auth) required + // oauth required + if (!string.IsNullOrEmpty(this.Configuration.AccessToken) && !localVarRequestOptions.HeaderParameters.ContainsKey("Authorization")) + { + localVarRequestOptions.HeaderParameters.Add("Authorization", "Bearer " + this.Configuration.AccessToken); + } + + // make the HTTP request + + var localVarResponse = await this.AsynchronousClient.PostAsync("/pet/{petId}/uploadImages", localVarRequestOptions, this.Configuration, cancellationToken).ConfigureAwait(false); + + if (this.ExceptionFactory != null) + { + Exception _exception = this.ExceptionFactory("UploadFiles", localVarResponse); + if (_exception != null) throw _exception; + } + + return localVarResponse; + } + } } diff --git a/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/README.md b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/README.md index 0a0407f2aa98..50e735052990 100644 --- a/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/README.md +++ b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/README.md @@ -166,6 +166,7 @@ Class | Method | HTTP request | Description *PetApi* | [**UpdatePetWithForm**](docs/PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data *PetApi* | [**UploadFile**](docs/PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image *PetApi* | [**UploadFileWithRequiredFile**](docs/PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) +*PetApi* | [**UploadFiles**](docs/PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images *StoreApi* | [**DeleteOrder**](docs/StoreApi.md#deleteorder) | **DELETE** /store/order/{order_id} | Delete purchase order by ID *StoreApi* | [**GetInventory**](docs/StoreApi.md#getinventory) | **GET** /store/inventory | Returns pet inventories by status *StoreApi* | [**GetOrderById**](docs/StoreApi.md#getorderbyid) | **GET** /store/order/{order_id} | Find purchase order by ID diff --git a/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/api/openapi.yaml index d8106a5755fc..ca451f3fb832 100644 --- a/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/api/openapi.yaml @@ -331,6 +331,40 @@ paths: summary: uploads an image tags: - pet + /pet/{petId}/uploadImages: + post: + description: "" + operationId: uploadFiles + parameters: + - description: ID of pet to update + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + multipart/form-data: + schema: + $ref: "#/components/schemas/uploadFiles_request" + required: true + responses: + "200": + content: + application/json: + schema: + $ref: "#/components/schemas/ApiResponse" + description: successful operation + security: + - petstore_auth: + - write:pets + - read:pets + summary: uploads an images + tags: + - pet /store/inventory: get: description: Returns a map of status codes to quantities @@ -2924,6 +2958,16 @@ components: format: binary type: string type: object + uploadFiles_request: + properties: + files: + items: + format: binary + type: string + type: array + required: + - files + type: object testEnumParameters_request: properties: enum_form_string_array: diff --git a/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/docs/PetApi.md b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/docs/PetApi.md index b7d549524b65..eb03434c366b 100644 --- a/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/docs/PetApi.md +++ b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/docs/PetApi.md @@ -13,6 +13,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* | [**UpdatePetWithForm**](PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data | | [**UploadFile**](PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image | | [**UploadFileWithRequiredFile**](PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) | +| [**UploadFiles**](PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images | # **AddPet** @@ -896,3 +897,101 @@ catch (ApiException e) [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + +# **UploadFiles** +> ApiResponse UploadFiles (long petId, List files) + +uploads an images + +### Example +```csharp +using System.Collections.Generic; +using System.Diagnostics; +using System.Net.Http; +using Org.OpenAPITools.Api; +using Org.OpenAPITools.Client; +using Org.OpenAPITools.Model; + +namespace Example +{ + public class UploadFilesExample + { + public static void Main() + { + Configuration config = new Configuration(); + config.BasePath = "http://petstore.swagger.io:80/v2"; + // Configure OAuth2 access token for authorization: petstore_auth + config.AccessToken = "YOUR_ACCESS_TOKEN"; + + // create instances of HttpClient, HttpClientHandler to be reused later with different Api classes + HttpClient httpClient = new HttpClient(); + HttpClientHandler httpClientHandler = new HttpClientHandler(); + var apiInstance = new PetApi(httpClient, config, httpClientHandler); + var petId = 789L; // long | ID of pet to update + var files = new List(); // List | + + try + { + // uploads an images + ApiResponse result = apiInstance.UploadFiles(petId, files); + Debug.WriteLine(result); + } + catch (ApiException e) + { + Debug.Print("Exception when calling PetApi.UploadFiles: " + e.Message); + Debug.Print("Status Code: " + e.ErrorCode); + Debug.Print(e.StackTrace); + } + } + } +} +``` + +#### Using the UploadFilesWithHttpInfo variant +This returns an ApiResponse object which contains the response data, status code and headers. + +```csharp +try +{ + // uploads an images + ApiResponse response = apiInstance.UploadFilesWithHttpInfo(petId, files); + Debug.Write("Status Code: " + response.StatusCode); + Debug.Write("Response Headers: " + response.Headers); + Debug.Write("Response Body: " + response.Data); +} +catch (ApiException e) +{ + Debug.Print("Exception when calling PetApi.UploadFilesWithHttpInfo: " + e.Message); + Debug.Print("Status Code: " + e.ErrorCode); + Debug.Print(e.StackTrace); +} +``` + +### Parameters + +| Name | Type | Description | Notes | +|------|------|-------------|-------| +| **petId** | **long** | ID of pet to update | | +| **files** | **List<FileParameter>** | | | + +### Return type + +[**ApiResponse**](ApiResponse.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: multipart/form-data + - **Accept**: application/json + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/src/Org.OpenAPITools/Api/PetApi.cs b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/src/Org.OpenAPITools/Api/PetApi.cs index ec2d209ced03..fb1604fe0013 100644 --- a/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/src/Org.OpenAPITools/Api/PetApi.cs +++ b/samples/client/petstore/csharp/httpclient/standard2.0/Petstore/src/Org.OpenAPITools/Api/PetApi.cs @@ -214,6 +214,26 @@ public interface IPetApiSync : IApiAccessor /// Additional data to pass to server (optional) /// ApiResponse of ApiResponse ApiResponse UploadFileWithRequiredFileWithHttpInfo(long petId, FileParameter requiredFile, string additionalMetadata = default); + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// ApiResponse + ApiResponse UploadFiles(long petId, List files); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// ApiResponse of ApiResponse + ApiResponse UploadFilesWithHttpInfo(long petId, List files); #endregion Synchronous Operations } @@ -446,6 +466,31 @@ public interface IPetApiAsync : IApiAccessor /// Cancellation Token to cancel the request. /// Task of ApiResponse (ApiResponse) System.Threading.Tasks.Task> UploadFileWithRequiredFileWithHttpInfoAsync(long petId, FileParameter requiredFile, string additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Cancellation Token to cancel the request. + /// Task of ApiResponse + System.Threading.Tasks.Task UploadFilesAsync(long petId, List files, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Cancellation Token to cancel the request. + /// Task of ApiResponse (ApiResponse) + System.Threading.Tasks.Task> UploadFilesWithHttpInfoAsync(long petId, List files, System.Threading.CancellationToken cancellationToken = default); #endregion Asynchronous Operations } @@ -1994,5 +2039,140 @@ public async System.Threading.Tasks.Task UploadFileWithRequiredFile return localVarResponse; } + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// ApiResponse + public ApiResponse UploadFiles(long petId, List files) + { + Org.OpenAPITools.Client.ApiResponse localVarResponse = UploadFilesWithHttpInfo(petId, files); + return localVarResponse.Data; + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// ApiResponse of ApiResponse + public Org.OpenAPITools.Client.ApiResponse UploadFilesWithHttpInfo(long petId, List files) + { + // verify the required parameter 'files' is set + if (files == null) + throw new Org.OpenAPITools.Client.ApiException(400, "Missing required parameter 'files' when calling PetApi->UploadFiles"); + + Org.OpenAPITools.Client.RequestOptions localVarRequestOptions = new Org.OpenAPITools.Client.RequestOptions(); + + string[] _contentTypes = new string[] { + "multipart/form-data" + }; + + // to determine the Accept header + string[] _accepts = new string[] { + "application/json" + }; + + var localVarContentType = Org.OpenAPITools.Client.ClientUtils.SelectHeaderContentType(_contentTypes); + if (localVarContentType != null) localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType); + + var localVarAccept = Org.OpenAPITools.Client.ClientUtils.SelectHeaderAccept(_accepts); + if (localVarAccept != null) localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept); + + localVarRequestOptions.PathParameters.Add("petId", Org.OpenAPITools.Client.ClientUtils.ParameterToString(petId)); // path parameter + localVarRequestOptions.FileParameters.Add("files", files); + + // authentication (petstore_auth) required + // oauth required + if (!string.IsNullOrEmpty(this.Configuration.AccessToken) && !localVarRequestOptions.HeaderParameters.ContainsKey("Authorization")) + { + localVarRequestOptions.HeaderParameters.Add("Authorization", "Bearer " + this.Configuration.AccessToken); + } + + // make the HTTP request + var localVarResponse = this.Client.Post("/pet/{petId}/uploadImages", localVarRequestOptions, this.Configuration); + + if (this.ExceptionFactory != null) + { + Exception _exception = this.ExceptionFactory("UploadFiles", localVarResponse); + if (_exception != null) throw _exception; + } + + return localVarResponse; + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Cancellation Token to cancel the request. + /// Task of ApiResponse + public async System.Threading.Tasks.Task UploadFilesAsync(long petId, List files, System.Threading.CancellationToken cancellationToken = default) + { + Org.OpenAPITools.Client.ApiResponse localVarResponse = await UploadFilesWithHttpInfoAsync(petId, files, cancellationToken).ConfigureAwait(false); + return localVarResponse.Data; + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Cancellation Token to cancel the request. + /// Task of ApiResponse (ApiResponse) + public async System.Threading.Tasks.Task> UploadFilesWithHttpInfoAsync(long petId, List files, System.Threading.CancellationToken cancellationToken = default) + { + // verify the required parameter 'files' is set + if (files == null) + throw new Org.OpenAPITools.Client.ApiException(400, "Missing required parameter 'files' when calling PetApi->UploadFiles"); + + + Org.OpenAPITools.Client.RequestOptions localVarRequestOptions = new Org.OpenAPITools.Client.RequestOptions(); + + string[] _contentTypes = new string[] { + "multipart/form-data" + }; + + // to determine the Accept header + string[] _accepts = new string[] { + "application/json" + }; + + + var localVarContentType = Org.OpenAPITools.Client.ClientUtils.SelectHeaderContentType(_contentTypes); + if (localVarContentType != null) localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType); + + var localVarAccept = Org.OpenAPITools.Client.ClientUtils.SelectHeaderAccept(_accepts); + if (localVarAccept != null) localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept); + + localVarRequestOptions.PathParameters.Add("petId", Org.OpenAPITools.Client.ClientUtils.ParameterToString(petId)); // path parameter + localVarRequestOptions.FileParameters.Add("files", files); + + // authentication (petstore_auth) required + // oauth required + if (!string.IsNullOrEmpty(this.Configuration.AccessToken) && !localVarRequestOptions.HeaderParameters.ContainsKey("Authorization")) + { + localVarRequestOptions.HeaderParameters.Add("Authorization", "Bearer " + this.Configuration.AccessToken); + } + + // make the HTTP request + + var localVarResponse = await this.AsynchronousClient.PostAsync("/pet/{petId}/uploadImages", localVarRequestOptions, this.Configuration, cancellationToken).ConfigureAwait(false); + + if (this.ExceptionFactory != null) + { + Exception _exception = this.ExceptionFactory("UploadFiles", localVarResponse); + if (_exception != null) throw _exception; + } + + return localVarResponse; + } + } } diff --git a/samples/client/petstore/csharp/restsharp/net8/Petstore/README.md b/samples/client/petstore/csharp/restsharp/net8/Petstore/README.md index 1db3095f8f3b..ded19553c295 100644 --- a/samples/client/petstore/csharp/restsharp/net8/Petstore/README.md +++ b/samples/client/petstore/csharp/restsharp/net8/Petstore/README.md @@ -153,6 +153,7 @@ Class | Method | HTTP request | Description *PetApi* | [**UpdatePetWithForm**](docs/PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data *PetApi* | [**UploadFile**](docs/PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image *PetApi* | [**UploadFileWithRequiredFile**](docs/PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) +*PetApi* | [**UploadFiles**](docs/PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images *StoreApi* | [**DeleteOrder**](docs/StoreApi.md#deleteorder) | **DELETE** /store/order/{order_id} | Delete purchase order by ID *StoreApi* | [**GetInventory**](docs/StoreApi.md#getinventory) | **GET** /store/inventory | Returns pet inventories by status *StoreApi* | [**GetOrderById**](docs/StoreApi.md#getorderbyid) | **GET** /store/order/{order_id} | Find purchase order by ID diff --git a/samples/client/petstore/csharp/restsharp/net8/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/restsharp/net8/Petstore/api/openapi.yaml index d8106a5755fc..ca451f3fb832 100644 --- a/samples/client/petstore/csharp/restsharp/net8/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/restsharp/net8/Petstore/api/openapi.yaml @@ -331,6 +331,40 @@ paths: summary: uploads an image tags: - pet + /pet/{petId}/uploadImages: + post: + description: "" + operationId: uploadFiles + parameters: + - description: ID of pet to update + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + multipart/form-data: + schema: + $ref: "#/components/schemas/uploadFiles_request" + required: true + responses: + "200": + content: + application/json: + schema: + $ref: "#/components/schemas/ApiResponse" + description: successful operation + security: + - petstore_auth: + - write:pets + - read:pets + summary: uploads an images + tags: + - pet /store/inventory: get: description: Returns a map of status codes to quantities @@ -2924,6 +2958,16 @@ components: format: binary type: string type: object + uploadFiles_request: + properties: + files: + items: + format: binary + type: string + type: array + required: + - files + type: object testEnumParameters_request: properties: enum_form_string_array: diff --git a/samples/client/petstore/csharp/restsharp/net8/Petstore/docs/PetApi.md b/samples/client/petstore/csharp/restsharp/net8/Petstore/docs/PetApi.md index 5272a0b102c3..829ca6d25184 100644 --- a/samples/client/petstore/csharp/restsharp/net8/Petstore/docs/PetApi.md +++ b/samples/client/petstore/csharp/restsharp/net8/Petstore/docs/PetApi.md @@ -13,6 +13,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* | [**UpdatePetWithForm**](PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data | | [**UploadFile**](PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image | | [**UploadFileWithRequiredFile**](PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) | +| [**UploadFiles**](PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images | # **AddPet** @@ -860,3 +861,97 @@ catch (ApiException e) [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + +# **UploadFiles** +> ApiResponse UploadFiles (long petId, List files) + +uploads an images + +### Example +```csharp +using System.Collections.Generic; +using System.Diagnostics; +using Org.OpenAPITools.Api; +using Org.OpenAPITools.Client; +using Org.OpenAPITools.Model; + +namespace Example +{ + public class UploadFilesExample + { + public static void Main() + { + Configuration config = new Configuration(); + config.BasePath = "http://petstore.swagger.io:80/v2"; + // Configure OAuth2 access token for authorization: petstore_auth + config.AccessToken = "YOUR_ACCESS_TOKEN"; + + var apiInstance = new PetApi(config); + var petId = 789L; // long | ID of pet to update + var files = new List(); // List | + + try + { + // uploads an images + ApiResponse result = apiInstance.UploadFiles(petId, files); + Debug.WriteLine(result); + } + catch (ApiException e) + { + Debug.Print("Exception when calling PetApi.UploadFiles: " + e.Message); + Debug.Print("Status Code: " + e.ErrorCode); + Debug.Print(e.StackTrace); + } + } + } +} +``` + +#### Using the UploadFilesWithHttpInfo variant +This returns an ApiResponse object which contains the response data, status code and headers. + +```csharp +try +{ + // uploads an images + ApiResponse response = apiInstance.UploadFilesWithHttpInfo(petId, files); + Debug.Write("Status Code: " + response.StatusCode); + Debug.Write("Response Headers: " + response.Headers); + Debug.Write("Response Body: " + response.Data); +} +catch (ApiException e) +{ + Debug.Print("Exception when calling PetApi.UploadFilesWithHttpInfo: " + e.Message); + Debug.Print("Status Code: " + e.ErrorCode); + Debug.Print(e.StackTrace); +} +``` + +### Parameters + +| Name | Type | Description | Notes | +|------|------|-------------|-------| +| **petId** | **long** | ID of pet to update | | +| **files** | **List<System.IO.Stream>** | | | + +### Return type + +[**ApiResponse**](ApiResponse.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: multipart/form-data + - **Accept**: application/json + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/samples/client/petstore/csharp/restsharp/net8/Petstore/src/Org.OpenAPITools/Api/PetApi.cs b/samples/client/petstore/csharp/restsharp/net8/Petstore/src/Org.OpenAPITools/Api/PetApi.cs index 86b40ec17eb1..1ea79a1c545a 100644 --- a/samples/client/petstore/csharp/restsharp/net8/Petstore/src/Org.OpenAPITools/Api/PetApi.cs +++ b/samples/client/petstore/csharp/restsharp/net8/Petstore/src/Org.OpenAPITools/Api/PetApi.cs @@ -232,6 +232,28 @@ public interface IPetApiSync : IApiAccessor /// Index associated with the operation. /// ApiResponse of ApiResponse ApiResponse UploadFileWithRequiredFileWithHttpInfo(long petId, System.IO.Stream requiredFile, string? additionalMetadata = default, int operationIndex = 0); + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Index associated with the operation. + /// ApiResponse + ApiResponse UploadFiles(long petId, List files, int operationIndex = 0); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Index associated with the operation. + /// ApiResponse of ApiResponse + ApiResponse UploadFilesWithHttpInfo(long petId, List files, int operationIndex = 0); #endregion Synchronous Operations } @@ -482,6 +504,33 @@ public interface IPetApiAsync : IApiAccessor /// Cancellation Token to cancel the request. /// Task of ApiResponse (ApiResponse) System.Threading.Tasks.Task> UploadFileWithRequiredFileWithHttpInfoAsync(long petId, System.IO.Stream requiredFile, string? additionalMetadata = default, int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default); + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Index associated with the operation. + /// Cancellation Token to cancel the request. + /// Task of ApiResponse + System.Threading.Tasks.Task UploadFilesAsync(long petId, List files, int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Index associated with the operation. + /// Cancellation Token to cancel the request. + /// Task of ApiResponse (ApiResponse) + System.Threading.Tasks.Task> UploadFilesWithHttpInfoAsync(long petId, List files, int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default); #endregion Asynchronous Operations } @@ -2351,5 +2400,196 @@ public async System.Threading.Tasks.Task UploadFileWithRequiredFile return localVarResponse; } + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Index associated with the operation. + /// ApiResponse + public ApiResponse UploadFiles(long petId, List files, int operationIndex = 0) + { + Org.OpenAPITools.Client.ApiResponse localVarResponse = UploadFilesWithHttpInfo(petId, files); + return localVarResponse.Data; + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Index associated with the operation. + /// ApiResponse of ApiResponse + public Org.OpenAPITools.Client.ApiResponse UploadFilesWithHttpInfo(long petId, List files, int operationIndex = 0) + { + // verify the required parameter 'files' is set + if (files == null) + { + throw new Org.OpenAPITools.Client.ApiException(400, "Missing required parameter 'files' when calling PetApi->UploadFiles"); + } + + Org.OpenAPITools.Client.RequestOptions localVarRequestOptions = new Org.OpenAPITools.Client.RequestOptions(); + + string[] _contentTypes = new string[] { + "multipart/form-data" + }; + + // to determine the Accept header + string[] _accepts = new string[] { + "application/json" + }; + + var localVarContentType = Org.OpenAPITools.Client.ClientUtils.SelectHeaderContentType(_contentTypes); + var localVarMultipartFormData = localVarContentType == "multipart/form-data"; + if (localVarContentType != null) + { + localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType); + } + + var localVarAccept = Org.OpenAPITools.Client.ClientUtils.SelectHeaderAccept(_accepts); + if (localVarAccept != null) + { + localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept); + } + + localVarRequestOptions.PathParameters.Add("petId", Org.OpenAPITools.Client.ClientUtils.ParameterToString(petId)); // path parameter + foreach (var file in files) + { + localVarRequestOptions.FileParameters.Add("files", file); + } + + localVarRequestOptions.Operation = "PetApi.UploadFiles"; + localVarRequestOptions.OperationIndex = operationIndex; + + // authentication (petstore_auth) required + // oauth required + if (!localVarRequestOptions.HeaderParameters.ContainsKey("Authorization")) + { + if (!string.IsNullOrEmpty(this.Configuration.AccessToken)) + { + localVarRequestOptions.HeaderParameters.Add("Authorization", "Bearer " + this.Configuration.AccessToken); + } + else if (!string.IsNullOrEmpty(this.Configuration.OAuthTokenUrl) && + !string.IsNullOrEmpty(this.Configuration.OAuthClientId) && + !string.IsNullOrEmpty(this.Configuration.OAuthClientSecret) && + this.Configuration.OAuthFlow != null) + { + localVarRequestOptions.OAuth = true; + } + } + + // make the HTTP request + var localVarResponse = this.Client.Post("/pet/{petId}/uploadImages", localVarRequestOptions, this.Configuration); + if (this.ExceptionFactory != null) + { + Exception _exception = this.ExceptionFactory("UploadFiles", localVarResponse); + if (_exception != null) + { + throw _exception; + } + } + + return localVarResponse; + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Index associated with the operation. + /// Cancellation Token to cancel the request. + /// Task of ApiResponse + public async System.Threading.Tasks.Task UploadFilesAsync(long petId, List files, int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default) + { + Org.OpenAPITools.Client.ApiResponse localVarResponse = await UploadFilesWithHttpInfoAsync(petId, files, operationIndex, cancellationToken).ConfigureAwait(false); + return localVarResponse.Data; + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Index associated with the operation. + /// Cancellation Token to cancel the request. + /// Task of ApiResponse (ApiResponse) + public async System.Threading.Tasks.Task> UploadFilesWithHttpInfoAsync(long petId, List files, int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default) + { + // verify the required parameter 'files' is set + if (files == null) + { + throw new Org.OpenAPITools.Client.ApiException(400, "Missing required parameter 'files' when calling PetApi->UploadFiles"); + } + + + Org.OpenAPITools.Client.RequestOptions localVarRequestOptions = new Org.OpenAPITools.Client.RequestOptions(); + + string[] _contentTypes = new string[] { + "multipart/form-data" + }; + + // to determine the Accept header + string[] _accepts = new string[] { + "application/json" + }; + + var localVarContentType = Org.OpenAPITools.Client.ClientUtils.SelectHeaderContentType(_contentTypes); + if (localVarContentType != null) + { + localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType); + } + + var localVarAccept = Org.OpenAPITools.Client.ClientUtils.SelectHeaderAccept(_accepts); + if (localVarAccept != null) + { + localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept); + } + + localVarRequestOptions.PathParameters.Add("petId", Org.OpenAPITools.Client.ClientUtils.ParameterToString(petId)); // path parameter + foreach (var file in files) + { + localVarRequestOptions.FileParameters.Add("files", file); + } + + localVarRequestOptions.Operation = "PetApi.UploadFiles"; + localVarRequestOptions.OperationIndex = operationIndex; + + // authentication (petstore_auth) required + // oauth required + if (!localVarRequestOptions.HeaderParameters.ContainsKey("Authorization")) + { + if (!string.IsNullOrEmpty(this.Configuration.AccessToken)) + { + localVarRequestOptions.HeaderParameters.Add("Authorization", "Bearer " + this.Configuration.AccessToken); + } + else if (!string.IsNullOrEmpty(this.Configuration.OAuthTokenUrl) && + !string.IsNullOrEmpty(this.Configuration.OAuthClientId) && + !string.IsNullOrEmpty(this.Configuration.OAuthClientSecret) && + this.Configuration.OAuthFlow != null) + { + localVarRequestOptions.OAuth = true; + } + } + + // make the HTTP request + var localVarResponse = await this.AsynchronousClient.PostAsync("/pet/{petId}/uploadImages", localVarRequestOptions, this.Configuration, cancellationToken).ConfigureAwait(false); + + if (this.ExceptionFactory != null) + { + Exception _exception = this.ExceptionFactory("UploadFiles", localVarResponse); + if (_exception != null) + { + throw _exception; + } + } + + return localVarResponse; + } + } } diff --git a/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/README.md b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/README.md index f7f95f4a3abf..af9ad0d78405 100644 --- a/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/README.md +++ b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/README.md @@ -141,6 +141,7 @@ Class | Method | HTTP request | Description *PetApi* | [**UpdatePetWithForm**](docs/PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data *PetApi* | [**UploadFile**](docs/PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image *PetApi* | [**UploadFileWithRequiredFile**](docs/PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) +*PetApi* | [**UploadFiles**](docs/PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images *StoreApi* | [**DeleteOrder**](docs/StoreApi.md#deleteorder) | **DELETE** /store/order/{order_id} | Delete purchase order by ID *StoreApi* | [**GetInventory**](docs/StoreApi.md#getinventory) | **GET** /store/inventory | Returns pet inventories by status *StoreApi* | [**GetOrderById**](docs/StoreApi.md#getorderbyid) | **GET** /store/order/{order_id} | Find purchase order by ID diff --git a/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/api/openapi.yaml b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/api/openapi.yaml index d8106a5755fc..ca451f3fb832 100644 --- a/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/api/openapi.yaml +++ b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/api/openapi.yaml @@ -331,6 +331,40 @@ paths: summary: uploads an image tags: - pet + /pet/{petId}/uploadImages: + post: + description: "" + operationId: uploadFiles + parameters: + - description: ID of pet to update + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + multipart/form-data: + schema: + $ref: "#/components/schemas/uploadFiles_request" + required: true + responses: + "200": + content: + application/json: + schema: + $ref: "#/components/schemas/ApiResponse" + description: successful operation + security: + - petstore_auth: + - write:pets + - read:pets + summary: uploads an images + tags: + - pet /store/inventory: get: description: Returns a map of status codes to quantities @@ -2924,6 +2958,16 @@ components: format: binary type: string type: object + uploadFiles_request: + properties: + files: + items: + format: binary + type: string + type: array + required: + - files + type: object testEnumParameters_request: properties: enum_form_string_array: diff --git a/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/docs/PetApi.md b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/docs/PetApi.md index 3db7da1cd2fa..cb3a65d239b4 100644 --- a/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/docs/PetApi.md +++ b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/docs/PetApi.md @@ -13,6 +13,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* | [**UpdatePetWithForm**](PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data | | [**UploadFile**](PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image | | [**UploadFileWithRequiredFile**](PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) | +| [**UploadFiles**](PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images | # **AddPet** @@ -860,3 +861,97 @@ catch (ApiException e) [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + +# **UploadFiles** +> ApiResponse UploadFiles (long petId, List files) + +uploads an images + +### Example +```csharp +using System.Collections.Generic; +using System.Diagnostics; +using Org.OpenAPITools.Api; +using Org.OpenAPITools.Client; +using Org.OpenAPITools.Model; + +namespace Example +{ + public class UploadFilesExample + { + public static void Main() + { + Configuration config = new Configuration(); + config.BasePath = "http://petstore.swagger.io:80/v2"; + // Configure OAuth2 access token for authorization: petstore_auth + config.AccessToken = "YOUR_ACCESS_TOKEN"; + + var apiInstance = new PetApi(config); + var petId = 789L; // long | ID of pet to update + var files = new List(); // List | + + try + { + // uploads an images + ApiResponse result = apiInstance.UploadFiles(petId, files); + Debug.WriteLine(result); + } + catch (ApiException e) + { + Debug.Print("Exception when calling PetApi.UploadFiles: " + e.Message); + Debug.Print("Status Code: " + e.ErrorCode); + Debug.Print(e.StackTrace); + } + } + } +} +``` + +#### Using the UploadFilesWithHttpInfo variant +This returns an ApiResponse object which contains the response data, status code and headers. + +```csharp +try +{ + // uploads an images + ApiResponse response = apiInstance.UploadFilesWithHttpInfo(petId, files); + Debug.Write("Status Code: " + response.StatusCode); + Debug.Write("Response Headers: " + response.Headers); + Debug.Write("Response Body: " + response.Data); +} +catch (ApiException e) +{ + Debug.Print("Exception when calling PetApi.UploadFilesWithHttpInfo: " + e.Message); + Debug.Print("Status Code: " + e.ErrorCode); + Debug.Print(e.StackTrace); +} +``` + +### Parameters + +| Name | Type | Description | Notes | +|------|------|-------------|-------| +| **petId** | **long** | ID of pet to update | | +| **files** | **List<System.IO.Stream>** | | | + +### Return type + +[**ApiResponse**](ApiResponse.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: multipart/form-data + - **Accept**: application/json + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools/Api/PetApi.cs b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools/Api/PetApi.cs index d6cbbc5133ed..8e0e14cc18dc 100644 --- a/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools/Api/PetApi.cs +++ b/samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools/Api/PetApi.cs @@ -232,6 +232,28 @@ public interface IPetApiSync : IApiAccessor /// Index associated with the operation. /// ApiResponse of ApiResponse ApiResponse UploadFileWithRequiredFileWithHttpInfo(long petId, System.IO.Stream requiredFile, string additionalMetadata = default, int operationIndex = 0); + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Index associated with the operation. + /// ApiResponse + ApiResponse UploadFiles(long petId, List files, int operationIndex = 0); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Index associated with the operation. + /// ApiResponse of ApiResponse + ApiResponse UploadFilesWithHttpInfo(long petId, List files, int operationIndex = 0); #endregion Synchronous Operations } @@ -482,6 +504,33 @@ public interface IPetApiAsync : IApiAccessor /// Cancellation Token to cancel the request. /// Task of ApiResponse (ApiResponse) System.Threading.Tasks.Task> UploadFileWithRequiredFileWithHttpInfoAsync(long petId, System.IO.Stream requiredFile, string additionalMetadata = default, int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default); + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Index associated with the operation. + /// Cancellation Token to cancel the request. + /// Task of ApiResponse + System.Threading.Tasks.Task UploadFilesAsync(long petId, List files, int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Index associated with the operation. + /// Cancellation Token to cancel the request. + /// Task of ApiResponse (ApiResponse) + System.Threading.Tasks.Task> UploadFilesWithHttpInfoAsync(long petId, List files, int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default); #endregion Asynchronous Operations } @@ -2351,5 +2400,196 @@ public async System.Threading.Tasks.Task UploadFileWithRequiredFile return localVarResponse; } + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Index associated with the operation. + /// ApiResponse + public ApiResponse UploadFiles(long petId, List files, int operationIndex = 0) + { + Org.OpenAPITools.Client.ApiResponse localVarResponse = UploadFilesWithHttpInfo(petId, files); + return localVarResponse.Data; + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Index associated with the operation. + /// ApiResponse of ApiResponse + public Org.OpenAPITools.Client.ApiResponse UploadFilesWithHttpInfo(long petId, List files, int operationIndex = 0) + { + // verify the required parameter 'files' is set + if (files == null) + { + throw new Org.OpenAPITools.Client.ApiException(400, "Missing required parameter 'files' when calling PetApi->UploadFiles"); + } + + Org.OpenAPITools.Client.RequestOptions localVarRequestOptions = new Org.OpenAPITools.Client.RequestOptions(); + + string[] _contentTypes = new string[] { + "multipart/form-data" + }; + + // to determine the Accept header + string[] _accepts = new string[] { + "application/json" + }; + + var localVarContentType = Org.OpenAPITools.Client.ClientUtils.SelectHeaderContentType(_contentTypes); + var localVarMultipartFormData = localVarContentType == "multipart/form-data"; + if (localVarContentType != null) + { + localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType); + } + + var localVarAccept = Org.OpenAPITools.Client.ClientUtils.SelectHeaderAccept(_accepts); + if (localVarAccept != null) + { + localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept); + } + + localVarRequestOptions.PathParameters.Add("petId", Org.OpenAPITools.Client.ClientUtils.ParameterToString(petId)); // path parameter + foreach (var file in files) + { + localVarRequestOptions.FileParameters.Add("files", file); + } + + localVarRequestOptions.Operation = "PetApi.UploadFiles"; + localVarRequestOptions.OperationIndex = operationIndex; + + // authentication (petstore_auth) required + // oauth required + if (!localVarRequestOptions.HeaderParameters.ContainsKey("Authorization")) + { + if (!string.IsNullOrEmpty(this.Configuration.AccessToken)) + { + localVarRequestOptions.HeaderParameters.Add("Authorization", "Bearer " + this.Configuration.AccessToken); + } + else if (!string.IsNullOrEmpty(this.Configuration.OAuthTokenUrl) && + !string.IsNullOrEmpty(this.Configuration.OAuthClientId) && + !string.IsNullOrEmpty(this.Configuration.OAuthClientSecret) && + this.Configuration.OAuthFlow != null) + { + localVarRequestOptions.OAuth = true; + } + } + + // make the HTTP request + var localVarResponse = this.Client.Post("/pet/{petId}/uploadImages", localVarRequestOptions, this.Configuration); + if (this.ExceptionFactory != null) + { + Exception _exception = this.ExceptionFactory("UploadFiles", localVarResponse); + if (_exception != null) + { + throw _exception; + } + } + + return localVarResponse; + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Index associated with the operation. + /// Cancellation Token to cancel the request. + /// Task of ApiResponse + public async System.Threading.Tasks.Task UploadFilesAsync(long petId, List files, int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default) + { + Org.OpenAPITools.Client.ApiResponse localVarResponse = await UploadFilesWithHttpInfoAsync(petId, files, operationIndex, cancellationToken).ConfigureAwait(false); + return localVarResponse.Data; + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Index associated with the operation. + /// Cancellation Token to cancel the request. + /// Task of ApiResponse (ApiResponse) + public async System.Threading.Tasks.Task> UploadFilesWithHttpInfoAsync(long petId, List files, int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default) + { + // verify the required parameter 'files' is set + if (files == null) + { + throw new Org.OpenAPITools.Client.ApiException(400, "Missing required parameter 'files' when calling PetApi->UploadFiles"); + } + + + Org.OpenAPITools.Client.RequestOptions localVarRequestOptions = new Org.OpenAPITools.Client.RequestOptions(); + + string[] _contentTypes = new string[] { + "multipart/form-data" + }; + + // to determine the Accept header + string[] _accepts = new string[] { + "application/json" + }; + + var localVarContentType = Org.OpenAPITools.Client.ClientUtils.SelectHeaderContentType(_contentTypes); + if (localVarContentType != null) + { + localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType); + } + + var localVarAccept = Org.OpenAPITools.Client.ClientUtils.SelectHeaderAccept(_accepts); + if (localVarAccept != null) + { + localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept); + } + + localVarRequestOptions.PathParameters.Add("petId", Org.OpenAPITools.Client.ClientUtils.ParameterToString(petId)); // path parameter + foreach (var file in files) + { + localVarRequestOptions.FileParameters.Add("files", file); + } + + localVarRequestOptions.Operation = "PetApi.UploadFiles"; + localVarRequestOptions.OperationIndex = operationIndex; + + // authentication (petstore_auth) required + // oauth required + if (!localVarRequestOptions.HeaderParameters.ContainsKey("Authorization")) + { + if (!string.IsNullOrEmpty(this.Configuration.AccessToken)) + { + localVarRequestOptions.HeaderParameters.Add("Authorization", "Bearer " + this.Configuration.AccessToken); + } + else if (!string.IsNullOrEmpty(this.Configuration.OAuthTokenUrl) && + !string.IsNullOrEmpty(this.Configuration.OAuthClientId) && + !string.IsNullOrEmpty(this.Configuration.OAuthClientSecret) && + this.Configuration.OAuthFlow != null) + { + localVarRequestOptions.OAuth = true; + } + } + + // make the HTTP request + var localVarResponse = await this.AsynchronousClient.PostAsync("/pet/{petId}/uploadImages", localVarRequestOptions, this.Configuration, cancellationToken).ConfigureAwait(false); + + if (this.ExceptionFactory != null) + { + Exception _exception = this.ExceptionFactory("UploadFiles", localVarResponse); + if (_exception != null) + { + throw _exception; + } + } + + return localVarResponse; + } + } } diff --git a/samples/client/petstore/csharp/unityWebRequest/net10/Petstore/README.md b/samples/client/petstore/csharp/unityWebRequest/net10/Petstore/README.md index 3e2173e6db41..f3a7c402bb1a 100644 --- a/samples/client/petstore/csharp/unityWebRequest/net10/Petstore/README.md +++ b/samples/client/petstore/csharp/unityWebRequest/net10/Petstore/README.md @@ -127,6 +127,7 @@ Class | Method | HTTP request | Description *PetApi* | [**UpdatePetWithForm**](PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data *PetApi* | [**UploadFile**](PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image *PetApi* | [**UploadFileWithRequiredFile**](PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) +*PetApi* | [**UploadFiles**](PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images *StoreApi* | [**DeleteOrder**](StoreApi.md#deleteorder) | **DELETE** /store/order/{order_id} | Delete purchase order by ID *StoreApi* | [**GetInventory**](StoreApi.md#getinventory) | **GET** /store/inventory | Returns pet inventories by status *StoreApi* | [**GetOrderById**](StoreApi.md#getorderbyid) | **GET** /store/order/{order_id} | Find purchase order by ID diff --git a/samples/client/petstore/csharp/unityWebRequest/net10/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/unityWebRequest/net10/Petstore/api/openapi.yaml index d8106a5755fc..ca451f3fb832 100644 --- a/samples/client/petstore/csharp/unityWebRequest/net10/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/unityWebRequest/net10/Petstore/api/openapi.yaml @@ -331,6 +331,40 @@ paths: summary: uploads an image tags: - pet + /pet/{petId}/uploadImages: + post: + description: "" + operationId: uploadFiles + parameters: + - description: ID of pet to update + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + multipart/form-data: + schema: + $ref: "#/components/schemas/uploadFiles_request" + required: true + responses: + "200": + content: + application/json: + schema: + $ref: "#/components/schemas/ApiResponse" + description: successful operation + security: + - petstore_auth: + - write:pets + - read:pets + summary: uploads an images + tags: + - pet /store/inventory: get: description: Returns a map of status codes to quantities @@ -2924,6 +2958,16 @@ components: format: binary type: string type: object + uploadFiles_request: + properties: + files: + items: + format: binary + type: string + type: array + required: + - files + type: object testEnumParameters_request: properties: enum_form_string_array: diff --git a/samples/client/petstore/csharp/unityWebRequest/net10/Petstore/docs/PetApi.md b/samples/client/petstore/csharp/unityWebRequest/net10/Petstore/docs/PetApi.md index 5272a0b102c3..829ca6d25184 100644 --- a/samples/client/petstore/csharp/unityWebRequest/net10/Petstore/docs/PetApi.md +++ b/samples/client/petstore/csharp/unityWebRequest/net10/Petstore/docs/PetApi.md @@ -13,6 +13,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* | [**UpdatePetWithForm**](PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data | | [**UploadFile**](PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image | | [**UploadFileWithRequiredFile**](PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) | +| [**UploadFiles**](PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images | # **AddPet** @@ -860,3 +861,97 @@ catch (ApiException e) [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + +# **UploadFiles** +> ApiResponse UploadFiles (long petId, List files) + +uploads an images + +### Example +```csharp +using System.Collections.Generic; +using System.Diagnostics; +using Org.OpenAPITools.Api; +using Org.OpenAPITools.Client; +using Org.OpenAPITools.Model; + +namespace Example +{ + public class UploadFilesExample + { + public static void Main() + { + Configuration config = new Configuration(); + config.BasePath = "http://petstore.swagger.io:80/v2"; + // Configure OAuth2 access token for authorization: petstore_auth + config.AccessToken = "YOUR_ACCESS_TOKEN"; + + var apiInstance = new PetApi(config); + var petId = 789L; // long | ID of pet to update + var files = new List(); // List | + + try + { + // uploads an images + ApiResponse result = apiInstance.UploadFiles(petId, files); + Debug.WriteLine(result); + } + catch (ApiException e) + { + Debug.Print("Exception when calling PetApi.UploadFiles: " + e.Message); + Debug.Print("Status Code: " + e.ErrorCode); + Debug.Print(e.StackTrace); + } + } + } +} +``` + +#### Using the UploadFilesWithHttpInfo variant +This returns an ApiResponse object which contains the response data, status code and headers. + +```csharp +try +{ + // uploads an images + ApiResponse response = apiInstance.UploadFilesWithHttpInfo(petId, files); + Debug.Write("Status Code: " + response.StatusCode); + Debug.Write("Response Headers: " + response.Headers); + Debug.Write("Response Body: " + response.Data); +} +catch (ApiException e) +{ + Debug.Print("Exception when calling PetApi.UploadFilesWithHttpInfo: " + e.Message); + Debug.Print("Status Code: " + e.ErrorCode); + Debug.Print(e.StackTrace); +} +``` + +### Parameters + +| Name | Type | Description | Notes | +|------|------|-------------|-------| +| **petId** | **long** | ID of pet to update | | +| **files** | **List<System.IO.Stream>** | | | + +### Return type + +[**ApiResponse**](ApiResponse.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: multipart/form-data + - **Accept**: application/json + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/samples/client/petstore/csharp/unityWebRequest/net10/Petstore/src/Org.OpenAPITools/Api/PetApi.cs b/samples/client/petstore/csharp/unityWebRequest/net10/Petstore/src/Org.OpenAPITools/Api/PetApi.cs index 2c624280f114..d23685664bc2 100644 --- a/samples/client/petstore/csharp/unityWebRequest/net10/Petstore/src/Org.OpenAPITools/Api/PetApi.cs +++ b/samples/client/petstore/csharp/unityWebRequest/net10/Petstore/src/Org.OpenAPITools/Api/PetApi.cs @@ -213,6 +213,26 @@ public interface IPetApiSync : IApiAccessor /// Additional data to pass to server (optional) /// ApiResponse of ApiResponse ApiResponse UploadFileWithRequiredFileWithHttpInfo(long petId, System.IO.Stream requiredFile, string? additionalMetadata = default); + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// ApiResponse + ApiResponse UploadFiles(long petId, List files); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// ApiResponse of ApiResponse + ApiResponse UploadFilesWithHttpInfo(long petId, List files); #endregion Synchronous Operations } @@ -445,6 +465,31 @@ public interface IPetApiAsync : IApiAccessor /// Cancellation Token to cancel the request. /// Task of ApiResponse (ApiResponse) System.Threading.Tasks.Task> UploadFileWithRequiredFileWithHttpInfoAsync(long petId, System.IO.Stream requiredFile, string? additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Cancellation Token to cancel the request. + /// Task of ApiResponse + System.Threading.Tasks.Task UploadFilesAsync(long petId, List files, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Cancellation Token to cancel the request. + /// Task of ApiResponse (ApiResponse) + System.Threading.Tasks.Task> UploadFilesWithHttpInfoAsync(long petId, List files, System.Threading.CancellationToken cancellationToken = default); #endregion Asynchronous Operations } @@ -2019,5 +2064,149 @@ public async System.Threading.Tasks.Task UploadFileWithRequiredFile return localVarResponse; } + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// ApiResponse + public ApiResponse UploadFiles(long petId, List files) + { + Org.OpenAPITools.Client.ApiResponse localVarResponse = UploadFilesWithHttpInfo(petId, files); + return localVarResponse.Data; + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// ApiResponse of ApiResponse + public Org.OpenAPITools.Client.ApiResponse UploadFilesWithHttpInfo(long petId, List files) + { + // verify the required parameter 'files' is set + if (files == null) + throw new Org.OpenAPITools.Client.ApiException(400, "Missing required parameter 'files' when calling PetApi->UploadFiles"); + + Org.OpenAPITools.Client.RequestOptions localVarRequestOptions = new Org.OpenAPITools.Client.RequestOptions(); + + string[] _contentTypes = new string[] { + "multipart/form-data" + }; + + // to determine the Accept header + string[] _accepts = new string[] { + "application/json" + }; + + var localVarContentType = Org.OpenAPITools.Client.ClientUtils.SelectHeaderContentType(_contentTypes); + if (localVarContentType != null) localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType); + + var localVarAccept = Org.OpenAPITools.Client.ClientUtils.SelectHeaderAccept(_accepts); + if (localVarAccept != null) localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept); + + localVarRequestOptions.PathParameters.Add("petId", Org.OpenAPITools.Client.ClientUtils.ParameterToString(petId)); // path parameter + + // authentication (petstore_auth) required + // oauth required + if (!string.IsNullOrEmpty(this.Configuration.AccessToken) && !localVarRequestOptions.HeaderParameters.ContainsKey("Authorization")) + { + localVarRequestOptions.HeaderParameters.Add("Authorization", "Bearer " + this.Configuration.AccessToken); + } + + // make the HTTP request + var localVarResponse = this.Client.Post("/pet/{petId}/uploadImages", localVarRequestOptions, this.Configuration); + + if (this.ExceptionFactory != null) + { + Exception _exception = this.ExceptionFactory("UploadFiles", localVarResponse); + if (_exception != null) throw _exception; + } + + return localVarResponse; + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Cancellation Token to cancel the request. + /// Task of ApiResponse + public async System.Threading.Tasks.Task UploadFilesAsync(long petId, List files, System.Threading.CancellationToken cancellationToken = default) + { + var task = UploadFilesWithHttpInfoAsync(petId, files, cancellationToken); +#if UNITY_EDITOR || !UNITY_WEBGL + Org.OpenAPITools.Client.ApiResponse localVarResponse = await task.ConfigureAwait(false); +#else + Org.OpenAPITools.Client.ApiResponse localVarResponse = await task; +#endif + return localVarResponse.Data; + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Cancellation Token to cancel the request. + /// Task of ApiResponse (ApiResponse) + public async System.Threading.Tasks.Task> UploadFilesWithHttpInfoAsync(long petId, List files, System.Threading.CancellationToken cancellationToken = default) + { + // verify the required parameter 'files' is set + if (files == null) + throw new Org.OpenAPITools.Client.ApiException(400, "Missing required parameter 'files' when calling PetApi->UploadFiles"); + + + Org.OpenAPITools.Client.RequestOptions localVarRequestOptions = new Org.OpenAPITools.Client.RequestOptions(); + + string[] _contentTypes = new string[] { + "multipart/form-data" + }; + + // to determine the Accept header + string[] _accepts = new string[] { + "application/json" + }; + + + var localVarContentType = Org.OpenAPITools.Client.ClientUtils.SelectHeaderContentType(_contentTypes); + if (localVarContentType != null) localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType); + + var localVarAccept = Org.OpenAPITools.Client.ClientUtils.SelectHeaderAccept(_accepts); + if (localVarAccept != null) localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept); + + localVarRequestOptions.PathParameters.Add("petId", Org.OpenAPITools.Client.ClientUtils.ParameterToString(petId)); // path parameter + + // authentication (petstore_auth) required + // oauth required + if (!string.IsNullOrEmpty(this.Configuration.AccessToken) && !localVarRequestOptions.HeaderParameters.ContainsKey("Authorization")) + { + localVarRequestOptions.HeaderParameters.Add("Authorization", "Bearer " + this.Configuration.AccessToken); + } + + // make the HTTP request + + var task = this.AsynchronousClient.PostAsync("/pet/{petId}/uploadImages", localVarRequestOptions, this.Configuration, cancellationToken); + +#if UNITY_EDITOR || !UNITY_WEBGL + var localVarResponse = await task.ConfigureAwait(false); +#else + var localVarResponse = await task; +#endif + + if (this.ExceptionFactory != null) + { + Exception _exception = this.ExceptionFactory("UploadFiles", localVarResponse); + if (_exception != null) throw _exception; + } + + return localVarResponse; + } + } } diff --git a/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/README.md b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/README.md index 3e2173e6db41..f3a7c402bb1a 100644 --- a/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/README.md +++ b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/README.md @@ -127,6 +127,7 @@ Class | Method | HTTP request | Description *PetApi* | [**UpdatePetWithForm**](PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data *PetApi* | [**UploadFile**](PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image *PetApi* | [**UploadFileWithRequiredFile**](PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) +*PetApi* | [**UploadFiles**](PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images *StoreApi* | [**DeleteOrder**](StoreApi.md#deleteorder) | **DELETE** /store/order/{order_id} | Delete purchase order by ID *StoreApi* | [**GetInventory**](StoreApi.md#getinventory) | **GET** /store/inventory | Returns pet inventories by status *StoreApi* | [**GetOrderById**](StoreApi.md#getorderbyid) | **GET** /store/order/{order_id} | Find purchase order by ID diff --git a/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/api/openapi.yaml index d8106a5755fc..ca451f3fb832 100644 --- a/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/api/openapi.yaml @@ -331,6 +331,40 @@ paths: summary: uploads an image tags: - pet + /pet/{petId}/uploadImages: + post: + description: "" + operationId: uploadFiles + parameters: + - description: ID of pet to update + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + multipart/form-data: + schema: + $ref: "#/components/schemas/uploadFiles_request" + required: true + responses: + "200": + content: + application/json: + schema: + $ref: "#/components/schemas/ApiResponse" + description: successful operation + security: + - petstore_auth: + - write:pets + - read:pets + summary: uploads an images + tags: + - pet /store/inventory: get: description: Returns a map of status codes to quantities @@ -2924,6 +2958,16 @@ components: format: binary type: string type: object + uploadFiles_request: + properties: + files: + items: + format: binary + type: string + type: array + required: + - files + type: object testEnumParameters_request: properties: enum_form_string_array: diff --git a/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/docs/PetApi.md b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/docs/PetApi.md index 5272a0b102c3..829ca6d25184 100644 --- a/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/docs/PetApi.md +++ b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/docs/PetApi.md @@ -13,6 +13,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* | [**UpdatePetWithForm**](PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data | | [**UploadFile**](PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image | | [**UploadFileWithRequiredFile**](PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) | +| [**UploadFiles**](PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images | # **AddPet** @@ -860,3 +861,97 @@ catch (ApiException e) [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + +# **UploadFiles** +> ApiResponse UploadFiles (long petId, List files) + +uploads an images + +### Example +```csharp +using System.Collections.Generic; +using System.Diagnostics; +using Org.OpenAPITools.Api; +using Org.OpenAPITools.Client; +using Org.OpenAPITools.Model; + +namespace Example +{ + public class UploadFilesExample + { + public static void Main() + { + Configuration config = new Configuration(); + config.BasePath = "http://petstore.swagger.io:80/v2"; + // Configure OAuth2 access token for authorization: petstore_auth + config.AccessToken = "YOUR_ACCESS_TOKEN"; + + var apiInstance = new PetApi(config); + var petId = 789L; // long | ID of pet to update + var files = new List(); // List | + + try + { + // uploads an images + ApiResponse result = apiInstance.UploadFiles(petId, files); + Debug.WriteLine(result); + } + catch (ApiException e) + { + Debug.Print("Exception when calling PetApi.UploadFiles: " + e.Message); + Debug.Print("Status Code: " + e.ErrorCode); + Debug.Print(e.StackTrace); + } + } + } +} +``` + +#### Using the UploadFilesWithHttpInfo variant +This returns an ApiResponse object which contains the response data, status code and headers. + +```csharp +try +{ + // uploads an images + ApiResponse response = apiInstance.UploadFilesWithHttpInfo(petId, files); + Debug.Write("Status Code: " + response.StatusCode); + Debug.Write("Response Headers: " + response.Headers); + Debug.Write("Response Body: " + response.Data); +} +catch (ApiException e) +{ + Debug.Print("Exception when calling PetApi.UploadFilesWithHttpInfo: " + e.Message); + Debug.Print("Status Code: " + e.ErrorCode); + Debug.Print(e.StackTrace); +} +``` + +### Parameters + +| Name | Type | Description | Notes | +|------|------|-------------|-------| +| **petId** | **long** | ID of pet to update | | +| **files** | **List<System.IO.Stream>** | | | + +### Return type + +[**ApiResponse**](ApiResponse.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: multipart/form-data + - **Accept**: application/json + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/src/Org.OpenAPITools/Api/PetApi.cs b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/src/Org.OpenAPITools/Api/PetApi.cs index 2c624280f114..d23685664bc2 100644 --- a/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/src/Org.OpenAPITools/Api/PetApi.cs +++ b/samples/client/petstore/csharp/unityWebRequest/net9/Petstore/src/Org.OpenAPITools/Api/PetApi.cs @@ -213,6 +213,26 @@ public interface IPetApiSync : IApiAccessor /// Additional data to pass to server (optional) /// ApiResponse of ApiResponse ApiResponse UploadFileWithRequiredFileWithHttpInfo(long petId, System.IO.Stream requiredFile, string? additionalMetadata = default); + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// ApiResponse + ApiResponse UploadFiles(long petId, List files); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// ApiResponse of ApiResponse + ApiResponse UploadFilesWithHttpInfo(long petId, List files); #endregion Synchronous Operations } @@ -445,6 +465,31 @@ public interface IPetApiAsync : IApiAccessor /// Cancellation Token to cancel the request. /// Task of ApiResponse (ApiResponse) System.Threading.Tasks.Task> UploadFileWithRequiredFileWithHttpInfoAsync(long petId, System.IO.Stream requiredFile, string? additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Cancellation Token to cancel the request. + /// Task of ApiResponse + System.Threading.Tasks.Task UploadFilesAsync(long petId, List files, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Cancellation Token to cancel the request. + /// Task of ApiResponse (ApiResponse) + System.Threading.Tasks.Task> UploadFilesWithHttpInfoAsync(long petId, List files, System.Threading.CancellationToken cancellationToken = default); #endregion Asynchronous Operations } @@ -2019,5 +2064,149 @@ public async System.Threading.Tasks.Task UploadFileWithRequiredFile return localVarResponse; } + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// ApiResponse + public ApiResponse UploadFiles(long petId, List files) + { + Org.OpenAPITools.Client.ApiResponse localVarResponse = UploadFilesWithHttpInfo(petId, files); + return localVarResponse.Data; + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// ApiResponse of ApiResponse + public Org.OpenAPITools.Client.ApiResponse UploadFilesWithHttpInfo(long petId, List files) + { + // verify the required parameter 'files' is set + if (files == null) + throw new Org.OpenAPITools.Client.ApiException(400, "Missing required parameter 'files' when calling PetApi->UploadFiles"); + + Org.OpenAPITools.Client.RequestOptions localVarRequestOptions = new Org.OpenAPITools.Client.RequestOptions(); + + string[] _contentTypes = new string[] { + "multipart/form-data" + }; + + // to determine the Accept header + string[] _accepts = new string[] { + "application/json" + }; + + var localVarContentType = Org.OpenAPITools.Client.ClientUtils.SelectHeaderContentType(_contentTypes); + if (localVarContentType != null) localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType); + + var localVarAccept = Org.OpenAPITools.Client.ClientUtils.SelectHeaderAccept(_accepts); + if (localVarAccept != null) localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept); + + localVarRequestOptions.PathParameters.Add("petId", Org.OpenAPITools.Client.ClientUtils.ParameterToString(petId)); // path parameter + + // authentication (petstore_auth) required + // oauth required + if (!string.IsNullOrEmpty(this.Configuration.AccessToken) && !localVarRequestOptions.HeaderParameters.ContainsKey("Authorization")) + { + localVarRequestOptions.HeaderParameters.Add("Authorization", "Bearer " + this.Configuration.AccessToken); + } + + // make the HTTP request + var localVarResponse = this.Client.Post("/pet/{petId}/uploadImages", localVarRequestOptions, this.Configuration); + + if (this.ExceptionFactory != null) + { + Exception _exception = this.ExceptionFactory("UploadFiles", localVarResponse); + if (_exception != null) throw _exception; + } + + return localVarResponse; + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Cancellation Token to cancel the request. + /// Task of ApiResponse + public async System.Threading.Tasks.Task UploadFilesAsync(long petId, List files, System.Threading.CancellationToken cancellationToken = default) + { + var task = UploadFilesWithHttpInfoAsync(petId, files, cancellationToken); +#if UNITY_EDITOR || !UNITY_WEBGL + Org.OpenAPITools.Client.ApiResponse localVarResponse = await task.ConfigureAwait(false); +#else + Org.OpenAPITools.Client.ApiResponse localVarResponse = await task; +#endif + return localVarResponse.Data; + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Cancellation Token to cancel the request. + /// Task of ApiResponse (ApiResponse) + public async System.Threading.Tasks.Task> UploadFilesWithHttpInfoAsync(long petId, List files, System.Threading.CancellationToken cancellationToken = default) + { + // verify the required parameter 'files' is set + if (files == null) + throw new Org.OpenAPITools.Client.ApiException(400, "Missing required parameter 'files' when calling PetApi->UploadFiles"); + + + Org.OpenAPITools.Client.RequestOptions localVarRequestOptions = new Org.OpenAPITools.Client.RequestOptions(); + + string[] _contentTypes = new string[] { + "multipart/form-data" + }; + + // to determine the Accept header + string[] _accepts = new string[] { + "application/json" + }; + + + var localVarContentType = Org.OpenAPITools.Client.ClientUtils.SelectHeaderContentType(_contentTypes); + if (localVarContentType != null) localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType); + + var localVarAccept = Org.OpenAPITools.Client.ClientUtils.SelectHeaderAccept(_accepts); + if (localVarAccept != null) localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept); + + localVarRequestOptions.PathParameters.Add("petId", Org.OpenAPITools.Client.ClientUtils.ParameterToString(petId)); // path parameter + + // authentication (petstore_auth) required + // oauth required + if (!string.IsNullOrEmpty(this.Configuration.AccessToken) && !localVarRequestOptions.HeaderParameters.ContainsKey("Authorization")) + { + localVarRequestOptions.HeaderParameters.Add("Authorization", "Bearer " + this.Configuration.AccessToken); + } + + // make the HTTP request + + var task = this.AsynchronousClient.PostAsync("/pet/{petId}/uploadImages", localVarRequestOptions, this.Configuration, cancellationToken); + +#if UNITY_EDITOR || !UNITY_WEBGL + var localVarResponse = await task.ConfigureAwait(false); +#else + var localVarResponse = await task; +#endif + + if (this.ExceptionFactory != null) + { + Exception _exception = this.ExceptionFactory("UploadFiles", localVarResponse); + if (_exception != null) throw _exception; + } + + return localVarResponse; + } + } } diff --git a/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/README.md b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/README.md index 3e2173e6db41..f3a7c402bb1a 100644 --- a/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/README.md +++ b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/README.md @@ -127,6 +127,7 @@ Class | Method | HTTP request | Description *PetApi* | [**UpdatePetWithForm**](PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data *PetApi* | [**UploadFile**](PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image *PetApi* | [**UploadFileWithRequiredFile**](PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) +*PetApi* | [**UploadFiles**](PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images *StoreApi* | [**DeleteOrder**](StoreApi.md#deleteorder) | **DELETE** /store/order/{order_id} | Delete purchase order by ID *StoreApi* | [**GetInventory**](StoreApi.md#getinventory) | **GET** /store/inventory | Returns pet inventories by status *StoreApi* | [**GetOrderById**](StoreApi.md#getorderbyid) | **GET** /store/order/{order_id} | Find purchase order by ID diff --git a/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/api/openapi.yaml b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/api/openapi.yaml index d8106a5755fc..ca451f3fb832 100644 --- a/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/api/openapi.yaml +++ b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/api/openapi.yaml @@ -331,6 +331,40 @@ paths: summary: uploads an image tags: - pet + /pet/{petId}/uploadImages: + post: + description: "" + operationId: uploadFiles + parameters: + - description: ID of pet to update + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + multipart/form-data: + schema: + $ref: "#/components/schemas/uploadFiles_request" + required: true + responses: + "200": + content: + application/json: + schema: + $ref: "#/components/schemas/ApiResponse" + description: successful operation + security: + - petstore_auth: + - write:pets + - read:pets + summary: uploads an images + tags: + - pet /store/inventory: get: description: Returns a map of status codes to quantities @@ -2924,6 +2958,16 @@ components: format: binary type: string type: object + uploadFiles_request: + properties: + files: + items: + format: binary + type: string + type: array + required: + - files + type: object testEnumParameters_request: properties: enum_form_string_array: diff --git a/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/docs/PetApi.md b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/docs/PetApi.md index 3db7da1cd2fa..cb3a65d239b4 100644 --- a/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/docs/PetApi.md +++ b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/docs/PetApi.md @@ -13,6 +13,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2* | [**UpdatePetWithForm**](PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data | | [**UploadFile**](PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image | | [**UploadFileWithRequiredFile**](PetApi.md#uploadfilewithrequiredfile) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) | +| [**UploadFiles**](PetApi.md#uploadfiles) | **POST** /pet/{petId}/uploadImages | uploads an images | # **AddPet** @@ -860,3 +861,97 @@ catch (ApiException e) [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + +# **UploadFiles** +> ApiResponse UploadFiles (long petId, List files) + +uploads an images + +### Example +```csharp +using System.Collections.Generic; +using System.Diagnostics; +using Org.OpenAPITools.Api; +using Org.OpenAPITools.Client; +using Org.OpenAPITools.Model; + +namespace Example +{ + public class UploadFilesExample + { + public static void Main() + { + Configuration config = new Configuration(); + config.BasePath = "http://petstore.swagger.io:80/v2"; + // Configure OAuth2 access token for authorization: petstore_auth + config.AccessToken = "YOUR_ACCESS_TOKEN"; + + var apiInstance = new PetApi(config); + var petId = 789L; // long | ID of pet to update + var files = new List(); // List | + + try + { + // uploads an images + ApiResponse result = apiInstance.UploadFiles(petId, files); + Debug.WriteLine(result); + } + catch (ApiException e) + { + Debug.Print("Exception when calling PetApi.UploadFiles: " + e.Message); + Debug.Print("Status Code: " + e.ErrorCode); + Debug.Print(e.StackTrace); + } + } + } +} +``` + +#### Using the UploadFilesWithHttpInfo variant +This returns an ApiResponse object which contains the response data, status code and headers. + +```csharp +try +{ + // uploads an images + ApiResponse response = apiInstance.UploadFilesWithHttpInfo(petId, files); + Debug.Write("Status Code: " + response.StatusCode); + Debug.Write("Response Headers: " + response.Headers); + Debug.Write("Response Body: " + response.Data); +} +catch (ApiException e) +{ + Debug.Print("Exception when calling PetApi.UploadFilesWithHttpInfo: " + e.Message); + Debug.Print("Status Code: " + e.ErrorCode); + Debug.Print(e.StackTrace); +} +``` + +### Parameters + +| Name | Type | Description | Notes | +|------|------|-------------|-------| +| **petId** | **long** | ID of pet to update | | +| **files** | **List<System.IO.Stream>** | | | + +### Return type + +[**ApiResponse**](ApiResponse.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + + - **Content-Type**: multipart/form-data + - **Accept**: application/json + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/src/Org.OpenAPITools/Api/PetApi.cs b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/src/Org.OpenAPITools/Api/PetApi.cs index 91f1a9769b50..767573545c91 100644 --- a/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/src/Org.OpenAPITools/Api/PetApi.cs +++ b/samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/src/Org.OpenAPITools/Api/PetApi.cs @@ -213,6 +213,26 @@ public interface IPetApiSync : IApiAccessor /// Additional data to pass to server (optional) /// ApiResponse of ApiResponse ApiResponse UploadFileWithRequiredFileWithHttpInfo(long petId, System.IO.Stream requiredFile, string additionalMetadata = default); + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// ApiResponse + ApiResponse UploadFiles(long petId, List files); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// ApiResponse of ApiResponse + ApiResponse UploadFilesWithHttpInfo(long petId, List files); #endregion Synchronous Operations } @@ -445,6 +465,31 @@ public interface IPetApiAsync : IApiAccessor /// Cancellation Token to cancel the request. /// Task of ApiResponse (ApiResponse) System.Threading.Tasks.Task> UploadFileWithRequiredFileWithHttpInfoAsync(long petId, System.IO.Stream requiredFile, string additionalMetadata = default, System.Threading.CancellationToken cancellationToken = default); + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Cancellation Token to cancel the request. + /// Task of ApiResponse + System.Threading.Tasks.Task UploadFilesAsync(long petId, List files, System.Threading.CancellationToken cancellationToken = default); + + /// + /// uploads an images + /// + /// + /// + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Cancellation Token to cancel the request. + /// Task of ApiResponse (ApiResponse) + System.Threading.Tasks.Task> UploadFilesWithHttpInfoAsync(long petId, List files, System.Threading.CancellationToken cancellationToken = default); #endregion Asynchronous Operations } @@ -2019,5 +2064,149 @@ public async System.Threading.Tasks.Task UploadFileWithRequiredFile return localVarResponse; } + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// ApiResponse + public ApiResponse UploadFiles(long petId, List files) + { + Org.OpenAPITools.Client.ApiResponse localVarResponse = UploadFilesWithHttpInfo(petId, files); + return localVarResponse.Data; + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// ApiResponse of ApiResponse + public Org.OpenAPITools.Client.ApiResponse UploadFilesWithHttpInfo(long petId, List files) + { + // verify the required parameter 'files' is set + if (files == null) + throw new Org.OpenAPITools.Client.ApiException(400, "Missing required parameter 'files' when calling PetApi->UploadFiles"); + + Org.OpenAPITools.Client.RequestOptions localVarRequestOptions = new Org.OpenAPITools.Client.RequestOptions(); + + string[] _contentTypes = new string[] { + "multipart/form-data" + }; + + // to determine the Accept header + string[] _accepts = new string[] { + "application/json" + }; + + var localVarContentType = Org.OpenAPITools.Client.ClientUtils.SelectHeaderContentType(_contentTypes); + if (localVarContentType != null) localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType); + + var localVarAccept = Org.OpenAPITools.Client.ClientUtils.SelectHeaderAccept(_accepts); + if (localVarAccept != null) localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept); + + localVarRequestOptions.PathParameters.Add("petId", Org.OpenAPITools.Client.ClientUtils.ParameterToString(petId)); // path parameter + + // authentication (petstore_auth) required + // oauth required + if (!string.IsNullOrEmpty(this.Configuration.AccessToken) && !localVarRequestOptions.HeaderParameters.ContainsKey("Authorization")) + { + localVarRequestOptions.HeaderParameters.Add("Authorization", "Bearer " + this.Configuration.AccessToken); + } + + // make the HTTP request + var localVarResponse = this.Client.Post("/pet/{petId}/uploadImages", localVarRequestOptions, this.Configuration); + + if (this.ExceptionFactory != null) + { + Exception _exception = this.ExceptionFactory("UploadFiles", localVarResponse); + if (_exception != null) throw _exception; + } + + return localVarResponse; + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Cancellation Token to cancel the request. + /// Task of ApiResponse + public async System.Threading.Tasks.Task UploadFilesAsync(long petId, List files, System.Threading.CancellationToken cancellationToken = default) + { + var task = UploadFilesWithHttpInfoAsync(petId, files, cancellationToken); +#if UNITY_EDITOR || !UNITY_WEBGL + Org.OpenAPITools.Client.ApiResponse localVarResponse = await task.ConfigureAwait(false); +#else + Org.OpenAPITools.Client.ApiResponse localVarResponse = await task; +#endif + return localVarResponse.Data; + } + + /// + /// uploads an images + /// + /// Thrown when fails to make API call + /// ID of pet to update + /// + /// Cancellation Token to cancel the request. + /// Task of ApiResponse (ApiResponse) + public async System.Threading.Tasks.Task> UploadFilesWithHttpInfoAsync(long petId, List files, System.Threading.CancellationToken cancellationToken = default) + { + // verify the required parameter 'files' is set + if (files == null) + throw new Org.OpenAPITools.Client.ApiException(400, "Missing required parameter 'files' when calling PetApi->UploadFiles"); + + + Org.OpenAPITools.Client.RequestOptions localVarRequestOptions = new Org.OpenAPITools.Client.RequestOptions(); + + string[] _contentTypes = new string[] { + "multipart/form-data" + }; + + // to determine the Accept header + string[] _accepts = new string[] { + "application/json" + }; + + + var localVarContentType = Org.OpenAPITools.Client.ClientUtils.SelectHeaderContentType(_contentTypes); + if (localVarContentType != null) localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType); + + var localVarAccept = Org.OpenAPITools.Client.ClientUtils.SelectHeaderAccept(_accepts); + if (localVarAccept != null) localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept); + + localVarRequestOptions.PathParameters.Add("petId", Org.OpenAPITools.Client.ClientUtils.ParameterToString(petId)); // path parameter + + // authentication (petstore_auth) required + // oauth required + if (!string.IsNullOrEmpty(this.Configuration.AccessToken) && !localVarRequestOptions.HeaderParameters.ContainsKey("Authorization")) + { + localVarRequestOptions.HeaderParameters.Add("Authorization", "Bearer " + this.Configuration.AccessToken); + } + + // make the HTTP request + + var task = this.AsynchronousClient.PostAsync("/pet/{petId}/uploadImages", localVarRequestOptions, this.Configuration, cancellationToken); + +#if UNITY_EDITOR || !UNITY_WEBGL + var localVarResponse = await task.ConfigureAwait(false); +#else + var localVarResponse = await task; +#endif + + if (this.ExceptionFactory != null) + { + Exception _exception = this.ExceptionFactory("UploadFiles", localVarResponse); + if (_exception != null) throw _exception; + } + + return localVarResponse; + } + } }