From ee2c0d6e0d19c9dbe6cc8a6a7308d79ddb865fed Mon Sep 17 00:00:00 2001 From: Adrien CABARBAYE Date: Wed, 14 Feb 2018 17:47:39 +0000 Subject: [PATCH] [Java][retrofit2] Fix for issue #7446: file upload sets filename as baseName instead of a dynamic filename. The solution is to use okhttp3.MultipartBody.Part instead of RequestBody in formParams template. --- .../src/main/resources/Java/libraries/retrofit2/api.mustache | 1 + .../main/resources/Java/libraries/retrofit2/formParams.mustache | 2 +- 2 files 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 0258afda049f..f6eb4c2dd07d 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 @@ -20,6 +20,7 @@ import retrofit2.http.*; import okhttp3.RequestBody; import okhttp3.ResponseBody; +import okhttp3.MultipartBody; {{#imports}}import {{import}}; {{/imports}} diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/formParams.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/formParams.mustache index 06c13e9ea33f..aab93a350aa3 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/formParams.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/formParams.mustache @@ -1 +1 @@ -{{#isFormParam}}{{#notFile}}{{#isMultipart}}@retrofit2.http.Part{{/isMultipart}}{{^isMultipart}}@retrofit2.http.Field{{/isMultipart}}("{{baseName}}") {{{dataType}}} {{paramName}}{{/notFile}}{{#isFile}}{{#isMultipart}}@retrofit2.http.Part{{/isMultipart}}{{^isMultipart}}@retrofit2.http.Field{{/isMultipart}}{{#usePlayWS}} okhttp3.MultipartBody.Part {{/usePlayWS}}{{^usePlayWS}}("{{baseName}}\"; filename=\"{{baseName}}") RequestBody {{/usePlayWS}}{{paramName}}{{/isFile}}{{/isFormParam}} \ No newline at end of file +{{#isFormParam}}{{#notFile}}{{#isMultipart}}@retrofit2.http.Part{{/isMultipart}}{{^isMultipart}}@retrofit2.http.Field{{/isMultipart}}("{{baseName}}") {{{dataType}}} {{paramName}}{{/notFile}}{{#isFile}}{{#isMultipart}}@retrofit2.http.Part{{/isMultipart}}{{^isMultipart}}@retrofit2.http.Field{{/isMultipart}}{{#usePlayWS}} okhttp3.MultipartBody.Part {{/usePlayWS}}{{^usePlayWS}}() MultipartBody.Part {{/usePlayWS}}{{paramName}}{{/isFile}}{{/isFormParam}} \ No newline at end of file