diff --git a/docs/src/pages/guides/fetch-client.md b/docs/src/pages/guides/fetch-client.md index 42fb5f723..4b1c74cda 100644 --- a/docs/src/pages/guides/fetch-client.md +++ b/docs/src/pages/guides/fetch-client.md @@ -97,7 +97,7 @@ export const useListPets = >( #### return original defined return type When using `fetch` as an `httpClient`, by default the `fetch` response type includes http status. -If use `swr` or queries, i will be accessing things like `data.data`, which will be noisy so if you want to return a defined return type instead of an automatically generated return type, set `override.fetch.includeHttpStatusReturnType` value to `false`. +If use `swr` or queries, i will be accessing things like `data.data`, which will be noisy so if you want to return a defined return type instead of an automatically generated return type, set `override.fetch.includeHttpResponseReturnType` value to `false`. ```js module.exports = { @@ -106,7 +106,7 @@ module.exports = { ... override: { fetch: { - includeHttpStatusReturnType: false, + includeHttpResponseReturnType: false, }, }, }, diff --git a/docs/src/pages/reference/configuration/output.md b/docs/src/pages/reference/configuration/output.md index d60eb92dc..8a2b2302b 100644 --- a/docs/src/pages/reference/configuration/output.md +++ b/docs/src/pages/reference/configuration/output.md @@ -683,7 +683,7 @@ module.exports = { ... override: { fetch: { - includeHttpStatusReturnType: false, + includeHttpResponseReturnType: false, }, }, }, @@ -692,7 +692,7 @@ module.exports = { }; ``` -##### includeHttpStatusReturnType +##### includeHttpResponseReturnType Type: `Boolean`. Default: `true` diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 2ba8d9a3a..38fc0aca1 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -500,7 +500,7 @@ export type SwrOptions = { }; export type FetchOptions = { - includeHttpStatusReturnType: boolean; + includeHttpResponseReturnType: boolean; }; export type InputTransformerFn = (spec: OpenAPIObject) => OpenAPIObject; diff --git a/packages/fetch/src/index.ts b/packages/fetch/src/index.ts index da9b09350..e3e5e1400 100644 --- a/packages/fetch/src/index.ts +++ b/packages/fetch/src/index.ts @@ -109,11 +109,12 @@ ${ response.definition.success, operationName, ); - const responseTypeImplementation = override.fetch.includeHttpResponseReturnType + const responseTypeImplementation = override.fetch + .includeHttpResponseReturnType ? `export type ${responseTypeName} = { data: ${response.definition.success || 'unknown'}; status: number; - headers?: Headers; + headers: Headers; }\n\n` : ''; @@ -168,7 +169,7 @@ ${ ) const data = await res.json() - ${override.fetch.includeHttpResponseReturnType ? 'return { status: res.status, data, headers?: res.headers }' : `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});`; diff --git a/packages/orval/src/utils/options.ts b/packages/orval/src/utils/options.ts index e3731e9f3..c2fa9b89d 100644 --- a/packages/orval/src/utils/options.ts +++ b/packages/orval/src/utils/options.ts @@ -304,8 +304,9 @@ export const normalizeOptions = async ( provideIn: outputOptions.override?.angular?.provideIn ?? 'root', }, fetch: { - includeHttpStatusReturnType: - outputOptions.override?.fetch?.includeHttpStatusReturnType ?? true, + includeHttpResponseReturnType: + outputOptions.override?.fetch?.includeHttpResponseReturnType ?? + true, ...(outputOptions.override?.fetch ?? {}), }, useDates: outputOptions.override?.useDates || false, diff --git a/packages/swr/src/client.ts b/packages/swr/src/client.ts index 8dbd4ef77..bc67c527e 100644 --- a/packages/swr/src/client.ts +++ b/packages/swr/src/client.ts @@ -235,13 +235,13 @@ export const getSwrMutationFetcherOptionType = ( export const getSwrMutationFetcherType = ( response: GetterResponse, httpClient: OutputHttpClient, - includeHttpStatusReturnType: boolean, + includeHttpResponseReturnType: boolean, operationName: string, mutator?: GeneratorMutator, ) => { if (httpClient === OutputHttpClient.FETCH) { const responseType = fetchResponseTypeName( - includeHttpStatusReturnType, + includeHttpResponseReturnType, response.definition.success, operationName, ); diff --git a/packages/swr/src/index.ts b/packages/swr/src/index.ts index 43bf6c083..4d9af3a07 100644 --- a/packages/swr/src/index.ts +++ b/packages/swr/src/index.ts @@ -532,7 +532,7 @@ export const ${swrKeyFnName} = (${queryKeyProps}) => [\`${route}\`${ const swrMutationFetcherType = getSwrMutationFetcherType( response, httpClient, - override.fetch.includeHttpStatusReturnType, + override.fetch.includeHttpResponseReturnType, operationName, mutator, );