swagger-api / swagger-api/swagger-codegen-generators

Generated ApiClient for Java/RestTemplate is not thread safe

Open
#634 1 comment 0 reactions 0 assignees View on GitHub

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

https://github.com/swagger-api/swagger-codegen-generators/blob/master/src/main/resources/handlebars/Java/libraries/resttemplate/ApiClient.mustache#L95

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:

  1. User needs to know the info must be read in the same thread.
  2. The ThreadLocal needs to be removed. It is unclear when to remove it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.