Open
Description
Description
v0.9.3, 0.9.x
Need a way to disable certification validation via a client option, as the fetch function needs to be replaced in order to make setGlobalDispatcher work, and the fetch signature used by openapi differs, passing a single request object.
Proposal
line 39 src/index.js
let {
baseUrl = "",
dispatcher = undefined,
fetch: baseFetch = globalThis.fetch,
[...]
then check in line 94 in src/index.js for a dispatcher object in the client options and pass it through if present, e.g.
let response = await fetch(request, dispatcher ? { dispatcher } : undefined);
Checklist
- I’m willing to open a PR for this (see CONTRIBUTING.md)
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
No status
Milestone
Relationships
Development
No branches or pull requests
Activity
[-]Send init parameter(s) into fetch requests which is currently unused (= undefined)[/-][+]Allow client option for custom dispatcher into fetch requests (e.g. to disable certificate validation)[/+]Allow client option for custom dispatcher into fetch requests (e.g. t…
Allow client option for custom dispatcher into fetch requests (e.g. t…
Allow client option for custom dispatcher into fetch requests (e.g. t…
drwpow commentedon May 16, 2024
Thanks for opening, but can you describe what a “dispatcher” is? Is this a concept from another library? Why won’t the custom
fetch
or middleware work? What prior art are you referencing?I’m not opposed to adding this, but I want to be 100% sure before we commit to adding breaking changes to the API there’s not a simpler solution to solve the problem (and I do not understand the problem)
mellster2012 commentedon May 16, 2024
Thanks for the comments!
Allow client option for custom dispatcher into fetch requests (e.g. t…
Allow client option for custom dispatcher into fetch requests (e.g. t…
mellster2012 commentedon May 16, 2024
There actually seems to be an option to modify the globalFetch Dispatcher:
globalThis[Symbol.for('undici.globalDispatcher.1')] = yourDispatcher;
Will verify this. You can just reject the reworked (according to your comments) PR at (#1636) if you think it's not useful enough, but the above is certainly a bit of a hack and I would prefer the option to inject a dispatcher per client.
mellster2012 commentedon May 17, 2024
The above doesn't work, neither does setGlobalDispatcher, so we will still rely on our fork in the meantime. Note that you can also pass a dispatcher as init parameter to fetch, however openapi-fetch does discard this additional parameter here:
let response = await fetch(request);
withwhere init can take a dispatcher object.
mellster2012 commentedon May 17, 2024
Specifying a custom fetch is tricky as the globalFetch does not use undici's exposed fetch method, so you have to do what node does and require the internal dependencies which necessitates the --expose-internals flag (or write it from scratch):
mellster2012 commentedon May 17, 2024
Ok so this does work, still not really clean, but using this override plus ts-expect-error providing a custom fetch is sufficient.
Feel free to close this and the related PR at (#1636), or modify the proposed changes as you see fit. Thanks!
aq1018 commentedon Jun 11, 2024
Building on top of @mellster2012 's solution with better typing:
P.S. I got the
dispatcher does not exist in type RequestInit
error as well. Turns out, this is due to howRequestInit
is defined in@types/node
:I was able to fix it by changing the
tsconfig.json
file by changing thetarget
andlib
to"ES6"
:Apparently, by using
ES6
, thedom.d.ts
definitions are not included, thus, makingonmessage: any
not defined.Allow client option for custom dispatcher into fetch requests (e.g. t…
github-actions commentedon Sep 10, 2024
This issue is stale because it has been open for 90 days with no activity. If there is no activity in the next 7 days, the issue will be closed.