OpenAPITools / OpenAPITools/openapi-generator

[REQ] [JAVA] Java Client Specify Bearer in each call

Open
#9,792 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

The Problem

I am writing a Java app that will use a generated Java Client. I'd like to use the pooled connection, but I need to specify a different Bearer token in each request.

Proposed Solution

Pass in a Map<String, String> of headers to to api method calls. This one is nice bc it is more general than just doing this for Authentication implementations. To keep things simple, any headers declared here will override any other headers that the code might add up and down the stack -- this makes it easy to reason about how the method will behave.

Alternatives Considered

To support this feature, the outer method must accept headers, either with a new parameter or piggy-backing an existing parameter. (changing client instance itself is not threadsafe). The other method sig I considered:

  • An additional method signature for each client call that takes an Authentication, which, when set, will take precedence over the one defined on the instance. public List<String> myMethod(MyMethodRequest myMethodRequest, Authentication auth) throws ApiException. This was fine choice, but specific to Auth, and opens the door to a bad pattern each time someone wants to override headers. It also is a very large git diff, making it riskier.
    Piggy-backing on existing param is a nonstarter since we aren't guaranteed the call will take any parameters

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

No files or tests are named. Start by tracing the generated Java client API method signatures and request-header handling; determine how per-call headers can override instance headers without changing the client. Done means generated calls accept a Map<String, String> of headers and a Bearer token can differ safely between requests, with coverage for the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.