Skip to content

Commit 2e2e557

Browse files
borschrk0n
authored andcommitted
[Java][OkHTTP] fix empty request body handling (OpenAPITools#12172)
1 parent cfd51ef commit 2e2e557

File tree

5 files changed

+5
-5
lines changed
  • modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson
  • samples/client
    • others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client
    • petstore/java
      • okhttp-gson-dynamicOperations/src/main/java/org/openapitools/client
      • okhttp-gson-parcelableModel/src/main/java/org/openapitools/client
      • okhttp-gson/src/main/java/org/openapitools/client

5 files changed

+5
-5
lines changed

modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,7 @@ public class ApiClient {
13561356
reqBody = null;
13571357
} else {
13581358
// use an empty request body (for POST, PUT and PATCH)
1359-
reqBody = RequestBody.create("", MediaType.parse(contentType));
1359+
reqBody = RequestBody.create("", contentType == null ? null : MediaType.parse(contentType));
13601360
}
13611361
} else {
13621362
reqBody = serialize(body, contentType);

samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,7 @@ public Request buildRequest(String baseUrl, String path, String method, List<Pai
11511151
reqBody = null;
11521152
} else {
11531153
// use an empty request body (for POST, PUT and PATCH)
1154-
reqBody = RequestBody.create("", MediaType.parse(contentType));
1154+
reqBody = RequestBody.create("", contentType == null ? null : MediaType.parse(contentType));
11551155
}
11561156
} else {
11571157
reqBody = serialize(body, contentType);

samples/client/petstore/java/okhttp-gson-dynamicOperations/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ public Request buildRequest(String baseUrl, String path, String method, List<Pai
12291229
reqBody = null;
12301230
} else {
12311231
// use an empty request body (for POST, PUT and PATCH)
1232-
reqBody = RequestBody.create("", MediaType.parse(contentType));
1232+
reqBody = RequestBody.create("", contentType == null ? null : MediaType.parse(contentType));
12331233
}
12341234
} else {
12351235
reqBody = serialize(body, contentType);

samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ public Request buildRequest(String baseUrl, String path, String method, List<Pai
12301230
reqBody = null;
12311231
} else {
12321232
// use an empty request body (for POST, PUT and PATCH)
1233-
reqBody = RequestBody.create("", MediaType.parse(contentType));
1233+
reqBody = RequestBody.create("", contentType == null ? null : MediaType.parse(contentType));
12341234
}
12351235
} else {
12361236
reqBody = serialize(body, contentType);

samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ public Request buildRequest(String baseUrl, String path, String method, List<Pai
12491249
reqBody = null;
12501250
} else {
12511251
// use an empty request body (for POST, PUT and PATCH)
1252-
reqBody = RequestBody.create("", MediaType.parse(contentType));
1252+
reqBody = RequestBody.create("", contentType == null ? null : MediaType.parse(contentType));
12531253
}
12541254
} else {
12551255
reqBody = serialize(body, contentType);

0 commit comments

Comments
 (0)