Swagger Codegen CLI Java Client one access token per instance, not thread safe

Viewed 216

I have openapi 3.0 specification. Generated code by:

java -jar /usr/bin/swagger-codegen-cli-v3.jar generate -l java -i openapi_shop.yaml -o apishop -DhideGenerationTimestamp=true -c config_shop.json

If in 1 service now I want to call that api I need to do:

String accessToken = getUserAccessToken();
api.getApiClient().setAccessToken(accessToken);
Products response = api.productsGet();

but as you see what if 50 users concurrently will start to ping that api ? it will end up mixing access tokens there. What is the correct way to use that auto generated client ? What I see there are 2 options:

  1. modify existing auto generated code and take token as a param in every method, and simply put it in headers at the end, like json body

  2. create new instance every time, for every user's request ( which does not sounds good )

Maybe I miss something ? thanks!

0 Answers
Related