Per-request auth / headers / request options
See original GitHub issueDescribe the solution you’d like In server side rendering environments it is common that a single process may need to make requests on behalf of several users, each with their own set of credentials. It seems like this is doable with something like:
import { MyService, OpenAPI } from 'MyService'
OpenAPI.TOKEN = () => { OpenAPI.TOKEN = undefined; return 'abc123' }
MyService.someOperation({})
The issue is that the TOKEN
needs to be set before each call in a bit of a clunky way, and if there the is anything async that happens between setting it and the request actually being sent off it’s possible for one request to incorrectly be made with credentials intended for another. Ideally I’d like to be able to pass credentials as a final argument any operation (this works better with the “useOptions” style). I’d also be OK with passing some kind of extension of ApiRequestOptions
so that resolvers could work on a per-req basis, e.g.:
import { MyService, OpenAPI } from 'MyService'
OpenAPI.TOKEN = (opts) => opts.myCustomAuth
MyService.someOperation({}, { myCustomAuth: 'abc123' )
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:6 (2 by maintainers)
Top GitHub Comments
@Lanny I see, it makes sense
But I still think that global parameters are evil =) What I see is that two parts of the generated code might be split:
core
models/services
in this case,
core
part might have aclient
which can be instantiated in order to have own token/url/etc. Andmodels/services
can accept theclient
as an argument and be just functions.But the main problem I see is that these changes require a lot of effort, bring significant changes into library api and probably conflict with other functionality I don’t know about… =)
These tickets are all related to the same “global” objects: https://github.com/ferdikoomen/openapi-typescript-codegen/issues/859 https://github.com/ferdikoomen/openapi-typescript-codegen/issues/703 https://github.com/ferdikoomen/openapi-typescript-codegen/issues/588
Closing them and keeping the original ticket: https://github.com/ferdikoomen/openapi-typescript-codegen/issues/428
I definitely see the use case, there is also already a PR for this: PR: https://github.com/ferdikoomen/openapi-typescript-codegen/pull/822