Skip to content

Commit

Permalink
fix: make defaultInit take function as header property
Browse files Browse the repository at this point in the history
  • Loading branch information
mnorlin committed Jul 20, 2023
1 parent 08235d4 commit a12d3ee
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/openapi-typescript/fetch-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function fetchFactory<Paths>(options?: InitParameters) {
}

function buildInit(
defaultInit: RequestInit,
defaultInit: Omit<RequestInit, "headers">,
options: AllFetchOptions,
headers: HeadersInit
): RequestInit {
Expand Down
8 changes: 3 additions & 5 deletions src/openapi-typescript/header-builder.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export function buildHeaders(
resolvedPath: string,
defaultHeaders?:
| RequestInitHeaders
| ((pathInfo: { resolvedPath: string }) => RequestInitHeaders),
headers?: RequestInitHeaders
| HeadersInit
| ((pathInfo: { resolvedPath: string }) => HeadersInit),
headers?: HeadersInit
) {
const resolvedDefaultHeaders =
typeof defaultHeaders === "function"
Expand Down Expand Up @@ -34,5 +34,3 @@ function headerToEntries(

return Object.entries(headers);
}

type RequestInitHeaders = Headers | [string, string][] | Record<string, string>;
6 changes: 5 additions & 1 deletion src/types/common.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
export type InitParameters = {
baseUrl?: string;
defaultInit?: Omit<RequestInit, "method">;
defaultInit?: Omit<RequestInit, "method" | "headers"> & {
headers:
| HeadersInit
| ((pathInfo: { resolvedPath: string }) => HeadersInit);
};
fetchMethod?: typeof fetch;
parameterSerialization?: {
path?: { explode?: boolean; style?: PathSerializationStyle };
Expand Down

0 comments on commit a12d3ee

Please sign in to comment.