forked from loafle/openapi-generator-original
[Java][okhttp-gson] Support text/plain body (#10885)
* support serialize RequestBody with contentType text/plain * add Serialize test * update test comment
This commit is contained in:
parent
06faa289bd
commit
3d92df5a41
@ -1081,6 +1081,8 @@ public class ApiClient {
|
||||
} else if (obj instanceof File) {
|
||||
// File body parameter support.
|
||||
return RequestBody.create((File) obj, MediaType.parse(contentType));
|
||||
} else if ("text/plain".equals(contentType) && obj instanceof String) {
|
||||
return RequestBody.create((String) obj, MediaType.parse(contentType));
|
||||
} else if (isJsonMime(contentType)) {
|
||||
String content;
|
||||
if (obj != null) {
|
||||
|
@ -871,6 +871,8 @@ public class ApiClient {
|
||||
} else if (obj instanceof File) {
|
||||
// File body parameter support.
|
||||
return RequestBody.create((File) obj, MediaType.parse(contentType));
|
||||
} else if ("text/plain".equals(contentType) && obj instanceof String) {
|
||||
return RequestBody.create((String) obj, MediaType.parse(contentType));
|
||||
} else if (isJsonMime(contentType)) {
|
||||
String content;
|
||||
if (obj != null) {
|
||||
|
@ -972,6 +972,8 @@ public class ApiClient {
|
||||
} else if (obj instanceof File) {
|
||||
// File body parameter support.
|
||||
return RequestBody.create((File) obj, MediaType.parse(contentType));
|
||||
} else if ("text/plain".equals(contentType) && obj instanceof String) {
|
||||
return RequestBody.create((String) obj, MediaType.parse(contentType));
|
||||
} else if (isJsonMime(contentType)) {
|
||||
String content;
|
||||
if (obj != null) {
|
||||
|
@ -973,6 +973,8 @@ public class ApiClient {
|
||||
} else if (obj instanceof File) {
|
||||
// File body parameter support.
|
||||
return RequestBody.create((File) obj, MediaType.parse(contentType));
|
||||
} else if ("text/plain".equals(contentType) && obj instanceof String) {
|
||||
return RequestBody.create((String) obj, MediaType.parse(contentType));
|
||||
} else if (isJsonMime(contentType)) {
|
||||
String content;
|
||||
if (obj != null) {
|
||||
|
@ -973,6 +973,8 @@ public class ApiClient {
|
||||
} else if (obj instanceof File) {
|
||||
// File body parameter support.
|
||||
return RequestBody.create((File) obj, MediaType.parse(contentType));
|
||||
} else if ("text/plain".equals(contentType) && obj instanceof String) {
|
||||
return RequestBody.create((String) obj, MediaType.parse(contentType));
|
||||
} else if (isJsonMime(contentType)) {
|
||||
String content;
|
||||
if (obj != null) {
|
||||
|
@ -342,4 +342,22 @@ public class ApiClientTest {
|
||||
public void testNullHttpClient() {
|
||||
apiClient.setHttpClient(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the ApiClient serialize methods
|
||||
*/
|
||||
@Test
|
||||
public void testSerializeRequest() throws ApiException {
|
||||
assertNotNull(apiClient.serialize("test", "text/plain"));
|
||||
assertNotNull(apiClient.serialize("{}", "application/json"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the ApiClient serialize methods with unsupported content-type
|
||||
* should raise ApiException
|
||||
*/
|
||||
@Test(expected = ApiException.class)
|
||||
public void testUnsupportedSerializeRequest() throws ApiException {
|
||||
apiClient.serialize("test", "unsupported/type");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user