-
-
Notifications
You must be signed in to change notification settings - Fork 529
Allow client option for custom dispatcher into fetch requests (e.g. to disable certificate validation) #1631
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
Comments
…o disable certificate validation) openapi-ts#1631
…o disable certificate validation) openapi-ts#1631
…o disable certificate validation) openapi-ts#1631
Thanks for opening, but can you describe what a “dispatcher” is? Is this a concept from another library? Why won’t the custom 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) |
Thanks for the comments!
|
…o disable certificate validation) openapi-ts#1631
…o disable certificate validation) openapi-ts#1631 rebase from upstream/main
There actually seems to be an option to modify the globalFetch Dispatcher: |
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:
where init can take a dispatcher object. |
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):
|
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! |
Building on top of @mellster2012 's solution with better typing: const fetchWithProxy: typeof globalThis.fetch = (input, init) =>
globalThis.fetch(input, {
...init,
dispatcher,
})
const client = createClient<paths>({
baseUrl: 'https://some.openapi-domain.com',
fetch: fetchWithProxy,
}) P.S. I got the // in globals.d.ts file in @types/node:
// Conditional type aliases, used at the end of this file.
// Will either be empty if lib-dom is included, or the undici version otherwise.
type _RequestInit = typeof globalThis extends { onmessage: any } ? {}
: import("undici-types").RequestInit; I was able to fix it by changing the {
"compilerOptions": {
"target": "ES6",
"lib": ["ES6"],
// ... rest of the configs here
}
} Apparently, by using |
…o disable certificate validation) openapi-ts#1631
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. |
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
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
The text was updated successfully, but these errors were encountered: