swagger-api / swagger-api/swagger-codegen-generators
Generated ApiClient for Java/RestTemplate is not thread safe
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 299
- Forks
- 439
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
The auto generated ApiClient for Java/RestTemplate is not thread safe because some response info is stored as fields in the ApiClient class - statusCode and responseHeaders
One option is to have something like the "withHttpInfo" pattern in a different branch - https://github.com/swagger-api/swagger-codegen/commit/17155272f14e587e57ba6cf277351eff1786d63c (this is preferred IMO).
Another option might be to store this info on ThreadLocal but than:
- User needs to know the info must be read in the same thread.
- The ThreadLocal needs to be removed. It is unclear when to remove it.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/main/resources/handlebars/Java/libraries/resttemplate/ApiClient.mustache around the statusCode and responseHeaders fields, then review the referenced withHttpInfo pattern in the linked swagger-codegen commit. The change is complete when generated RestTemplate ApiClient calls no longer share response information through ApiClient fields and remain safe for concurrent use.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100