Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Resttemplate thread safe by using the withHttpInfo pattern #4049

Conversation

thomasJoei
Copy link
Contributor

…by many other generated clients

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\. If contributing template-only or documentation-only changes which will change sample output, be sure to build the project first.
  • Filed the PR against the correct branch: master, 4.1.x, 5.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

This PR is just a copy of the one I just merged in the old swagger-api/swagger-codegen repo
swagger-api/swagger-codegen#9737

This PR is to make the generated RestTemplate client thread safe. Currently, we don't have any way of retrieving the response headers except by using getResponseHeaders() method which returns the latest response headers, in the case multiple threads use the ApiClient we might end up getting the headers of the response sent to another thread.

This PR purpose is to add an additional method which not only return the expected DTO but also the ResponseEntity wrapping it, so user can easily retrieve headers by inspecting the ResponseEntity. The usual methods to directly get the DTO are conserved.

This change breaks backward compatibility since (thread unsafe) attributes, statusCode and responseHeaders, are removed from ApiClient class.

Java technical committee:
@bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04)

@wing328
Copy link
Member

wing328 commented Oct 7, 2019

Thanks for the PR but your commit (as shown in the Commits tab) is not linked to your Github account, which means this PR won't count as your contribution in https://github.com/OpenAPITools/openapi-generator/graphs/contributors.

Let me know if you need help fixing it.

Ref: https://github.com/OpenAPITools/openapi-generator/wiki/FAQ#how-can-i-update-commits-that-are-not-linked-to-my-github-account

@wing328
Copy link
Member

wing328 commented Oct 7, 2019

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	modified:   samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/ApiClient.java
	modified:   samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/api/AnotherFakeApi.java
	modified:   samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/api/FakeApi.java
	modified:   samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/api/FakeClassnameTags123Api.java
	modified:   samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/api/PetApi.java
	modified:   samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/api/StoreApi.java
	modified:   samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/api/UserApi.java

Please also run ./bin/java-petstore-resttemplate-withxml.sh to update the Pestore sample

@thomasJoei thomasJoei force-pushed the feature/resttemplate-client-return-headers branch 2 times, most recently from b7f2b86 to d3400d1 Compare October 7, 2019 13:25
@thomasJoei thomasJoei force-pushed the feature/resttemplate-client-return-headers branch from d3400d1 to 807868f Compare October 7, 2019 13:29
@thomasJoei
Copy link
Contributor Author

Thanks @wing328, didn't realize my professional email was linked into my commits instead of my Github related email.
I updated resttemplate-withxml samples, re-ran the tests and updated my commit to include the changes.

@wing328
Copy link
Member

wing328 commented Oct 10, 2019

@thomasJoei thanks for the PR, which looks good to me

The Travis CI failure has been fixed in the master.

@wing328 wing328 merged commit a13543e into OpenAPITools:master Oct 10, 2019
@thomasJoei
Copy link
Contributor Author

Thanks @wing328 !

jimschubert added a commit that referenced this pull request Oct 14, 2019
* master: (78 commits)
  Replaced dashes with underscores in build.gradle files. (#4092)
  [cxf-cdi] use @FormParam for form parameters when it is not Multipart (#4125)
  Corrections to script names (#4135)
  [python] Add missing keywords python (#4134)
  Update PULL_REQUEST_TEMPLATE.md (#4080)
  revert the fix to broken links
  Rename property name from propertyRawName to propertyBaseName (#4124)
  [Go] Fix go.mod and go.sum for 1.13 (#4084)
  [kotlin] add option for non public api (#4089)
  Added new discriminator RawName property to preserve declared discriminator for @JsonTypeInfo annotations (#3320)
  Fix links to other files (#4120)
  [JAVA][JAXRS] Fix parameters validation (#3862)
  Make Resttemplate thread safe by using the withHttpInfo pattern used by many other generated clients (#4049)
  Disabling linting for typescript-fetch (#4110)
  [Kotlin][Client] fix missing curly bracket when the model contains enum property (#4118)
  Fix NPE in Elm path parameter (#4116)
  test aiohttp first (#4117)
  add back ruby client folders
  update petstore samples
  [CLI] Initial implementation for batch generation (#3789)
  ...
@wing328 wing328 changed the title Make Resttemplate thread safe by using the withHttpInfo pattern used … Make Resttemplate thread safe by using the withHttpInfo pattern Oct 30, 2019
@wing328
Copy link
Member

wing328 commented Oct 31, 2019

@thomasJoei thanks for the PR, which has been included in v4.2.0 release: https://twitter.com/oas_generator/status/1189824932345069569

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