forked from loafle/openapi-generator-original
fix java apache client optional body, add tests (#14227)
This commit is contained in:
parent
1fad61e2f8
commit
11d31117a8
@ -1059,6 +1059,9 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
|
|||||||
} else {
|
} else {
|
||||||
throw new ApiException("method " + method + " does not support a request body");
|
throw new ApiException("method " + method + " does not support a request body");
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// for empty body
|
||||||
|
builder.setEntity(serialize(null, null, contentTypeObj));
|
||||||
}
|
}
|
||||||
|
|
||||||
try (CloseableHttpResponse response = httpClient.execute(builder.build(), context)) {
|
try (CloseableHttpResponse response = httpClient.execute(builder.build(), context)) {
|
||||||
|
@ -932,6 +932,9 @@ public class ApiClient extends JavaTimeFormatter {
|
|||||||
} else {
|
} else {
|
||||||
throw new ApiException("method " + method + " does not support a request body");
|
throw new ApiException("method " + method + " does not support a request body");
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// for empty body
|
||||||
|
builder.setEntity(serialize(null, null, contentTypeObj));
|
||||||
}
|
}
|
||||||
|
|
||||||
try (CloseableHttpResponse response = httpClient.execute(builder.build(), context)) {
|
try (CloseableHttpResponse response = httpClient.execute(builder.build(), context)) {
|
||||||
|
@ -15,10 +15,8 @@ package org.openapitools.client;
|
|||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.openapitools.client.ApiException;
|
import org.openapitools.client.ApiException;
|
||||||
import org.openapitools.client.api.QueryApi;
|
import org.openapitools.client.api.*;
|
||||||
import org.openapitools.client.model.Category;
|
import org.openapitools.client.model.*;
|
||||||
import org.openapitools.client.model.Pet;
|
|
||||||
import org.openapitools.client.model.TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
|
|
||||||
@ -31,7 +29,29 @@ import java.util.*;
|
|||||||
public class CustomTest {
|
public class CustomTest {
|
||||||
|
|
||||||
private final QueryApi api = new QueryApi();
|
private final QueryApi api = new QueryApi();
|
||||||
|
private final BodyApi bodyApi = new BodyApi();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test body parameter(s)
|
||||||
|
* <p>
|
||||||
|
* Test body parameter(s)
|
||||||
|
*
|
||||||
|
* @throws ApiException if the Api call fails
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testEchoBodyPet() throws ApiException {
|
||||||
|
Pet queryObject = new Pet().id(12345L).name("Hello World").
|
||||||
|
photoUrls(Arrays.asList(new String[]{"http://a.com", "http://b.com"})).category(new Category().id(987L).name("new category"));
|
||||||
|
|
||||||
|
Pet p = bodyApi.testEchoBodyPet(queryObject);
|
||||||
|
Assert.assertNotNull(p);
|
||||||
|
Assert.assertEquals("Hello World", p.getName());
|
||||||
|
Assert.assertEquals(Long.valueOf(12345L), p.getId());
|
||||||
|
|
||||||
|
// response is empty body
|
||||||
|
Pet p2 = bodyApi.testEchoBodyPet(null);
|
||||||
|
Assert.assertNull(p2);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test query parameter(s)
|
* Test query parameter(s)
|
||||||
|
@ -1075,6 +1075,9 @@ public class ApiClient extends JavaTimeFormatter {
|
|||||||
} else {
|
} else {
|
||||||
throw new ApiException("method " + method + " does not support a request body");
|
throw new ApiException("method " + method + " does not support a request body");
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// for empty body
|
||||||
|
builder.setEntity(serialize(null, null, contentTypeObj));
|
||||||
}
|
}
|
||||||
|
|
||||||
try (CloseableHttpResponse response = httpClient.execute(builder.build(), context)) {
|
try (CloseableHttpResponse response = httpClient.execute(builder.build(), context)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user