Skip to content

Commit 44bbe30

Browse files
committed
Support primitive string response in Java clients
1 parent 69f8274 commit 44bbe30

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,15 @@ public class ApiClient {
385385
386386
if (contentType.startsWith("application/json")) {
387387
return json.deserialize(body, returnType);
388+
} else if (returnType.getType().equals(String.class)) {
389+
// Expecting string, return the raw response body.
390+
return (T) body;
388391
} else {
389-
throw new ApiException(500, "can not deserialize Content-Type: " + contentType);
392+
throw new ApiException(
393+
500,
394+
"Content type \"" + contentType + "\" is not supported for type: "
395+
+ returnType.getType()
396+
);
390397
}
391398
}
392399

modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,15 @@ public class ApiClient {
389389
390390
if (contentType.startsWith("application/json")) {
391391
return json.deserialize(body, returnType);
392+
} else if (returnType.getType().equals(String.class)) {
393+
// Expecting string, return the raw response body.
394+
return (T) body;
392395
} else {
393-
throw new ApiException(500, "can not deserialize Content-Type: " + contentType);
396+
throw new ApiException(
397+
500,
398+
"Content type \"" + contentType + "\" is not supported for type: "
399+
+ returnType.getType()
400+
);
394401
}
395402
}
396403

@@ -429,7 +436,7 @@ public class ApiClient {
429436
}
430437
}
431438

432-
Invocation.Builder invocationBuilder = target.request(contentType).accept(accept);
439+
Invocation.Builder invocationBuilder = target.request().accept(accept);
433440

434441
for (String key : headerParams.keySet()) {
435442
String value = headerParams.get(key);

modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,9 +536,12 @@ public class ApiClient {
536536
}
537537
if (contentType.startsWith("application/json")) {
538538
return json.deserialize(respBody, returnType);
539+
} else if (returnType.equals(String.class)) {
540+
// Expecting string, return the raw response body.
541+
return (T) respBody;
539542
} else {
540543
throw new ApiException(
541-
"Content type \"" + contentType + "\" is not supported",
544+
"Content type \"" + contentType + "\" is not supported for type: " + returnType,
542545
response.code(),
543546
response.headers().toMultimap(),
544547
respBody);

0 commit comments

Comments
 (0)