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.
This commit is contained in:
craffael 2017-09-01 11:01:15 +02:00 committed by wing328
parent 5a533a2f00
commit 481c040373

View File

@ -14,6 +14,7 @@ import retrofit2.Call;
import retrofit2.http.*;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
{{#imports}}import {{import}};
{{/imports}}
@ -55,7 +56,7 @@ public interface {{classname}} {
{{/prioritizedContentTypes}}
{{/formParams}}
@{{httpMethod}}("{{{path}}}")
{{^doNotUseRx}}Observable{{/doNotUseRx}}{{#doNotUseRx}}Call{{/doNotUseRx}}<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Object{{/returnType}}> {{operationId}}({{^allParams}});{{/allParams}}
{{^doNotUseRx}}Observable{{/doNotUseRx}}{{#doNotUseRx}}Call{{/doNotUseRx}}<{{#isResponseFile}}ResponseBody{{/isResponseFile}}{{^isResponseFile}}{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Object{{/returnType}}{{/isResponseFile}}> {{operationId}}({{^allParams}});{{/allParams}}
{{#allParams}}{{>libraries/retrofit2/queryParams}}{{>libraries/retrofit2/pathParams}}{{>libraries/retrofit2/headerParams}}{{>libraries/retrofit2/bodyParams}}{{>libraries/retrofit2/formParams}}{{#hasMore}}, {{/hasMore}}{{^hasMore}}
);{{/hasMore}}{{/allParams}}