Skip to content

Commit

Permalink
(fix) add response headers in fetch client
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Nov 9, 2024
1 parent c1851f1 commit e40b326
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/fetch/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,15 @@ ${
}\n`;

const responseTypeName = fetchResponseTypeName(
override.fetch.includeHttpStatusReturnType,
override.fetch.includeHttpResponseReturnType,
response.definition.success,
operationName,
);
const responseTypeImplementation = override.fetch.includeHttpStatusReturnType
const responseTypeImplementation = override.fetch.includeHttpResponseReturnType
? `export type ${responseTypeName} = {
data: ${response.definition.success || 'unknown'};
status: number;
headers?: Headers;
}\n\n`
: '';

Expand Down Expand Up @@ -167,7 +168,7 @@ ${
)
const data = await res.json()
${override.fetch.includeHttpStatusReturnType ? 'return { status: res.status, data }' : `return data as ${responseTypeName}`}
${override.fetch.includeHttpResponseReturnType ? 'return { status: res.status, data, headers?: res.headers }' : `return data as ${responseTypeName}`}
`;
const customFetchResponseImplementation = `return ${mutator?.name}<${retrunType}>(${fetchFnOptions});`;

Expand Down Expand Up @@ -197,11 +198,11 @@ ${
};

export const fetchResponseTypeName = (
includeHttpStatusReturnType: boolean,
includeHttpResponseReturnType: boolean,
definitionSuccessResponse: string,
operationName: string,
) => {
return includeHttpStatusReturnType
return includeHttpResponseReturnType
? `${operationName}Response`
: definitionSuccessResponse;
};
Expand Down

0 comments on commit e40b326

Please sign in to comment.