From 481c040373be1bbdae587b121b24b44a2520a6ce Mon Sep 17 00:00:00 2001 From: craffael Date: Fri, 1 Sep 2017 11:01:15 +0200 Subject: [PATCH] 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. --- .../src/main/resources/Java/libraries/retrofit2/api.mustache | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/api.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/api.mustache index e1d5220101c..00b28c20aab 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/api.mustache @@ -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}}