-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
[Java][native] Add ability to add header to specific calls #21495
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
Conversation
Can you please take a look? @bbdouglas @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger @karismann @Zomzog @lwlee2608 @martin-mfg |
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. |
This is an interesting approach, but in our case the token is almost always unique. For example a BFF API takes a user token of our customers and fans-out requests to downstream services. One of these downstream APIs needs this token passed on to them to do a secure operation. So basically the token is fairly unique across requests. |
@wing328 Thanks for the headsup. I think I fixed the emails now and regenerated the samples. Can you please help target the correct release branch? |
@wing328 @chameleon82 @Mattias-Sehlstedt I've made the solution more flexible, so that devs can add any needed header per request. Can you please review? |
@bgong-mdsol @jo1gi Can you please review as well? |
PR is ready for review 🚀 🚀 |
.../client/petstore/java/native-async/src/main/java/org/openapitools/client/api/DefaultApi.java
Show resolved
Hide resolved
Hi @martin-mfg @wing328 @welandaz @marcel-huber-ptv Can you please review this PR? |
modules/openapi-generator/src/main/resources/Java/libraries/native/api.mustache
Show resolved
Hide resolved
modules/openapi-generator/src/main/resources/Java/libraries/native/api.mustache
Show resolved
Hide resolved
modules/openapi-generator/src/main/resources/Java/libraries/native/api.mustache
Outdated
Show resolved
Hide resolved
@wing328 Updated as per suggestions ✅ |
@wing328 Do you think we can squeeze this one for next release? My team will need this change in a couple of weeks. |
yes, i think so if no further feedback, i'll merge it over the weekend thanks for the contribution |
Hi @inemtsev , It is still not clear for me why is not viable the use of the Supplier. It is called before each request to supply the bearer token and it is up to your supplier to provide unique/specific one for each request. Could you please elaborate? |
The token in this case is tied to the parameters being sent in the request (it's a multiuser environment), so it makes sense for it to be passed (as a parameter/header instead of a Supplier). Also, this change opens up the possibility of settings various other headers on-demand also |
It makes sense. Generally speaking you need a context to supply the token. The best practice in the industry is to store the context in a thread local variable. |
The need for this change is that we need to be able to set the bearer Token per request (for Java native library option), we would like to reuse ApiClient (because recreating it is expensive), but bearer token needs to change. We can achieve this by attaching a specific headers for specific requests, and reusing the same ApiClient.
For example:
Related issue: #21487
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master
(upcoming7.x.0
minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)