[Java][Native] Fix multipart builder files array (#16055) (#16094)

* [Java] Fixed bug in native client generation when API accepts array of files (#16055)

* Adding test for java native client

* Updated samples
This commit is contained in:
Luca
2023-07-24 09:57:21 +02:00
committed by GitHub
parent 0a02860b50
commit 584f8448ee
20 changed files with 1028 additions and 1 deletions

View File

@@ -445,7 +445,13 @@ public class {{classname}} {
{{#formParams}}
{{#isArray}}
for (int i=0; i < {{paramName}}.size(); i++) {
{{#isFile}}
multiPartBuilder.addBinaryBody("{{{baseName}}}", {{paramName}}.get(i));
hasFiles = true;
{{/isFile}}
{{^isFile}}
multiPartBuilder.addTextBody("{{{baseName}}}", {{paramName}}.get(i).toString());
{{/isFile}}
}
{{/isArray}}
{{^isArray}}

View File

@@ -423,6 +423,34 @@ paths:
schema:
type: string
format: binary
# Array of binary in multipart mime tests
/body/application/octetstream/array_of_binary:
post:
tags:
- body
summary: Test array of binary in multipart mime
description: Test array of binary in multipart mime
operationId: test/body/multipart/formdata/array_of_binary
requestBody:
content:
multipart/form-data:
schema:
required:
- files
type: object
properties:
files:
type: array
items:
type: string
format: binary
responses:
'200':
description: Successful operation
content:
text/plain:
schema:
type: string
components:
requestBodies:

View File

@@ -107,6 +107,7 @@ Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*BodyApi* | [**testBinaryGif**](docs/BodyApi.md#testBinaryGif) | **POST** /binary/gif | Test binary (gif) response body
*BodyApi* | [**testBodyApplicationOctetstreamBinary**](docs/BodyApi.md#testBodyApplicationOctetstreamBinary) | **POST** /body/application/octetstream/binary | Test body parameter(s)
*BodyApi* | [**testBodyMultipartFormdataArrayOfBinary**](docs/BodyApi.md#testBodyMultipartFormdataArrayOfBinary) | **POST** /body/application/octetstream/array_of_binary | Test array of binary in multipart mime
*BodyApi* | [**testEchoBodyFreeFormObjectResponseString**](docs/BodyApi.md#testEchoBodyFreeFormObjectResponseString) | **POST** /echo/body/FreeFormObject/response_string | Test free form object
*BodyApi* | [**testEchoBodyPet**](docs/BodyApi.md#testEchoBodyPet) | **POST** /echo/body/Pet | Test body parameter(s)
*BodyApi* | [**testEchoBodyPetResponseString**](docs/BodyApi.md#testEchoBodyPetResponseString) | **POST** /echo/body/Pet/response_string | Test empty response body

View File

@@ -427,6 +427,27 @@ paths:
tags:
- body
x-accepts: image/gif
/body/application/octetstream/array_of_binary:
post:
description: Test array of binary in multipart mime
operationId: test/body/multipart/formdata/array_of_binary
requestBody:
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/test_body_multipart_formdata_array_of_binary_request'
responses:
"200":
content:
text/plain:
schema:
type: string
description: Successful operation
summary: Test array of binary in multipart mime
tags:
- body
x-content-type: multipart/form-data
x-accepts: text/plain
components:
requestBodies:
Pet:
@@ -657,4 +678,14 @@ components:
allOf:
- $ref: '#/components/schemas/Bird'
- $ref: '#/components/schemas/Category'
test_body_multipart_formdata_array_of_binary_request:
properties:
files:
items:
format: binary
type: string
type: array
required:
- files
type: object

View File

@@ -6,6 +6,7 @@ All URIs are relative to *http://localhost:3000*
|------------- | ------------- | -------------|
| [**testBinaryGif**](BodyApi.md#testBinaryGif) | **POST** /binary/gif | Test binary (gif) response body |
| [**testBodyApplicationOctetstreamBinary**](BodyApi.md#testBodyApplicationOctetstreamBinary) | **POST** /body/application/octetstream/binary | Test body parameter(s) |
| [**testBodyMultipartFormdataArrayOfBinary**](BodyApi.md#testBodyMultipartFormdataArrayOfBinary) | **POST** /body/application/octetstream/array_of_binary | Test array of binary in multipart mime |
| [**testEchoBodyFreeFormObjectResponseString**](BodyApi.md#testEchoBodyFreeFormObjectResponseString) | **POST** /echo/body/FreeFormObject/response_string | Test free form object |
| [**testEchoBodyPet**](BodyApi.md#testEchoBodyPet) | **POST** /echo/body/Pet | Test body parameter(s) |
| [**testEchoBodyPetResponseString**](BodyApi.md#testEchoBodyPetResponseString) | **POST** /echo/body/Pet/response_string | Test empty response body |
@@ -141,6 +142,72 @@ No authorization required
| **200** | Successful operation | - |
## testBodyMultipartFormdataArrayOfBinary
> String testBodyMultipartFormdataArrayOfBinary(files)
Test array of binary in multipart mime
Test array of binary in multipart mime
### Example
```java
// Import classes:
import org.openapitools.client.ApiClient;
import org.openapitools.client.ApiException;
import org.openapitools.client.Configuration;
import org.openapitools.client.models.*;
import org.openapitools.client.api.BodyApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("http://localhost:3000");
BodyApi apiInstance = new BodyApi(defaultClient);
List<File> files = Arrays.asList(); // List<File> |
try {
String result = apiInstance.testBodyMultipartFormdataArrayOfBinary(files);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling BodyApi#testBodyMultipartFormdataArrayOfBinary");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
```
### Parameters
| Name | Type | Description | Notes |
|------------- | ------------- | ------------- | -------------|
| **files** | **List&lt;File&gt;**| | |
### Return type
**String**
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: multipart/form-data
- **Accept**: text/plain
### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | Successful operation | - |
## testEchoBodyFreeFormObjectResponseString
> String testEchoBodyFreeFormObjectResponseString(body)

View File

@@ -189,6 +189,82 @@ public class BodyApi {
);
}
/**
* Test array of binary in multipart mime
* Test array of binary in multipart mime
* @param files (required)
* @return String
* @throws ApiException if fails to make API call
*/
public String testBodyMultipartFormdataArrayOfBinary(List<File> files) throws ApiException {
return this.testBodyMultipartFormdataArrayOfBinary(files, Collections.emptyMap());
}
/**
* Test array of binary in multipart mime
* Test array of binary in multipart mime
* @param files (required)
* @param additionalHeaders additionalHeaders for this call
* @return String
* @throws ApiException if fails to make API call
*/
public String testBodyMultipartFormdataArrayOfBinary(List<File> files, Map<String, String> additionalHeaders) throws ApiException {
Object localVarPostBody = null;
// verify the required parameter 'files' is set
if (files == null) {
throw new ApiException(400, "Missing the required parameter 'files' when calling testBodyMultipartFormdataArrayOfBinary");
}
// create path and map variables
String localVarPath = "/body/application/octetstream/array_of_binary";
StringJoiner localVarQueryStringJoiner = new StringJoiner("&");
String localVarQueryParameterBaseName;
List<Pair> localVarQueryParams = new ArrayList<Pair>();
List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
Map<String, String> localVarCookieParams = new HashMap<String, String>();
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
localVarHeaderParams.putAll(additionalHeaders);
if (files != null)
localVarFormParams.put("files", files);
final String[] localVarAccepts = {
"text/plain"
};
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
final String[] localVarContentTypes = {
"multipart/form-data"
};
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
String[] localVarAuthNames = new String[] { };
TypeReference<String> localVarReturnType = new TypeReference<String>() {};
return apiClient.invokeAPI(
localVarPath,
"POST",
localVarQueryParams,
localVarCollectionQueryParams,
localVarQueryStringJoiner.toString(),
localVarPostBody,
localVarHeaderParams,
localVarCookieParams,
localVarFormParams,
localVarAccept,
localVarContentType,
localVarAuthNames,
localVarReturnType
);
}
/**
* Test free form object
* Test free form object

View File

@@ -427,6 +427,27 @@ paths:
tags:
- body
x-accepts: image/gif
/body/application/octetstream/array_of_binary:
post:
description: Test array of binary in multipart mime
operationId: test/body/multipart/formdata/array_of_binary
requestBody:
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/test_body_multipart_formdata_array_of_binary_request'
responses:
"200":
content:
text/plain:
schema:
type: string
description: Successful operation
summary: Test array of binary in multipart mime
tags:
- body
x-content-type: multipart/form-data
x-accepts: text/plain
components:
requestBodies:
Pet:
@@ -657,4 +678,14 @@ components:
allOf:
- $ref: '#/components/schemas/Bird'
- $ref: '#/components/schemas/Category'
test_body_multipart_formdata_array_of_binary_request:
properties:
files:
items:
format: binary
type: string
type: array
required:
- files
type: object

View File

@@ -72,6 +72,35 @@ public interface BodyApi extends ApiClient.Api {
/**
* Test array of binary in multipart mime
* Test array of binary in multipart mime
* @param files (required)
* @return String
*/
@RequestLine("POST /body/application/octetstream/array_of_binary")
@Headers({
"Content-Type: multipart/form-data",
"Accept: text/plain",
})
String testBodyMultipartFormdataArrayOfBinary(@Param("files") List<File> files);
/**
* Test array of binary in multipart mime
* Similar to <code>testBodyMultipartFormdataArrayOfBinary</code> but it also returns the http response headers .
* Test array of binary in multipart mime
* @param files (required)
* @return A ApiResponse that wraps the response boyd and the http headers.
*/
@RequestLine("POST /body/application/octetstream/array_of_binary")
@Headers({
"Content-Type: multipart/form-data",
"Accept: text/plain",
})
ApiResponse<String> testBodyMultipartFormdataArrayOfBinaryWithHttpInfo(@Param("files") List<File> files);
/**
* Test free form object
* Test free form object

View File

@@ -108,6 +108,8 @@ Class | Method | HTTP request | Description
*BodyApi* | [**testBinaryGifWithHttpInfo**](docs/BodyApi.md#testBinaryGifWithHttpInfo) | **POST** /binary/gif | Test binary (gif) response body
*BodyApi* | [**testBodyApplicationOctetstreamBinary**](docs/BodyApi.md#testBodyApplicationOctetstreamBinary) | **POST** /body/application/octetstream/binary | Test body parameter(s)
*BodyApi* | [**testBodyApplicationOctetstreamBinaryWithHttpInfo**](docs/BodyApi.md#testBodyApplicationOctetstreamBinaryWithHttpInfo) | **POST** /body/application/octetstream/binary | Test body parameter(s)
*BodyApi* | [**testBodyMultipartFormdataArrayOfBinary**](docs/BodyApi.md#testBodyMultipartFormdataArrayOfBinary) | **POST** /body/application/octetstream/array_of_binary | Test array of binary in multipart mime
*BodyApi* | [**testBodyMultipartFormdataArrayOfBinaryWithHttpInfo**](docs/BodyApi.md#testBodyMultipartFormdataArrayOfBinaryWithHttpInfo) | **POST** /body/application/octetstream/array_of_binary | Test array of binary in multipart mime
*BodyApi* | [**testEchoBodyFreeFormObjectResponseString**](docs/BodyApi.md#testEchoBodyFreeFormObjectResponseString) | **POST** /echo/body/FreeFormObject/response_string | Test free form object
*BodyApi* | [**testEchoBodyFreeFormObjectResponseStringWithHttpInfo**](docs/BodyApi.md#testEchoBodyFreeFormObjectResponseStringWithHttpInfo) | **POST** /echo/body/FreeFormObject/response_string | Test free form object
*BodyApi* | [**testEchoBodyPet**](docs/BodyApi.md#testEchoBodyPet) | **POST** /echo/body/Pet | Test body parameter(s)

View File

@@ -427,6 +427,27 @@ paths:
tags:
- body
x-accepts: image/gif
/body/application/octetstream/array_of_binary:
post:
description: Test array of binary in multipart mime
operationId: test/body/multipart/formdata/array_of_binary
requestBody:
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/test_body_multipart_formdata_array_of_binary_request'
responses:
"200":
content:
text/plain:
schema:
type: string
description: Successful operation
summary: Test array of binary in multipart mime
tags:
- body
x-content-type: multipart/form-data
x-accepts: text/plain
components:
requestBodies:
Pet:
@@ -657,4 +678,14 @@ components:
allOf:
- $ref: '#/components/schemas/Bird'
- $ref: '#/components/schemas/Category'
test_body_multipart_formdata_array_of_binary_request:
properties:
files:
items:
format: binary
type: string
type: array
required:
- files
type: object

View File

@@ -8,6 +8,8 @@ All URIs are relative to *http://localhost:3000*
| [**testBinaryGifWithHttpInfo**](BodyApi.md#testBinaryGifWithHttpInfo) | **POST** /binary/gif | Test binary (gif) response body |
| [**testBodyApplicationOctetstreamBinary**](BodyApi.md#testBodyApplicationOctetstreamBinary) | **POST** /body/application/octetstream/binary | Test body parameter(s) |
| [**testBodyApplicationOctetstreamBinaryWithHttpInfo**](BodyApi.md#testBodyApplicationOctetstreamBinaryWithHttpInfo) | **POST** /body/application/octetstream/binary | Test body parameter(s) |
| [**testBodyMultipartFormdataArrayOfBinary**](BodyApi.md#testBodyMultipartFormdataArrayOfBinary) | **POST** /body/application/octetstream/array_of_binary | Test array of binary in multipart mime |
| [**testBodyMultipartFormdataArrayOfBinaryWithHttpInfo**](BodyApi.md#testBodyMultipartFormdataArrayOfBinaryWithHttpInfo) | **POST** /body/application/octetstream/array_of_binary | Test array of binary in multipart mime |
| [**testEchoBodyFreeFormObjectResponseString**](BodyApi.md#testEchoBodyFreeFormObjectResponseString) | **POST** /echo/body/FreeFormObject/response_string | Test free form object |
| [**testEchoBodyFreeFormObjectResponseStringWithHttpInfo**](BodyApi.md#testEchoBodyFreeFormObjectResponseStringWithHttpInfo) | **POST** /echo/body/FreeFormObject/response_string | Test free form object |
| [**testEchoBodyPet**](BodyApi.md#testEchoBodyPet) | **POST** /echo/body/Pet | Test body parameter(s) |
@@ -279,6 +281,140 @@ No authorization required
| **200** | Successful operation | - |
## testBodyMultipartFormdataArrayOfBinary
> String testBodyMultipartFormdataArrayOfBinary(files)
Test array of binary in multipart mime
Test array of binary in multipart mime
### Example
```java
// Import classes:
import org.openapitools.client.ApiClient;
import org.openapitools.client.ApiException;
import org.openapitools.client.Configuration;
import org.openapitools.client.models.*;
import org.openapitools.client.api.BodyApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("http://localhost:3000");
BodyApi apiInstance = new BodyApi(defaultClient);
List<File> files = Arrays.asList(); // List<File> |
try {
String result = apiInstance.testBodyMultipartFormdataArrayOfBinary(files);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling BodyApi#testBodyMultipartFormdataArrayOfBinary");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
```
### Parameters
| Name | Type | Description | Notes |
|------------- | ------------- | ------------- | -------------|
| **files** | **List&lt;File&gt;**| | |
### Return type
**String**
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: multipart/form-data
- **Accept**: text/plain
### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | Successful operation | - |
## testBodyMultipartFormdataArrayOfBinaryWithHttpInfo
> ApiResponse<String> testBodyMultipartFormdataArrayOfBinary testBodyMultipartFormdataArrayOfBinaryWithHttpInfo(files)
Test array of binary in multipart mime
Test array of binary in multipart mime
### Example
```java
// Import classes:
import org.openapitools.client.ApiClient;
import org.openapitools.client.ApiException;
import org.openapitools.client.ApiResponse;
import org.openapitools.client.Configuration;
import org.openapitools.client.models.*;
import org.openapitools.client.api.BodyApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("http://localhost:3000");
BodyApi apiInstance = new BodyApi(defaultClient);
List<File> files = Arrays.asList(); // List<File> |
try {
ApiResponse<String> response = apiInstance.testBodyMultipartFormdataArrayOfBinaryWithHttpInfo(files);
System.out.println("Status code: " + response.getStatusCode());
System.out.println("Response headers: " + response.getHeaders());
System.out.println("Response body: " + response.getData());
} catch (ApiException e) {
System.err.println("Exception when calling BodyApi#testBodyMultipartFormdataArrayOfBinary");
System.err.println("Status code: " + e.getCode());
System.err.println("Response headers: " + e.getResponseHeaders());
System.err.println("Reason: " + e.getResponseBody());
e.printStackTrace();
}
}
}
```
### Parameters
| Name | Type | Description | Notes |
|------------- | ------------- | ------------- | -------------|
| **files** | **List&lt;File&gt;**| | |
### Return type
ApiResponse<**String**>
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: multipart/form-data
- **Accept**: text/plain
### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | Successful operation | - |
## testEchoBodyFreeFormObjectResponseString
> String testEchoBodyFreeFormObjectResponseString(body)

View File

@@ -24,6 +24,12 @@ import org.openapitools.client.model.Tag;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -229,6 +235,120 @@ public class BodyApi {
}
return localVarRequestBuilder;
}
/**
* Test array of binary in multipart mime
* Test array of binary in multipart mime
* @param files (required)
* @return String
* @throws ApiException if fails to make API call
*/
public String testBodyMultipartFormdataArrayOfBinary(List<File> files) throws ApiException {
ApiResponse<String> localVarResponse = testBodyMultipartFormdataArrayOfBinaryWithHttpInfo(files);
return localVarResponse.getData();
}
/**
* Test array of binary in multipart mime
* Test array of binary in multipart mime
* @param files (required)
* @return ApiResponse&lt;String&gt;
* @throws ApiException if fails to make API call
*/
public ApiResponse<String> testBodyMultipartFormdataArrayOfBinaryWithHttpInfo(List<File> files) throws ApiException {
HttpRequest.Builder localVarRequestBuilder = testBodyMultipartFormdataArrayOfBinaryRequestBuilder(files);
try {
HttpResponse<InputStream> localVarResponse = memberVarHttpClient.send(
localVarRequestBuilder.build(),
HttpResponse.BodyHandlers.ofInputStream());
if (memberVarResponseInterceptor != null) {
memberVarResponseInterceptor.accept(localVarResponse);
}
try {
if (localVarResponse.statusCode()/ 100 != 2) {
throw getApiException("testBodyMultipartFormdataArrayOfBinary", localVarResponse);
}
// for plain text response
if (localVarResponse.headers().map().containsKey("Content-Type") &&
"text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) {
java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A");
String responseBodyText = s.hasNext() ? s.next() : "";
return new ApiResponse<String>(
localVarResponse.statusCode(),
localVarResponse.headers().map(),
responseBodyText
);
} else {
throw new RuntimeException("Error! The response Content-Type is supposed to be `text/plain` but it's not: " + localVarResponse);
}
} finally {
}
} catch (IOException e) {
throw new ApiException(e);
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new ApiException(e);
}
}
private HttpRequest.Builder testBodyMultipartFormdataArrayOfBinaryRequestBuilder(List<File> files) throws ApiException {
// verify the required parameter 'files' is set
if (files == null) {
throw new ApiException(400, "Missing the required parameter 'files' when calling testBodyMultipartFormdataArrayOfBinary");
}
HttpRequest.Builder localVarRequestBuilder = HttpRequest.newBuilder();
String localVarPath = "/body/application/octetstream/array_of_binary";
localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath));
localVarRequestBuilder.header("Accept", "text/plain");
MultipartEntityBuilder multiPartBuilder = MultipartEntityBuilder.create();
boolean hasFiles = false;
for (int i=0; i < files.size(); i++) {
multiPartBuilder.addBinaryBody("files", files.get(i));
hasFiles = true;
}
HttpEntity entity = multiPartBuilder.build();
HttpRequest.BodyPublisher formDataPublisher;
if (hasFiles) {
Pipe pipe;
try {
pipe = Pipe.open();
} catch (IOException e) {
throw new RuntimeException(e);
}
new Thread(() -> {
try (OutputStream outputStream = Channels.newOutputStream(pipe.sink())) {
entity.writeTo(outputStream);
} catch (IOException e) {
e.printStackTrace();
}
}).start();
formDataPublisher = HttpRequest.BodyPublishers.ofInputStream(() -> Channels.newInputStream(pipe.source()));
} else {
ByteArrayOutputStream formOutputStream = new ByteArrayOutputStream();
try {
entity.writeTo(formOutputStream);
} catch (IOException e) {
throw new RuntimeException(e);
}
formDataPublisher = HttpRequest.BodyPublishers
.ofInputStream(() -> new ByteArrayInputStream(formOutputStream.toByteArray()));
}
localVarRequestBuilder
.header("Content-Type", entity.getContentType().getValue())
.method("POST", formDataPublisher);
if (memberVarReadTimeout != null) {
localVarRequestBuilder.timeout(memberVarReadTimeout);
}
if (memberVarInterceptor != null) {
memberVarInterceptor.accept(localVarRequestBuilder);
}
return localVarRequestBuilder;
}
/**
* Test free form object
* Test free form object

View File

@@ -21,7 +21,11 @@ import org.openapitools.client.model.*;
import org.junit.Test;
import org.junit.Ignore;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.util.*;
/**
@@ -279,4 +283,33 @@ public class CustomTest {
Assert.assertEquals("/form/integer/boolean/string", p.path);
Assert.assertEquals("3b\ninteger_form=1337&boolean_form=true&string_form=Hello+World\n0\n\n", p.body);
}
@Test
public void testBodyMultipartFormdataArrayOfBinary() throws ApiException {
File file1 = Objects.requireNonNull(getFile("Hello"));
File file2 = Objects.requireNonNull(getFile("World"));
String response = bodyApi.testBodyMultipartFormdataArrayOfBinary(List.of(file1, file2));
org.openapitools.client.EchoServerResponseParser p = new org.openapitools.client.EchoServerResponseParser(response);
Assert.assertEquals("/body/application/octetstream/array_of_binary", p.path);
Assert.assertTrue(p.body.contains(file1.getName()));
Assert.assertTrue(p.body.contains("Hello"));
Assert.assertTrue(p.body.contains(file2.getName()));
Assert.assertTrue(p.body.contains("World"));
}
private File getFile(String content) {
try {
File tempFile = Files.createTempFile("tempFile", ".txt").toFile();
BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
writer.write(content);
writer.close();
return tempFile;
} catch (IOException e) {
return null;
}
}
}

View File

@@ -114,6 +114,7 @@ Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*BodyApi* | [**testBinaryGif**](docs/BodyApi.md#testBinaryGif) | **POST** /binary/gif | Test binary (gif) response body
*BodyApi* | [**testBodyApplicationOctetstreamBinary**](docs/BodyApi.md#testBodyApplicationOctetstreamBinary) | **POST** /body/application/octetstream/binary | Test body parameter(s)
*BodyApi* | [**testBodyMultipartFormdataArrayOfBinary**](docs/BodyApi.md#testBodyMultipartFormdataArrayOfBinary) | **POST** /body/application/octetstream/array_of_binary | Test array of binary in multipart mime
*BodyApi* | [**testEchoBodyFreeFormObjectResponseString**](docs/BodyApi.md#testEchoBodyFreeFormObjectResponseString) | **POST** /echo/body/FreeFormObject/response_string | Test free form object
*BodyApi* | [**testEchoBodyPet**](docs/BodyApi.md#testEchoBodyPet) | **POST** /echo/body/Pet | Test body parameter(s)
*BodyApi* | [**testEchoBodyPetResponseString**](docs/BodyApi.md#testEchoBodyPetResponseString) | **POST** /echo/body/Pet/response_string | Test empty response body

View File

@@ -427,6 +427,27 @@ paths:
tags:
- body
x-accepts: image/gif
/body/application/octetstream/array_of_binary:
post:
description: Test array of binary in multipart mime
operationId: test/body/multipart/formdata/array_of_binary
requestBody:
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/test_body_multipart_formdata_array_of_binary_request'
responses:
"200":
content:
text/plain:
schema:
type: string
description: Successful operation
summary: Test array of binary in multipart mime
tags:
- body
x-content-type: multipart/form-data
x-accepts: text/plain
components:
requestBodies:
Pet:
@@ -657,4 +678,14 @@ components:
allOf:
- $ref: '#/components/schemas/Bird'
- $ref: '#/components/schemas/Category'
test_body_multipart_formdata_array_of_binary_request:
properties:
files:
items:
format: binary
type: string
type: array
required:
- files
type: object

View File

@@ -6,6 +6,7 @@ All URIs are relative to *http://localhost:3000*
|------------- | ------------- | -------------|
| [**testBinaryGif**](BodyApi.md#testBinaryGif) | **POST** /binary/gif | Test binary (gif) response body |
| [**testBodyApplicationOctetstreamBinary**](BodyApi.md#testBodyApplicationOctetstreamBinary) | **POST** /body/application/octetstream/binary | Test body parameter(s) |
| [**testBodyMultipartFormdataArrayOfBinary**](BodyApi.md#testBodyMultipartFormdataArrayOfBinary) | **POST** /body/application/octetstream/array_of_binary | Test array of binary in multipart mime |
| [**testEchoBodyFreeFormObjectResponseString**](BodyApi.md#testEchoBodyFreeFormObjectResponseString) | **POST** /echo/body/FreeFormObject/response_string | Test free form object |
| [**testEchoBodyPet**](BodyApi.md#testEchoBodyPet) | **POST** /echo/body/Pet | Test body parameter(s) |
| [**testEchoBodyPetResponseString**](BodyApi.md#testEchoBodyPetResponseString) | **POST** /echo/body/Pet/response_string | Test empty response body |
@@ -132,6 +133,68 @@ No authorization required
|-------------|-------------|------------------|
| **200** | Successful operation | - |
<a id="testBodyMultipartFormdataArrayOfBinary"></a>
# **testBodyMultipartFormdataArrayOfBinary**
> String testBodyMultipartFormdataArrayOfBinary(files)
Test array of binary in multipart mime
Test array of binary in multipart mime
### Example
```java
// Import classes:
import org.openapitools.client.ApiClient;
import org.openapitools.client.ApiException;
import org.openapitools.client.Configuration;
import org.openapitools.client.models.*;
import org.openapitools.client.api.BodyApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("http://localhost:3000");
BodyApi apiInstance = new BodyApi(defaultClient);
List<File> files = Arrays.asList(); // List<File> |
try {
String result = apiInstance.testBodyMultipartFormdataArrayOfBinary(files);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling BodyApi#testBodyMultipartFormdataArrayOfBinary");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
```
### Parameters
| Name | Type | Description | Notes |
|------------- | ------------- | ------------- | -------------|
| **files** | **List&lt;File&gt;**| | |
### Return type
**String**
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: multipart/form-data
- **Accept**: text/plain
### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | Successful operation | - |
<a id="testEchoBodyFreeFormObjectResponseString"></a>
# **testEchoBodyFreeFormObjectResponseString**
> String testEchoBodyFreeFormObjectResponseString(body)

View File

@@ -305,6 +305,133 @@ public class BodyApi {
localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
return localVarCall;
}
/**
* Build call for testBodyMultipartFormdataArrayOfBinary
* @param files (required)
* @param _callback Callback for upload/download progress
* @return Call to execute
* @throws ApiException If fail to serialize the request body object
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> Successful operation </td><td> - </td></tr>
</table>
*/
public okhttp3.Call testBodyMultipartFormdataArrayOfBinaryCall(List<File> files, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
// Determine Base Path to Use
if (localCustomBaseUrl != null){
basePath = localCustomBaseUrl;
} else if ( localBasePaths.length > 0 ) {
basePath = localBasePaths[localHostIndex];
} else {
basePath = null;
}
Object localVarPostBody = null;
// create path and map variables
String localVarPath = "/body/application/octetstream/array_of_binary";
List<Pair> localVarQueryParams = new ArrayList<Pair>();
List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
Map<String, String> localVarCookieParams = new HashMap<String, String>();
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
if (files != null) {
localVarFormParams.put("files", files);
}
final String[] localVarAccepts = {
"text/plain"
};
final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts);
if (localVarAccept != null) {
localVarHeaderParams.put("Accept", localVarAccept);
}
final String[] localVarContentTypes = {
"multipart/form-data"
};
final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes);
if (localVarContentType != null) {
localVarHeaderParams.put("Content-Type", localVarContentType);
}
String[] localVarAuthNames = new String[] { };
return localVarApiClient.buildCall(basePath, localVarPath, "POST", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback);
}
@SuppressWarnings("rawtypes")
private okhttp3.Call testBodyMultipartFormdataArrayOfBinaryValidateBeforeCall(List<File> files, final ApiCallback _callback) throws ApiException {
// verify the required parameter 'files' is set
if (files == null) {
throw new ApiException("Missing the required parameter 'files' when calling testBodyMultipartFormdataArrayOfBinary(Async)");
}
return testBodyMultipartFormdataArrayOfBinaryCall(files, _callback);
}
/**
* Test array of binary in multipart mime
* Test array of binary in multipart mime
* @param files (required)
* @return String
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> Successful operation </td><td> - </td></tr>
</table>
*/
public String testBodyMultipartFormdataArrayOfBinary(List<File> files) throws ApiException {
ApiResponse<String> localVarResp = testBodyMultipartFormdataArrayOfBinaryWithHttpInfo(files);
return localVarResp.getData();
}
/**
* Test array of binary in multipart mime
* Test array of binary in multipart mime
* @param files (required)
* @return ApiResponse&lt;String&gt;
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> Successful operation </td><td> - </td></tr>
</table>
*/
public ApiResponse<String> testBodyMultipartFormdataArrayOfBinaryWithHttpInfo(List<File> files) throws ApiException {
okhttp3.Call localVarCall = testBodyMultipartFormdataArrayOfBinaryValidateBeforeCall(files, null);
Type localVarReturnType = new TypeToken<String>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
}
/**
* Test array of binary in multipart mime (asynchronously)
* Test array of binary in multipart mime
* @param files (required)
* @param _callback The callback to be executed when the API call finishes
* @return The request call
* @throws ApiException If fail to process the API call, e.g. serializing the request body object
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> Successful operation </td><td> - </td></tr>
</table>
*/
public okhttp3.Call testBodyMultipartFormdataArrayOfBinaryAsync(List<File> files, final ApiCallback<String> _callback) throws ApiException {
okhttp3.Call localVarCall = testBodyMultipartFormdataArrayOfBinaryValidateBeforeCall(files, _callback);
Type localVarReturnType = new TypeToken<String>(){}.getType();
localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
return localVarCall;
}
/**
* Build call for testEchoBodyFreeFormObjectResponseString
* @param body Free form object (optional)

View File

@@ -86,6 +86,7 @@ Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*BodyApi* | [**test_binary_gif**](docs/BodyApi.md#test_binary_gif) | **POST** /binary/gif | Test binary (gif) response body
*BodyApi* | [**test_body_application_octetstream_binary**](docs/BodyApi.md#test_body_application_octetstream_binary) | **POST** /body/application/octetstream/binary | Test body parameter(s)
*BodyApi* | [**test_body_multipart_formdata_array_of_binary**](docs/BodyApi.md#test_body_multipart_formdata_array_of_binary) | **POST** /body/application/octetstream/array_of_binary | Test array of binary in multipart mime
*BodyApi* | [**test_echo_body_free_form_object_response_string**](docs/BodyApi.md#test_echo_body_free_form_object_response_string) | **POST** /echo/body/FreeFormObject/response_string | Test free form object
*BodyApi* | [**test_echo_body_pet**](docs/BodyApi.md#test_echo_body_pet) | **POST** /echo/body/Pet | Test body parameter(s)
*BodyApi* | [**test_echo_body_pet_response_string**](docs/BodyApi.md#test_echo_body_pet_response_string) | **POST** /echo/body/Pet/response_string | Test empty response body

View File

@@ -6,6 +6,7 @@ Method | HTTP request | Description
------------- | ------------- | -------------
[**test_binary_gif**](BodyApi.md#test_binary_gif) | **POST** /binary/gif | Test binary (gif) response body
[**test_body_application_octetstream_binary**](BodyApi.md#test_body_application_octetstream_binary) | **POST** /body/application/octetstream/binary | Test body parameter(s)
[**test_body_multipart_formdata_array_of_binary**](BodyApi.md#test_body_multipart_formdata_array_of_binary) | **POST** /body/application/octetstream/array_of_binary | Test array of binary in multipart mime
[**test_echo_body_free_form_object_response_string**](BodyApi.md#test_echo_body_free_form_object_response_string) | **POST** /echo/body/FreeFormObject/response_string | Test free form object
[**test_echo_body_pet**](BodyApi.md#test_echo_body_pet) | **POST** /echo/body/Pet | Test body parameter(s)
[**test_echo_body_pet_response_string**](BodyApi.md#test_echo_body_pet_response_string) | **POST** /echo/body/Pet/response_string | Test empty response body
@@ -138,6 +139,71 @@ No authorization 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)
# **test_body_multipart_formdata_array_of_binary**
> str test_body_multipart_formdata_array_of_binary(files)
Test array of binary in multipart mime
Test array of binary in multipart mime
### Example
```python
import time
import os
import openapi_client
from openapi_client.rest import ApiException
from pprint import pprint
# Defining the host is optional and defaults to http://localhost:3000
# See configuration.py for a list of all supported configuration parameters.
configuration = openapi_client.Configuration(
host = "http://localhost:3000"
)
# Enter a context with an instance of the API client
with openapi_client.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = openapi_client.BodyApi(api_client)
files = None # List[bytearray] |
try:
# Test array of binary in multipart mime
api_response = api_instance.test_body_multipart_formdata_array_of_binary(files)
print("The response of BodyApi->test_body_multipart_formdata_array_of_binary:\n")
pprint(api_response)
except Exception as e:
print("Exception when calling BodyApi->test_body_multipart_formdata_array_of_binary: %s\n" % e)
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**files** | **List[bytearray]**| |
### Return type
**str**
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: multipart/form-data
- **Accept**: text/plain
### 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)
# **test_echo_body_free_form_object_response_string**
> str test_echo_body_free_form_object_response_string(body=body)

View File

@@ -20,7 +20,7 @@ import warnings
from pydantic import validate_arguments, ValidationError
from typing_extensions import Annotated
from pydantic import Field, StrictBytes, StrictStr
from pydantic import Field, StrictBytes, StrictStr, conlist
from typing import Any, Dict, Optional, Union
@@ -329,6 +329,153 @@ class BodyApi(object):
collection_formats=_collection_formats,
_request_auth=_params.get('_request_auth'))
@validate_arguments
def test_body_multipart_formdata_array_of_binary(self, files : conlist(Union[StrictBytes, StrictStr]), **kwargs) -> str: # noqa: E501
"""Test array of binary in multipart mime # noqa: E501
Test array of binary in multipart mime # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async_req=True
>>> thread = api.test_body_multipart_formdata_array_of_binary(files, async_req=True)
>>> result = thread.get()
:param files: (required)
:type files: List[bytearray]
:param async_req: Whether to execute the request asynchronously.
:type async_req: bool, optional
:param _request_timeout: timeout setting for this request. If one
number provided, it will be total request
timeout. It can also be a pair (tuple) of
(connection, read) timeouts.
:return: Returns the result object.
If the method is called asynchronously,
returns the request thread.
:rtype: str
"""
kwargs['_return_http_data_only'] = True
if '_preload_content' in kwargs:
raise ValueError("Error! Please call the test_body_multipart_formdata_array_of_binary_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data")
return self.test_body_multipart_formdata_array_of_binary_with_http_info(files, **kwargs) # noqa: E501
@validate_arguments
def test_body_multipart_formdata_array_of_binary_with_http_info(self, files : conlist(Union[StrictBytes, StrictStr]), **kwargs) -> ApiResponse: # noqa: E501
"""Test array of binary in multipart mime # noqa: E501
Test array of binary in multipart mime # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async_req=True
>>> thread = api.test_body_multipart_formdata_array_of_binary_with_http_info(files, async_req=True)
>>> result = thread.get()
:param files: (required)
:type files: List[bytearray]
:param async_req: Whether to execute the request asynchronously.
:type async_req: bool, optional
:param _preload_content: if False, the ApiResponse.data will
be set to none and raw_data will store the
HTTP response body without reading/decoding.
Default is True.
:type _preload_content: bool, optional
:param _return_http_data_only: response data instead of ApiResponse
object with status code, headers, etc
:type _return_http_data_only: bool, optional
:param _request_timeout: timeout setting for this request. If one
number provided, it will be total request
timeout. It can also be a pair (tuple) of
(connection, read) timeouts.
:param _request_auth: set to override the auth_settings for an a single
request; this effectively ignores the authentication
in the spec for a single request.
:type _request_auth: dict, optional
:type _content_type: string, optional: force content-type for the request
:return: Returns the result object.
If the method is called asynchronously,
returns the request thread.
:rtype: tuple(str, status_code(int), headers(HTTPHeaderDict))
"""
_params = locals()
_all_params = [
'files'
]
_all_params.extend(
[
'async_req',
'_return_http_data_only',
'_preload_content',
'_request_timeout',
'_request_auth',
'_content_type',
'_headers'
]
)
# validate the arguments
for _key, _val in _params['kwargs'].items():
if _key not in _all_params:
raise ApiTypeError(
"Got an unexpected keyword argument '%s'"
" to method test_body_multipart_formdata_array_of_binary" % _key
)
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
# process the path parameters
_path_params = {}
# process the query parameters
_query_params = []
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
if _params['files']:
_files['files'] = _params['files']
_collection_formats['files'] = 'csv'
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
_header_params['Accept'] = self.api_client.select_header_accept(
['text/plain']) # noqa: E501
# set the HTTP header `Content-Type`
_content_types_list = _params.get('_content_type',
self.api_client.select_header_content_type(
['multipart/form-data']))
if _content_types_list:
_header_params['Content-Type'] = _content_types_list
# authentication setting
_auth_settings = [] # noqa: E501
_response_types_map = {
'200': "str",
}
return self.api_client.call_api(
'/body/application/octetstream/array_of_binary', 'POST',
_path_params,
_query_params,
_header_params,
body=_body_params,
post_params=_form_params,
files=_files,
response_types_map=_response_types_map,
auth_settings=_auth_settings,
async_req=_params.get('async_req'),
_return_http_data_only=_params.get('_return_http_data_only'), # noqa: E501
_preload_content=_params.get('_preload_content', True),
_request_timeout=_params.get('_request_timeout'),
collection_formats=_collection_formats,
_request_auth=_params.get('_request_auth'))
@validate_arguments
def test_echo_body_free_form_object_response_string(self, body : Annotated[Optional[Dict[str, Any]], Field(description="Free form object")] = None, **kwargs) -> str: # noqa: E501
"""Test free form object # noqa: E501