forked from loafle/openapi-generator-original
[java][native] Add tests for oneOf form parameters (#16487)
* add tests for oneOf form parameters * update samples
This commit is contained in:
@@ -185,4 +185,118 @@ public class FormApi {
|
||||
}
|
||||
return localVarRequestBuilder;
|
||||
}
|
||||
/**
|
||||
* Test form parameter(s) for oneOf schema
|
||||
* Test form parameter(s) for oneOf schema
|
||||
* @param form1 (optional)
|
||||
* @param form2 (optional)
|
||||
* @param form3 (optional)
|
||||
* @param form4 (optional)
|
||||
* @param id (optional)
|
||||
* @param name (optional)
|
||||
* @return String
|
||||
* @throws ApiException if fails to make API call
|
||||
*/
|
||||
public String testFormOneof(String form1, Integer form2, String form3, Boolean form4, Long id, String name) throws ApiException {
|
||||
ApiResponse<String> localVarResponse = testFormOneofWithHttpInfo(form1, form2, form3, form4, id, name);
|
||||
return localVarResponse.getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test form parameter(s) for oneOf schema
|
||||
* Test form parameter(s) for oneOf schema
|
||||
* @param form1 (optional)
|
||||
* @param form2 (optional)
|
||||
* @param form3 (optional)
|
||||
* @param form4 (optional)
|
||||
* @param id (optional)
|
||||
* @param name (optional)
|
||||
* @return ApiResponse<String>
|
||||
* @throws ApiException if fails to make API call
|
||||
*/
|
||||
public ApiResponse<String> testFormOneofWithHttpInfo(String form1, Integer form2, String form3, Boolean form4, Long id, String name) throws ApiException {
|
||||
HttpRequest.Builder localVarRequestBuilder = testFormOneofRequestBuilder(form1, form2, form3, form4, id, name);
|
||||
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("testFormOneof", 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 testFormOneofRequestBuilder(String form1, Integer form2, String form3, Boolean form4, Long id, String name) throws ApiException {
|
||||
|
||||
HttpRequest.Builder localVarRequestBuilder = HttpRequest.newBuilder();
|
||||
|
||||
String localVarPath = "/form/oneof";
|
||||
|
||||
localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath));
|
||||
|
||||
localVarRequestBuilder.header("Accept", "text/plain");
|
||||
|
||||
List<NameValuePair> formValues = new ArrayList<>();
|
||||
if (form1 != null) {
|
||||
formValues.add(new BasicNameValuePair("form1", form1.toString()));
|
||||
}
|
||||
if (form2 != null) {
|
||||
formValues.add(new BasicNameValuePair("form2", form2.toString()));
|
||||
}
|
||||
if (form3 != null) {
|
||||
formValues.add(new BasicNameValuePair("form3", form3.toString()));
|
||||
}
|
||||
if (form4 != null) {
|
||||
formValues.add(new BasicNameValuePair("form4", form4.toString()));
|
||||
}
|
||||
if (id != null) {
|
||||
formValues.add(new BasicNameValuePair("id", id.toString()));
|
||||
}
|
||||
if (name != null) {
|
||||
formValues.add(new BasicNameValuePair("name", name.toString()));
|
||||
}
|
||||
HttpEntity entity = new UrlEncodedFormEntity(formValues, java.nio.charset.StandardCharsets.UTF_8);
|
||||
ByteArrayOutputStream formOutputStream = new ByteArrayOutputStream();
|
||||
try {
|
||||
entity.writeTo(formOutputStream);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
localVarRequestBuilder
|
||||
.header("Content-Type", entity.getContentType().getValue())
|
||||
.method("POST", HttpRequest.BodyPublishers
|
||||
.ofInputStream(() -> new ByteArrayInputStream(formOutputStream.toByteArray())));
|
||||
if (memberVarReadTimeout != null) {
|
||||
localVarRequestBuilder.timeout(memberVarReadTimeout);
|
||||
}
|
||||
if (memberVarInterceptor != null) {
|
||||
memberVarInterceptor.accept(localVarRequestBuilder);
|
||||
}
|
||||
return localVarRequestBuilder;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,6 +284,18 @@ public class CustomTest {
|
||||
Assert.assertEquals("3b\ninteger_form=1337&boolean_form=true&string_form=Hello+World\n0\n\n", p.body);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormOneOf() throws ApiException {
|
||||
String form1 = "form1_example"; // String |
|
||||
Integer form2 = 56; // Integer |
|
||||
String form3 = "form3 example"; // String |
|
||||
Boolean form4 = true;
|
||||
String response = formApi.testFormOneof(form1, form2, form3, form4, null, null);
|
||||
org.openapitools.client.EchoServerResponseParser p = new org.openapitools.client.EchoServerResponseParser(response);
|
||||
Assert.assertEquals("/form/oneof", p.path);
|
||||
Assert.assertEquals("3c\nform1=form1_example&form2=56&form3=form3++example&form4=true\n0\n\n", p.body);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBodyMultipartFormdataArrayOfBinary() throws ApiException {
|
||||
File file1 = Objects.requireNonNull(getFile("Hello"));
|
||||
|
||||
Reference in New Issue
Block a user