From ea0251647c4cb04e1f46933bb0847627755bda19 Mon Sep 17 00:00:00 2001 From: devhl Date: Sun, 25 Jan 2026 16:53:18 -0500 Subject: [PATCH 1/2] better file support --- .../csharp/libraries/generichost/api.mustache | 41 +- ...odels-for-testing-with-http-signature.yaml | 40 ++ .../net10/FormModels/api/openapi.yaml | 44 +++ .../net10/FormModels/docs/apis/PetApi.md | 36 ++ .../src/Org.OpenAPITools/Api/DefaultApi.cs | 7 +- .../src/Org.OpenAPITools/Api/FakeApi.cs | 26 +- .../src/Org.OpenAPITools/Api/PetApi.cs | 367 +++++++++++++++++- .../net10/NullReferenceTypes/api/openapi.yaml | 44 +++ .../NullReferenceTypes/docs/apis/PetApi.md | 36 ++ .../src/Org.OpenAPITools/Api/DefaultApi.cs | 7 +- .../src/Org.OpenAPITools/Api/FakeApi.cs | 26 +- .../src/Org.OpenAPITools/Api/PetApi.cs | 367 +++++++++++++++++- .../net10/Petstore/api/openapi.yaml | 44 +++ .../net10/Petstore/docs/apis/PetApi.md | 36 ++ .../src/Org.OpenAPITools/Api/DefaultApi.cs | 7 +- .../src/Org.OpenAPITools/Api/FakeApi.cs | 26 +- .../src/Org.OpenAPITools/Api/PetApi.cs | 367 +++++++++++++++++- .../net10/SourceGeneration/api/openapi.yaml | 44 +++ .../SourceGeneration/docs/apis/PetApi.md | 36 ++ .../src/Org.OpenAPITools/Api/DefaultApi.cs | 7 +- .../src/Org.OpenAPITools/Api/FakeApi.cs | 26 +- .../src/Org.OpenAPITools/Api/PetApi.cs | 367 +++++++++++++++++- .../net4.7/FormModels/api/openapi.yaml | 44 +++ .../net4.7/FormModels/docs/apis/PetApi.md | 36 ++ .../src/Org.OpenAPITools/Api/DefaultApi.cs | 7 +- .../src/Org.OpenAPITools/Api/FakeApi.cs | 26 +- .../src/Org.OpenAPITools/Api/PetApi.cs | 366 ++++++++++++++++- .../net4.7/Petstore/api/openapi.yaml | 44 +++ .../net4.7/Petstore/docs/apis/PetApi.md | 36 ++ .../src/Org.OpenAPITools/Api/DefaultApi.cs | 7 +- .../src/Org.OpenAPITools/Api/FakeApi.cs | 26 +- .../src/Org.OpenAPITools/Api/PetApi.cs | 366 ++++++++++++++++- .../net4.8/FormModels/api/openapi.yaml | 44 +++ .../net4.8/FormModels/docs/apis/PetApi.md | 36 ++ .../src/Org.OpenAPITools/Api/DefaultApi.cs | 7 +- .../src/Org.OpenAPITools/Api/FakeApi.cs | 26 +- .../src/Org.OpenAPITools/Api/PetApi.cs | 366 ++++++++++++++++- .../net4.8/Petstore/api/openapi.yaml | 44 +++ .../net4.8/Petstore/docs/apis/PetApi.md | 36 ++ .../src/Org.OpenAPITools/Api/DefaultApi.cs | 7 +- .../src/Org.OpenAPITools/Api/FakeApi.cs | 26 +- .../src/Org.OpenAPITools/Api/PetApi.cs | 366 ++++++++++++++++- .../net8/FormModels/api/openapi.yaml | 44 +++ .../net8/FormModels/docs/apis/PetApi.md | 36 ++ .../src/Org.OpenAPITools/Api/DefaultApi.cs | 7 +- .../src/Org.OpenAPITools/Api/FakeApi.cs | 26 +- .../src/Org.OpenAPITools/Api/PetApi.cs | 367 +++++++++++++++++- .../net8/NullReferenceTypes/api/openapi.yaml | 44 +++ .../NullReferenceTypes/docs/apis/PetApi.md | 36 ++ .../src/Org.OpenAPITools/Api/DefaultApi.cs | 7 +- .../src/Org.OpenAPITools/Api/FakeApi.cs | 26 +- .../src/Org.OpenAPITools/Api/PetApi.cs | 367 +++++++++++++++++- .../net8/Petstore/api/openapi.yaml | 44 +++ .../net8/Petstore/docs/apis/PetApi.md | 36 ++ .../src/Org.OpenAPITools/Api/DefaultApi.cs | 7 +- .../src/Org.OpenAPITools/Api/FakeApi.cs | 26 +- .../src/Org.OpenAPITools/Api/PetApi.cs | 367 +++++++++++++++++- .../net8/SourceGeneration/api/openapi.yaml | 44 +++ .../net8/SourceGeneration/docs/apis/PetApi.md | 36 ++ .../src/Org.OpenAPITools/Api/DefaultApi.cs | 7 +- .../src/Org.OpenAPITools/Api/FakeApi.cs | 26 +- .../src/Org.OpenAPITools/Api/PetApi.cs | 367 +++++++++++++++++- .../net9/FormModels/api/openapi.yaml | 44 +++ .../net9/FormModels/docs/apis/PetApi.md | 36 ++ .../src/Org.OpenAPITools/Api/DefaultApi.cs | 7 +- .../src/Org.OpenAPITools/Api/FakeApi.cs | 26 +- .../src/Org.OpenAPITools/Api/PetApi.cs | 367 +++++++++++++++++- .../net9/NullReferenceTypes/api/openapi.yaml | 44 +++ .../NullReferenceTypes/docs/apis/PetApi.md | 36 ++ .../src/Org.OpenAPITools/Api/DefaultApi.cs | 7 +- .../src/Org.OpenAPITools/Api/FakeApi.cs | 26 +- .../src/Org.OpenAPITools/Api/PetApi.cs | 367 +++++++++++++++++- .../net9/Petstore/api/openapi.yaml | 44 +++ .../net9/Petstore/docs/apis/PetApi.md | 36 ++ .../src/Org.OpenAPITools/Api/DefaultApi.cs | 7 +- .../src/Org.OpenAPITools/Api/FakeApi.cs | 26 +- .../src/Org.OpenAPITools/Api/PetApi.cs | 367 +++++++++++++++++- .../net9/SourceGeneration/api/openapi.yaml | 44 +++ .../net9/SourceGeneration/docs/apis/PetApi.md | 36 ++ .../src/Org.OpenAPITools/Api/DefaultApi.cs | 7 +- .../src/Org.OpenAPITools/Api/FakeApi.cs | 26 +- .../src/Org.OpenAPITools/Api/PetApi.cs | 367 +++++++++++++++++- .../standard2.0/Petstore/api/openapi.yaml | 44 +++ .../standard2.0/Petstore/docs/apis/PetApi.md | 36 ++ .../src/Org.OpenAPITools/Api/DefaultApi.cs | 7 +- .../src/Org.OpenAPITools/Api/FakeApi.cs | 26 +- .../src/Org.OpenAPITools/Api/PetApi.cs | 366 ++++++++++++++++- .../httpclient/net10/Petstore/README.md | 1 + .../net10/Petstore/api/openapi.yaml | 44 +++ .../httpclient/net10/Petstore/docs/PetApi.md | 99 +++++ .../src/Org.OpenAPITools/Api/PetApi.cs | 180 +++++++++ .../csharp/httpclient/net9/Petstore/README.md | 1 + .../httpclient/net9/Petstore/api/openapi.yaml | 44 +++ .../httpclient/net9/Petstore/docs/PetApi.md | 99 +++++ .../src/Org.OpenAPITools/Api/PetApi.cs | 180 +++++++++ .../httpclient/standard2.0/Petstore/README.md | 1 + .../standard2.0/Petstore/api/openapi.yaml | 44 +++ .../standard2.0/Petstore/docs/PetApi.md | 99 +++++ .../src/Org.OpenAPITools/Api/PetApi.cs | 180 +++++++++ .../csharp/restsharp/net8/Petstore/README.md | 1 + .../restsharp/net8/Petstore/api/openapi.yaml | 44 +++ .../restsharp/net8/Petstore/docs/PetApi.md | 95 +++++ .../src/Org.OpenAPITools/Api/PetApi.cs | 240 ++++++++++++ .../ConditionalSerialization/README.md | 1 + .../ConditionalSerialization/api/openapi.yaml | 44 +++ .../ConditionalSerialization/docs/PetApi.md | 95 +++++ .../src/Org.OpenAPITools/Api/PetApi.cs | 240 ++++++++++++ .../unityWebRequest/net10/Petstore/README.md | 1 + .../net10/Petstore/api/openapi.yaml | 44 +++ .../net10/Petstore/docs/PetApi.md | 95 +++++ .../src/Org.OpenAPITools/Api/PetApi.cs | 189 +++++++++ .../unityWebRequest/net9/Petstore/README.md | 1 + .../net9/Petstore/api/openapi.yaml | 44 +++ .../net9/Petstore/docs/PetApi.md | 95 +++++ .../src/Org.OpenAPITools/Api/PetApi.cs | 189 +++++++++ .../standard2.0/Petstore/README.md | 1 + .../standard2.0/Petstore/api/openapi.yaml | 44 +++ .../standard2.0/Petstore/docs/PetApi.md | 95 +++++ .../src/Org.OpenAPITools/Api/PetApi.cs | 189 +++++++++ 119 files changed, 10627 insertions(+), 328 deletions(-) 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..29153e6e9040 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 @@ -471,14 +471,15 @@ namespace {{packageName}}.{{apiPackage}} {{/headerParams}} {{#formParams}} {{#-first}} - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars));{{/-first}}{{^isFile}}{{#required}} - + {{/-first}} + {{^isFile}} + {{#required}} formParameterLocalVars.Add(new KeyValuePair("{{baseName}}", ClientUtils.ParameterToString({{paramName}}))); {{/required}} @@ -490,16 +491,46 @@ namespace {{packageName}}.{{apiPackage}} {{/isFile}} {{#isFile}} {{#required}} - multipartContentLocalVar.Add(new StreamContent({{paramName}})); + {{#isContainer}} + foreach (global::System.IO.Stream streamLocalVar in {{paramName}}) + { + var streamContentLocalVar = new StreamContent(streamLocalVar); + multipartContentLocalVar.Add(streamContentLocalVar, "{{baseName}}"); + } + + {{/isContainer}} + {{^isContainer}} + var streamContentLocalVar = new StreamContent({{paramName}}); + multipartContentLocalVar.Add(streamContentLocalVar, "{{baseName}}"); + {{/isContainer}} {{/required}} {{^required}} if ({{paramName}}.IsSet) - multipartContentLocalVar.Add(new StreamContent({{paramName}}.Value)); + { + {{#isContainer}} + foreach (global::System.IO.Stream streamLocalVar in {{paramName}}.Value) + { + var streamContentLocalVar = new StreamContent(streamLocalVar); + multipartContentLocalVar.Add(streamContentLocalVar, "{{baseName}}"); + } + {{/isContainer}} + {{^isContainer}} + var streamContentLocalVar = new StreamContent({{paramName}}.Value); + multipartContentLocalVar.Add(streamContentLocalVar, "{{baseName}}"); + {{/isContainer}} + } {{/required}} {{/isFile}} {{/formParams}} + {{#formParams}} + {{#-first}} + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + + {{/-first}} + {{/formParams}} {{#bodyParam}} {{#required}} httpRequestMessageLocalVar.Content = ({{paramName}}{{^required}}.Value{{/required}} as object) is System.IO.Stream stream 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/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/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Api/DefaultApi.cs index 3c26a27185e6..66211422bf81 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,16 +764,17 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..bb4069b491a3 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 @@ -4281,14 +4281,12 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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 +4296,10 @@ public async Task TestEndpointParametersAsyn formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.Value)); + { + var streamContentLocalVar = new StreamContent(binary.Value); + multipartContentLocalVar.Add(streamContentLocalVar, "binary"); + } if (callback.IsSet) formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); @@ -4327,6 +4328,9 @@ public async Task TestEndpointParametersAsyn if (varString.IsSet) formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4625,18 +4629,21 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { @@ -5534,18 +5541,19 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..34ddd104a52e 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 @@ -257,6 +257,31 @@ public interface IPetApi : IApi /// Cancellation Token to cancel the request. /// <> Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream 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,21 @@ 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(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2579,17 +2639,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); + multipartContentLocalVar.Add(streamContentLocalVar, "file"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2869,17 +2935,21 @@ 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); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile"); if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -3038,5 +3108,288 @@ 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 (global::System.IO.Stream streamLocalVar in files) + { + var streamContentLocalVar = new StreamContent(streamLocalVar); + multipartContentLocalVar.Add(streamContentLocalVar, "files"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + + 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 contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); + + if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) + httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); + + 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/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/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/src/Org.OpenAPITools/Api/DefaultApi.cs index 2391c7e1ee03..629302a4d2da 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,16 +766,17 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..fdd57d8cb1df 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 @@ -4283,14 +4283,12 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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))); @@ -4300,7 +4298,10 @@ public async Task TestEndpointParametersAsyn formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.Value)); + { + var streamContentLocalVar = new StreamContent(binary.Value); + multipartContentLocalVar.Add(streamContentLocalVar, "binary"); + } if (callback.IsSet) formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); @@ -4329,6 +4330,9 @@ public async Task TestEndpointParametersAsyn if (varString.IsSet) formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4639,18 +4643,21 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { @@ -5548,18 +5555,19 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..6cc527fa0dc1 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 @@ -259,6 +259,31 @@ public interface IPetApi : IApi /// Cancellation Token to cancel the request. /// <?> Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream 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,18 +2389,21 @@ 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(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2581,17 +2641,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); + multipartContentLocalVar.Add(streamContentLocalVar, "file"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2871,17 +2937,21 @@ 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); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile"); if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -3040,5 +3110,288 @@ 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 (global::System.IO.Stream streamLocalVar in files) + { + var streamContentLocalVar = new StreamContent(streamLocalVar); + multipartContentLocalVar.Add(streamContentLocalVar, "files"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + + 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? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); + + if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) + httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); + + 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/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/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net10/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs index 3c26a27185e6..66211422bf81 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,16 +764,17 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..aa95f6cb4b32 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 @@ -4281,14 +4281,12 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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 +4296,10 @@ public async Task TestEndpointParametersAsyn formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.Value)); + { + var streamContentLocalVar = new StreamContent(binary.Value); + multipartContentLocalVar.Add(streamContentLocalVar, "binary"); + } if (callback.IsSet) formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); @@ -4327,6 +4328,9 @@ public async Task TestEndpointParametersAsyn if (varString.IsSet) formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4637,18 +4641,21 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { @@ -5546,18 +5553,19 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..79a8214463d3 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 @@ -257,6 +257,31 @@ public interface IPetApi : IApi /// Cancellation Token to cancel the request. /// <> Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream 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,21 @@ 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(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2579,17 +2639,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); + multipartContentLocalVar.Add(streamContentLocalVar, "file"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2869,17 +2935,21 @@ 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); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile"); if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -3038,5 +3108,288 @@ 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 (global::System.IO.Stream streamLocalVar in files) + { + var streamContentLocalVar = new StreamContent(streamLocalVar); + multipartContentLocalVar.Add(streamContentLocalVar, "files"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + + 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 contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); + + if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) + httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); + + 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/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/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net10/SourceGeneration/src/Org.OpenAPITools/Api/DefaultApi.cs index 2391c7e1ee03..629302a4d2da 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,16 +766,17 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..fdd57d8cb1df 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 @@ -4283,14 +4283,12 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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))); @@ -4300,7 +4298,10 @@ public async Task TestEndpointParametersAsyn formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.Value)); + { + var streamContentLocalVar = new StreamContent(binary.Value); + multipartContentLocalVar.Add(streamContentLocalVar, "binary"); + } if (callback.IsSet) formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); @@ -4329,6 +4330,9 @@ public async Task TestEndpointParametersAsyn if (varString.IsSet) formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4639,18 +4643,21 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { @@ -5548,18 +5555,19 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..6cc527fa0dc1 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 @@ -259,6 +259,31 @@ public interface IPetApi : IApi /// Cancellation Token to cancel the request. /// <?> Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream 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,18 +2389,21 @@ 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(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2581,17 +2641,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); + multipartContentLocalVar.Add(streamContentLocalVar, "file"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2871,17 +2937,21 @@ 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); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile"); if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -3040,5 +3110,288 @@ 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 (global::System.IO.Stream streamLocalVar in files) + { + var streamContentLocalVar = new StreamContent(streamLocalVar); + multipartContentLocalVar.Add(streamContentLocalVar, "files"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + + 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? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); + + if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) + httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); + + 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/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/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Api/DefaultApi.cs index 1bbf43279f7c..942454324c21 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,16 +763,17 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..023e16226228 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 @@ -4272,14 +4272,12 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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 +4287,10 @@ public async Task TestEndpointParametersAsyn formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.Value)); + { + var streamContentLocalVar = new StreamContent(binary.Value); + multipartContentLocalVar.Add(streamContentLocalVar, "binary"); + } if (callback.IsSet) formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); @@ -4318,6 +4319,9 @@ public async Task TestEndpointParametersAsyn if (varString.IsSet) formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4616,18 +4620,21 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { @@ -5524,18 +5531,19 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..bae78e0a8e62 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 @@ -257,6 +257,31 @@ public interface IPetApi : IApi /// Cancellation Token to cancel the request. /// <> Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream 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,21 @@ 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(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2575,17 +2635,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); + multipartContentLocalVar.Add(streamContentLocalVar, "file"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2864,17 +2930,21 @@ 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); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile"); if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -3032,5 +3102,287 @@ 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 (global::System.IO.Stream streamLocalVar in files) + { + var streamContentLocalVar = new StreamContent(streamLocalVar); + multipartContentLocalVar.Add(streamContentLocalVar, "files"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + + 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 contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); + + if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) + httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); + + 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/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/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs index 1bbf43279f7c..942454324c21 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,16 +763,17 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..b85cf1d91ef4 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 @@ -4272,14 +4272,12 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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 +4287,10 @@ public async Task TestEndpointParametersAsyn formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.Value)); + { + var streamContentLocalVar = new StreamContent(binary.Value); + multipartContentLocalVar.Add(streamContentLocalVar, "binary"); + } if (callback.IsSet) formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); @@ -4318,6 +4319,9 @@ public async Task TestEndpointParametersAsyn if (varString.IsSet) formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4628,18 +4632,21 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { @@ -5536,18 +5543,19 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..95cd8163eca3 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 @@ -257,6 +257,31 @@ public interface IPetApi : IApi /// Cancellation Token to cancel the request. /// <> Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream 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,21 @@ 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(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2575,17 +2635,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); + multipartContentLocalVar.Add(streamContentLocalVar, "file"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2864,17 +2930,21 @@ 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); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile"); if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -3032,5 +3102,287 @@ 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 (global::System.IO.Stream streamLocalVar in files) + { + var streamContentLocalVar = new StreamContent(streamLocalVar); + multipartContentLocalVar.Add(streamContentLocalVar, "files"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + + 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 contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); + + if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) + httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); + + 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/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/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Api/DefaultApi.cs index 1bbf43279f7c..942454324c21 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,16 +763,17 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..023e16226228 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 @@ -4272,14 +4272,12 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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 +4287,10 @@ public async Task TestEndpointParametersAsyn formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.Value)); + { + var streamContentLocalVar = new StreamContent(binary.Value); + multipartContentLocalVar.Add(streamContentLocalVar, "binary"); + } if (callback.IsSet) formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); @@ -4318,6 +4319,9 @@ public async Task TestEndpointParametersAsyn if (varString.IsSet) formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4616,18 +4620,21 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { @@ -5524,18 +5531,19 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..bae78e0a8e62 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 @@ -257,6 +257,31 @@ public interface IPetApi : IApi /// Cancellation Token to cancel the request. /// <> Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream 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,21 @@ 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(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2575,17 +2635,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); + multipartContentLocalVar.Add(streamContentLocalVar, "file"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2864,17 +2930,21 @@ 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); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile"); if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -3032,5 +3102,287 @@ 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 (global::System.IO.Stream streamLocalVar in files) + { + var streamContentLocalVar = new StreamContent(streamLocalVar); + multipartContentLocalVar.Add(streamContentLocalVar, "files"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + + 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 contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); + + if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) + httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); + + 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/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/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs index 1bbf43279f7c..942454324c21 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,16 +763,17 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..b85cf1d91ef4 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 @@ -4272,14 +4272,12 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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 +4287,10 @@ public async Task TestEndpointParametersAsyn formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.Value)); + { + var streamContentLocalVar = new StreamContent(binary.Value); + multipartContentLocalVar.Add(streamContentLocalVar, "binary"); + } if (callback.IsSet) formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); @@ -4318,6 +4319,9 @@ public async Task TestEndpointParametersAsyn if (varString.IsSet) formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4628,18 +4632,21 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { @@ -5536,18 +5543,19 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..95cd8163eca3 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 @@ -257,6 +257,31 @@ public interface IPetApi : IApi /// Cancellation Token to cancel the request. /// <> Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream 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,21 @@ 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(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2575,17 +2635,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); + multipartContentLocalVar.Add(streamContentLocalVar, "file"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2864,17 +2930,21 @@ 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); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile"); if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -3032,5 +3102,287 @@ 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 (global::System.IO.Stream streamLocalVar in files) + { + var streamContentLocalVar = new StreamContent(streamLocalVar); + multipartContentLocalVar.Add(streamContentLocalVar, "files"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + + 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 contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); + + if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) + httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); + + 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/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/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Api/DefaultApi.cs index 3c26a27185e6..66211422bf81 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,16 +764,17 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..bb4069b491a3 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 @@ -4281,14 +4281,12 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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 +4296,10 @@ public async Task TestEndpointParametersAsyn formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.Value)); + { + var streamContentLocalVar = new StreamContent(binary.Value); + multipartContentLocalVar.Add(streamContentLocalVar, "binary"); + } if (callback.IsSet) formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); @@ -4327,6 +4328,9 @@ public async Task TestEndpointParametersAsyn if (varString.IsSet) formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4625,18 +4629,21 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { @@ -5534,18 +5541,19 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..34ddd104a52e 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 @@ -257,6 +257,31 @@ public interface IPetApi : IApi /// Cancellation Token to cancel the request. /// <> Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream 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,21 @@ 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(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2579,17 +2639,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); + multipartContentLocalVar.Add(streamContentLocalVar, "file"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2869,17 +2935,21 @@ 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); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile"); if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -3038,5 +3108,288 @@ 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 (global::System.IO.Stream streamLocalVar in files) + { + var streamContentLocalVar = new StreamContent(streamLocalVar); + multipartContentLocalVar.Add(streamContentLocalVar, "files"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + + 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 contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); + + if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) + httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); + + 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/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/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools/Api/DefaultApi.cs index 2391c7e1ee03..629302a4d2da 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,16 +766,17 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..fdd57d8cb1df 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 @@ -4283,14 +4283,12 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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))); @@ -4300,7 +4298,10 @@ public async Task TestEndpointParametersAsyn formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.Value)); + { + var streamContentLocalVar = new StreamContent(binary.Value); + multipartContentLocalVar.Add(streamContentLocalVar, "binary"); + } if (callback.IsSet) formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); @@ -4329,6 +4330,9 @@ public async Task TestEndpointParametersAsyn if (varString.IsSet) formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4639,18 +4643,21 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { @@ -5548,18 +5555,19 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..6cc527fa0dc1 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 @@ -259,6 +259,31 @@ public interface IPetApi : IApi /// Cancellation Token to cancel the request. /// <?> Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream 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,18 +2389,21 @@ 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(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2581,17 +2641,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); + multipartContentLocalVar.Add(streamContentLocalVar, "file"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2871,17 +2937,21 @@ 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); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile"); if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -3040,5 +3110,288 @@ 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 (global::System.IO.Stream streamLocalVar in files) + { + var streamContentLocalVar = new StreamContent(streamLocalVar); + multipartContentLocalVar.Add(streamContentLocalVar, "files"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + + 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? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); + + if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) + httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); + + 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/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/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs index 3c26a27185e6..66211422bf81 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,16 +764,17 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..aa95f6cb4b32 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 @@ -4281,14 +4281,12 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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 +4296,10 @@ public async Task TestEndpointParametersAsyn formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.Value)); + { + var streamContentLocalVar = new StreamContent(binary.Value); + multipartContentLocalVar.Add(streamContentLocalVar, "binary"); + } if (callback.IsSet) formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); @@ -4327,6 +4328,9 @@ public async Task TestEndpointParametersAsyn if (varString.IsSet) formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4637,18 +4641,21 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { @@ -5546,18 +5553,19 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..79a8214463d3 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 @@ -257,6 +257,31 @@ public interface IPetApi : IApi /// Cancellation Token to cancel the request. /// <> Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream 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,21 @@ 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(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2579,17 +2639,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); + multipartContentLocalVar.Add(streamContentLocalVar, "file"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2869,17 +2935,21 @@ 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); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile"); if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -3038,5 +3108,288 @@ 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 (global::System.IO.Stream streamLocalVar in files) + { + var streamContentLocalVar = new StreamContent(streamLocalVar); + multipartContentLocalVar.Add(streamContentLocalVar, "files"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + + 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 contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); + + if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) + httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); + + 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/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/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools/Api/DefaultApi.cs index 2391c7e1ee03..629302a4d2da 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,16 +766,17 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..fdd57d8cb1df 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 @@ -4283,14 +4283,12 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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))); @@ -4300,7 +4298,10 @@ public async Task TestEndpointParametersAsyn formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.Value)); + { + var streamContentLocalVar = new StreamContent(binary.Value); + multipartContentLocalVar.Add(streamContentLocalVar, "binary"); + } if (callback.IsSet) formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); @@ -4329,6 +4330,9 @@ public async Task TestEndpointParametersAsyn if (varString.IsSet) formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4639,18 +4643,21 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { @@ -5548,18 +5555,19 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..6cc527fa0dc1 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 @@ -259,6 +259,31 @@ public interface IPetApi : IApi /// Cancellation Token to cancel the request. /// <?> Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream 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,18 +2389,21 @@ 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(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2581,17 +2641,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); + multipartContentLocalVar.Add(streamContentLocalVar, "file"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2871,17 +2937,21 @@ 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); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile"); if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -3040,5 +3110,288 @@ 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 (global::System.IO.Stream streamLocalVar in files) + { + var streamContentLocalVar = new StreamContent(streamLocalVar); + multipartContentLocalVar.Add(streamContentLocalVar, "files"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + + 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? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); + + if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) + httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); + + 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/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/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Api/DefaultApi.cs index 3c26a27185e6..66211422bf81 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,16 +764,17 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..bb4069b491a3 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 @@ -4281,14 +4281,12 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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 +4296,10 @@ public async Task TestEndpointParametersAsyn formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.Value)); + { + var streamContentLocalVar = new StreamContent(binary.Value); + multipartContentLocalVar.Add(streamContentLocalVar, "binary"); + } if (callback.IsSet) formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); @@ -4327,6 +4328,9 @@ public async Task TestEndpointParametersAsyn if (varString.IsSet) formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4625,18 +4629,21 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { @@ -5534,18 +5541,19 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..34ddd104a52e 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 @@ -257,6 +257,31 @@ public interface IPetApi : IApi /// Cancellation Token to cancel the request. /// <> Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream 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,21 @@ 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(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2579,17 +2639,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); + multipartContentLocalVar.Add(streamContentLocalVar, "file"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2869,17 +2935,21 @@ 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); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile"); if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -3038,5 +3108,288 @@ 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 (global::System.IO.Stream streamLocalVar in files) + { + var streamContentLocalVar = new StreamContent(streamLocalVar); + multipartContentLocalVar.Add(streamContentLocalVar, "files"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + + 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 contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); + + if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) + httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); + + 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/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/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Api/DefaultApi.cs index 2391c7e1ee03..629302a4d2da 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,16 +766,17 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..fdd57d8cb1df 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 @@ -4283,14 +4283,12 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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))); @@ -4300,7 +4298,10 @@ public async Task TestEndpointParametersAsyn formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.Value)); + { + var streamContentLocalVar = new StreamContent(binary.Value); + multipartContentLocalVar.Add(streamContentLocalVar, "binary"); + } if (callback.IsSet) formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); @@ -4329,6 +4330,9 @@ public async Task TestEndpointParametersAsyn if (varString.IsSet) formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4639,18 +4643,21 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { @@ -5548,18 +5555,19 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..6cc527fa0dc1 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 @@ -259,6 +259,31 @@ public interface IPetApi : IApi /// Cancellation Token to cancel the request. /// <?> Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream 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,18 +2389,21 @@ 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(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2581,17 +2641,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); + multipartContentLocalVar.Add(streamContentLocalVar, "file"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2871,17 +2937,21 @@ 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); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile"); if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -3040,5 +3110,288 @@ 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 (global::System.IO.Stream streamLocalVar in files) + { + var streamContentLocalVar = new StreamContent(streamLocalVar); + multipartContentLocalVar.Add(streamContentLocalVar, "files"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + + 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? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); + + if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) + httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); + + 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/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/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs index 3c26a27185e6..66211422bf81 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,16 +764,17 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..aa95f6cb4b32 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 @@ -4281,14 +4281,12 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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 +4296,10 @@ public async Task TestEndpointParametersAsyn formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.Value)); + { + var streamContentLocalVar = new StreamContent(binary.Value); + multipartContentLocalVar.Add(streamContentLocalVar, "binary"); + } if (callback.IsSet) formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); @@ -4327,6 +4328,9 @@ public async Task TestEndpointParametersAsyn if (varString.IsSet) formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4637,18 +4641,21 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { @@ -5546,18 +5553,19 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..79a8214463d3 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 @@ -257,6 +257,31 @@ public interface IPetApi : IApi /// Cancellation Token to cancel the request. /// <> Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream 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,21 @@ 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(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2579,17 +2639,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); + multipartContentLocalVar.Add(streamContentLocalVar, "file"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2869,17 +2935,21 @@ 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); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile"); if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -3038,5 +3108,288 @@ 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 (global::System.IO.Stream streamLocalVar in files) + { + var streamContentLocalVar = new StreamContent(streamLocalVar); + multipartContentLocalVar.Add(streamContentLocalVar, "files"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + + 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 contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); + + if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) + httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); + + 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/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/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Api/DefaultApi.cs index 2391c7e1ee03..629302a4d2da 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,16 +766,17 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..fdd57d8cb1df 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 @@ -4283,14 +4283,12 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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))); @@ -4300,7 +4298,10 @@ public async Task TestEndpointParametersAsyn formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.Value)); + { + var streamContentLocalVar = new StreamContent(binary.Value); + multipartContentLocalVar.Add(streamContentLocalVar, "binary"); + } if (callback.IsSet) formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); @@ -4329,6 +4330,9 @@ public async Task TestEndpointParametersAsyn if (varString.IsSet) formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4639,18 +4643,21 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { @@ -5548,18 +5555,19 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..6cc527fa0dc1 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 @@ -259,6 +259,31 @@ public interface IPetApi : IApi /// Cancellation Token to cancel the request. /// <?> Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream 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,18 +2389,21 @@ 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(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2581,17 +2641,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); + multipartContentLocalVar.Add(streamContentLocalVar, "file"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2871,17 +2937,21 @@ 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); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile"); if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -3040,5 +3110,288 @@ 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 (global::System.IO.Stream streamLocalVar in files) + { + var streamContentLocalVar = new StreamContent(streamLocalVar); + multipartContentLocalVar.Add(streamContentLocalVar, "files"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + + 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? contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); + + if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) + httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); + + 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/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/Api/DefaultApi.cs b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs index 8f794c9ca7c8..0e0e7300d209 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,16 +762,17 @@ public async Task GetCountryAsync(string country, System ? "/country" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/country"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); httpRequestMessageLocalVar.Content = multipartContentLocalVar; List> formParameterLocalVars = new List>(); - multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); - formParameterLocalVars.Add(new KeyValuePair("country", ClientUtils.ParameterToString(country))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..857caf21eb9b 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 @@ -4271,14 +4271,12 @@ public async Task TestEndpointParametersAsyn ? "/fake" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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 +4286,10 @@ public async Task TestEndpointParametersAsyn formParameterLocalVars.Add(new KeyValuePair("double", ClientUtils.ParameterToString(varDouble))); if (binary.IsSet) - multipartContentLocalVar.Add(new StreamContent(binary.Value)); + { + var streamContentLocalVar = new StreamContent(binary.Value); + multipartContentLocalVar.Add(streamContentLocalVar, "binary"); + } if (callback.IsSet) formParameterLocalVars.Add(new KeyValuePair("callback", ClientUtils.ParameterToString(callback.Value))); @@ -4317,6 +4318,9 @@ public async Task TestEndpointParametersAsyn if (varString.IsSet) formParameterLocalVars.Add(new KeyValuePair("string", ClientUtils.ParameterToString(varString.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -4627,18 +4631,21 @@ public async Task TestEnumParametersAsync(Option if (enumHeaderStringArray.IsSet) httpRequestMessageLocalVar.Headers.Add("enum_header_string_array", ClientUtils.ParameterToString(enumHeaderStringArray.Value)); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { @@ -5535,18 +5542,19 @@ public async Task TestJsonFormDataAsync(string par ? "/fake/jsonFormData" : string.Concat(HttpClient.BaseAddress.AbsolutePath, "/fake/jsonFormData"); - MultipartContent multipartContentLocalVar = new MultipartContent(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; string[] contentTypes = new string[] { 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..5f56473ddd75 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 @@ -256,6 +256,31 @@ public interface IPetApi : IApi /// Cancellation Token to cancel the request. /// <> Task UploadFileWithRequiredFileOrDefaultAsync(long petId, System.IO.Stream 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,21 @@ 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(); + MultipartFormDataContent multipartContentLocalVar = new MultipartFormDataContent(); 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) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2574,17 +2634,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); + multipartContentLocalVar.Add(streamContentLocalVar, "file"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -2863,17 +2929,21 @@ 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); + multipartContentLocalVar.Add(streamContentLocalVar, "requiredFile"); if (additionalMetadata.IsSet) formParameterLocalVars.Add(new KeyValuePair("additionalMetadata", ClientUtils.ParameterToString(additionalMetadata.Value))); + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + List tokenBaseLocalVars = new List(); httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri; @@ -3031,5 +3101,287 @@ 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 (global::System.IO.Stream streamLocalVar in files) + { + var streamContentLocalVar = new StreamContent(streamLocalVar); + multipartContentLocalVar.Add(streamContentLocalVar, "files"); + } + + if (formParameterLocalVars.Count > 0) + multipartContentLocalVar.Add(new FormUrlEncodedContent(formParameterLocalVars)); + + 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 contentTypeLocalVar = ClientUtils.SelectHeaderContentType(contentTypes); + + if (contentTypeLocalVar != null && httpRequestMessageLocalVar.Content != null) + httpRequestMessageLocalVar.Content.Headers.ContentType = new MediaTypeHeaderValue(contentTypeLocalVar); + + 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/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; + } + } } From ff5bd0bd6226539f2be47775223f8671012f9732 Mon Sep 17 00:00:00 2001 From: devhl Date: Sun, 25 Jan 2026 17:42:07 -0500 Subject: [PATCH 2/2] build tests --- .../src/Org.OpenAPITools.Test/Api/PetApiTests.cs | 13 +++++++++++++ .../src/Org.OpenAPITools.Test/Api/PetApiTests.cs | 13 +++++++++++++ .../src/Org.OpenAPITools.Test/Api/PetApiTests.cs | 13 +++++++++++++ .../src/Org.OpenAPITools.Test/Api/PetApiTests.cs | 13 +++++++++++++ .../src/Org.OpenAPITools.Test/Api/PetApiTests.cs | 13 +++++++++++++ .../src/Org.OpenAPITools.Test/Api/PetApiTests.cs | 13 +++++++++++++ .../src/Org.OpenAPITools.Test/Api/PetApiTests.cs | 13 +++++++++++++ .../src/Org.OpenAPITools.Test/Api/PetApiTests.cs | 13 +++++++++++++ .../src/Org.OpenAPITools.Test/Api/PetApiTests.cs | 13 +++++++++++++ .../src/Org.OpenAPITools.Test/Api/PetApiTests.cs | 13 +++++++++++++ .../src/Org.OpenAPITools.Test/Api/PetApiTests.cs | 13 +++++++++++++ .../src/Org.OpenAPITools.Test/Api/PetApiTests.cs | 13 +++++++++++++ .../src/Org.OpenAPITools.Test/Api/PetApiTests.cs | 13 +++++++++++++ .../src/Org.OpenAPITools.Test/Api/PetApiTests.cs | 13 +++++++++++++ .../src/Org.OpenAPITools.Test/Api/PetApiTests.cs | 13 +++++++++++++ .../src/Org.OpenAPITools.Test/Api/PetApiTests.cs | 13 +++++++++++++ .../src/Org.OpenAPITools.Test/Api/PetApiTests.cs | 13 +++++++++++++ 17 files changed, 221 insertions(+) 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..5ce22922ba57 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 @@ -156,5 +156,18 @@ public async Task UploadFileWithRequiredFileAsyncTest() 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.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/net10/NullReferenceTypes/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 49e7b21b53c2..a275bfac9b85 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 @@ -156,5 +156,18 @@ public async Task UploadFileWithRequiredFileAsyncTest() 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.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/net10/Petstore/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 215e88093797..c9b30a54e4d7 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 @@ -156,5 +156,18 @@ public async Task UploadFileWithRequiredFileAsyncTest() 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.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/net10/SourceGeneration/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 49e7b21b53c2..a275bfac9b85 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 @@ -156,5 +156,18 @@ public async Task UploadFileWithRequiredFileAsyncTest() 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.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 1f1d7f6c4576..5ce22922ba57 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 @@ -156,5 +156,18 @@ public async Task UploadFileWithRequiredFileAsyncTest() 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.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 215e88093797..c9b30a54e4d7 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 @@ -156,5 +156,18 @@ public async Task UploadFileWithRequiredFileAsyncTest() 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.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 1f1d7f6c4576..5ce22922ba57 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 @@ -156,5 +156,18 @@ public async Task UploadFileWithRequiredFileAsyncTest() 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.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 215e88093797..c9b30a54e4d7 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 @@ -156,5 +156,18 @@ public async Task UploadFileWithRequiredFileAsyncTest() 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.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 1f1d7f6c4576..5ce22922ba57 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 @@ -156,5 +156,18 @@ public async Task UploadFileWithRequiredFileAsyncTest() 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.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/net8/NullReferenceTypes/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 49e7b21b53c2..a275bfac9b85 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 @@ -156,5 +156,18 @@ public async Task UploadFileWithRequiredFileAsyncTest() 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.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 215e88093797..c9b30a54e4d7 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 @@ -156,5 +156,18 @@ public async Task UploadFileWithRequiredFileAsyncTest() 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.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/net8/SourceGeneration/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 49e7b21b53c2..a275bfac9b85 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 @@ -156,5 +156,18 @@ public async Task UploadFileWithRequiredFileAsyncTest() 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.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 1f1d7f6c4576..5ce22922ba57 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 @@ -156,5 +156,18 @@ public async Task UploadFileWithRequiredFileAsyncTest() 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.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 49e7b21b53c2..a275bfac9b85 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 @@ -156,5 +156,18 @@ public async Task UploadFileWithRequiredFileAsyncTest() 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.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/net9/Petstore/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 215e88093797..c9b30a54e4d7 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 @@ -156,5 +156,18 @@ public async Task UploadFileWithRequiredFileAsyncTest() 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.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 49e7b21b53c2..a275bfac9b85 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 @@ -156,5 +156,18 @@ public async Task UploadFileWithRequiredFileAsyncTest() 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.Test/Api/PetApiTests.cs b/samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools.Test/Api/PetApiTests.cs index 215e88093797..c9b30a54e4d7 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 @@ -156,5 +156,18 @@ public async Task UploadFileWithRequiredFileAsyncTest() 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); + } } }