Skip to content

Commit

Permalink
Allow client option for custom dispatcher into fetch requests (e.g. t…
Browse files Browse the repository at this point in the history
…o disable certificate validation) openapi-ts#1631
  • Loading branch information
mellster2012 committed Apr 27, 2024
1 parent 8c350ab commit a910d0e
Show file tree
Hide file tree
Showing 5 changed files with 4,686 additions and 3,797 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@changesets/cli": "^2.27.1",
"del-cli": "^5.1.0",
"prettier": "^3.2.5",
"typescript": "^5.4.5"
"typescript": "^5.4.5",
"undici": "^6.14.1"
}
}
2 changes: 2 additions & 0 deletions packages/openapi-fetch/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import type {
export interface ClientOptions extends Omit<RequestInit, "headers"> {
/** set the common root URL for all API requests */
baseUrl?: string;
/** custom dispatcher */
dispatcher?: unknown;
/** custom fetch (defaults to globalThis.fetch) */
fetch?: (request: Request) => ReturnType<typeof fetch>;
/** global querySerializer */
Expand Down
3 changes: 2 additions & 1 deletion packages/openapi-fetch/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const PATH_PARAM_RE = /\{[^{}]+\}/g;
export default function createClient(clientOptions) {
let {
baseUrl = "",
dispatcher = undefined,
fetch: baseFetch = globalThis.fetch,
querySerializer: globalQuerySerializer,
bodySerializer: globalBodySerializer,
Expand Down Expand Up @@ -91,7 +92,7 @@ export default function createClient(clientOptions) {
}

// fetch!
let response = await fetch(request);
let response = await fetch(request, dispatcher ? { dispatcher } : undefined);

// middleware (response)
// execute in reverse-array order (first priority gets last transform)
Expand Down
Loading

0 comments on commit a910d0e

Please sign in to comment.