Skip to content

[Java][Retrofit2] Return ResponseBody if response is "file"#6407

Merged
wing328 merged 2 commits into
swagger-api:masterfrom
craffael:master
Sep 1, 2017
Merged

[Java][Retrofit2] Return ResponseBody if response is "file"#6407
wing328 merged 2 commits into
swagger-api:masterfrom
craffael:master

Conversation

@craffael

Copy link
Copy Markdown
Contributor

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.

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change.
    There is no shell script for Retrofit2
  • Filed the PR against the correct branch: master for non-breaking changes and 3.0.0 branch for breaking (non-backward compatible) changes.

Description of the PR

See issue #6406

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.
@wing328

wing328 commented Aug 31, 2017

Copy link
Copy Markdown
Contributor

@craffael thanks for the PR. I wonder if you and rebase the change on the latest master to resolve the merge conflicts as we just merged another PR related to retrofit2 into master.

@wing328 wing328 merged commit 481c040 into swagger-api:master Sep 1, 2017
@wing328

wing328 commented Sep 1, 2017

Copy link
Copy Markdown
Contributor

FYI. I've updated the petstore samples via 0f1a61d

Next time please run ./bin/java-petstore-retrofit2-all.sh to update the samples so that CIs can verify the change

@wing328 wing328 changed the title Retrofit2: Return ResponseBody if response if file. [Java][Retrofit2] Return ResponseBody if response if file. Sep 1, 2017
@wing328 wing328 changed the title [Java][Retrofit2] Return ResponseBody if response if file. [Java][Retrofit2] Return ResponseBody if response is "file" Sep 1, 2017
@wing328

wing328 commented Sep 1, 2017

Copy link
Copy Markdown
Contributor

I need to roll back this change due to the following errors:

Tests in error: 
  testUploadFile(io.swagger.client.api.PetApiTest): io.swagger.client.api.PetApi.uploadFile(Ljava/lang/Long;Ljava/lang/String;Lokhttp3/RequestBody;)Lretrofit2/Call;

Tests run: 18, Failures: 1, Errors: 1, Skipped: 0

wing328 added a commit that referenced this pull request Sep 1, 2017
wing328 added a commit that referenced this pull request Sep 1, 2017
…6421)

* Revert "Make the Rust codegen compile. (#6411)"

This reverts commit 60766c6.

* Revert "[Kotlin] Fix model enum generation (#6383)"

This reverts commit adf5d64.

* Revert "Global namespaces for ruby basic types (#6418)"

This reverts commit 070894d.

* Revert "add ehyche to swift tech comm"

This reverts commit 5c62ba1.

* Revert "[python-client] Thread pool fix (#6396)"

This reverts commit a28ce0b.

* Revert "update retrofit2 petstore samples"

This reverts commit 0f1a61d.

* Revert "Retrofit2: Return ResponseBody if response if file. (#6407)"

This reverts commit 481c040.
@craffael

craffael commented Sep 1, 2017

Copy link
Copy Markdown
Contributor Author

Sorry about that. I don't know why I didn't find ./bin/java-petstore-retrofit2-all.sh. I think I was looking for something that started with java, but still is hould have found that. I will fix this now and resubmit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants