Skip to content

Commit 481c040

Browse files
craffaelwing328
authored andcommitted
Retrofit2: Return ResponseBody if response if file. (#6407)
Until now -------------------- If a swagger endpoint returned a file (e.g. an image), then the Retrofit2 template has choosen the return type java.io.File. However, retrofit cannot deal with this and throws a com.google.gson.stream.MalformedJsonException. New: ------------------- If a swagger endpoint returns a file, then the corresponding Retrofit2 endpoint will return a okhttp3.ResponseBody which can be used to retrieve the file.
1 parent 5a533a2 commit 481c040

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

  • modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2

modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/api.mustache

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import retrofit2.Call;
1414
import retrofit2.http.*;
1515

1616
import okhttp3.RequestBody;
17+
import okhttp3.ResponseBody;
1718

1819
{{#imports}}import {{import}};
1920
{{/imports}}
@@ -55,7 +56,7 @@ public interface {{classname}} {
5556
{{/prioritizedContentTypes}}
5657
{{/formParams}}
5758
@{{httpMethod}}("{{{path}}}")
58-
{{^doNotUseRx}}Observable{{/doNotUseRx}}{{#doNotUseRx}}Call{{/doNotUseRx}}<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Object{{/returnType}}> {{operationId}}({{^allParams}});{{/allParams}}
59+
{{^doNotUseRx}}Observable{{/doNotUseRx}}{{#doNotUseRx}}Call{{/doNotUseRx}}<{{#isResponseFile}}ResponseBody{{/isResponseFile}}{{^isResponseFile}}{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Object{{/returnType}}{{/isResponseFile}}> {{operationId}}({{^allParams}});{{/allParams}}
5960
{{#allParams}}{{>libraries/retrofit2/queryParams}}{{>libraries/retrofit2/pathParams}}{{>libraries/retrofit2/headerParams}}{{>libraries/retrofit2/bodyParams}}{{>libraries/retrofit2/formParams}}{{#hasMore}}, {{/hasMore}}{{^hasMore}}
6061
);{{/hasMore}}{{/allParams}}
6162

0 commit comments

Comments
 (0)