From f2c3aaca6eef27d20db8d02b767f7d4e6b589e0f Mon Sep 17 00:00:00 2001 From: raffael Date: Wed, 30 Aug 2017 12:51:45 +0200 Subject: [PATCH] Retrofit2: Return ResponseBody if response if file. 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 36d4a5c55a9..bee45765669 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}} @@ -60,7 +61,7 @@ public interface {{classname}} { {{/prioritizedContentTypes}} {{/formParams}} @{{httpMethod}}("{{{path}}}") - {{^usePlay24WS}}{{^doNotUseRx}}Observable{{/doNotUseRx}}{{#doNotUseRx}}Call{{/doNotUseRx}}{{/usePlay24WS}}{{#usePlay24WS}}F.Promise{{#usePlay24WS}}>{{/usePlay24WS}} {{operationId}}({{^allParams}});{{/allParams}} + {{^usePlay24WS}}{{^doNotUseRx}}Observable{{/doNotUseRx}}{{#doNotUseRx}}Call{{/doNotUseRx}}{{/usePlay24WS}}{{#usePlay24WS}}F.Promise{{#usePlay24WS}}>{{/usePlay24WS}} {{operationId}}({{^allParams}});{{/allParams}} {{#allParams}}{{>libraries/retrofit2/queryParams}}{{>libraries/retrofit2/pathParams}}{{>libraries/retrofit2/headerParams}}{{>libraries/retrofit2/bodyParams}}{{>libraries/retrofit2/formParams}}{{#hasMore}}, {{/hasMore}}{{^hasMore}} );{{/hasMore}}{{/allParams}}