OpenAPITools / OpenAPITools/openapi-generator
[REQ][javascript] Ability to intercept requests and dynamically compute an authorization header value
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Hi,
Is your feature request related to a problem? Please describe.
I generated a client library using openapi-generator-cli and the following command:
java -jar openapi-generator-cli.jar generate -i *.yaml -g javascript -o out
I'm now searching for a way to inject an OAuth header computed from the request without changing the generated code.
Describe the solution you'd like
The ability to pass superagent request interceptors or "authenticators" to the ApiClient instance.
Describe alternatives you've considered
I tried the following:
- Override
applyAuthToRequestto set the header
client.applyAuthToRequest = function(request) {
const auth = computeAuthorization(request);
request.set({'Authorization': auth });
};
But applyAuthToRequest is called too early, when the request object is not entirely filled.
- Override
applyAuthToRequestto add a listener to requests
client.applyAuthToRequest = function(request) {
request.addListener("end", function() {
// ...
});
};
But the end event seems to be the only event we can listen to, and it happens to late.
- Pass a custom
requestAgentto theApiClient
const apiClient = require('../../ApiClient.js');
const requestAgent = new require("https").Agent({ /* Options */});
const client = apiClient.instance;
client.requestAgent = requestAgent;
(...)
In that case the custom agent is used, but I haven't find any way of adding interceptors or listening to requests.
Any help would be appreciated.
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 the generated JavaScript ApiClient.js and its applyAuthToRequest entry point, then review how openapi-generator-cli creates the client and how the request object is assembled. The requested behavior is a supported interceptor or authenticator that can compute an authorization header after the request is fully prepared; validate it with a generated JavaScript client.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, javascript
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100