From d8bbc987546dc0eb77e868fa1e47e64f7e553f1c Mon Sep 17 00:00:00 2001 From: Batyr Jumageldiyew Date: Tue, 26 Aug 2025 14:57:55 +0500 Subject: [PATCH] support next.js config props --- src/templates/client.hbs | 2 ++ src/templates/core/OpenAPI.hbs | 4 ++++ src/templates/core/fetch/request.hbs | 6 +++++- src/templates/core/fetch/sendRequest.hbs | 6 +++++- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/templates/client.hbs b/src/templates/client.hbs index 601f27d8f..0e3919aea 100644 --- a/src/templates/client.hbs +++ b/src/templates/client.hbs @@ -70,6 +70,8 @@ export class {{{clientName}}} { PASSWORD: config?.PASSWORD, HEADERS: config?.HEADERS, ENCODE_PATH: config?.ENCODE_PATH, + NEXT: config?.NEXT, + CACHE: config?.CACHE, }); {{#each services}} diff --git a/src/templates/core/OpenAPI.hbs b/src/templates/core/OpenAPI.hbs index 7b9560a26..f8bf34257 100644 --- a/src/templates/core/OpenAPI.hbs +++ b/src/templates/core/OpenAPI.hbs @@ -15,6 +15,8 @@ export type OpenAPIConfig = { PASSWORD?: string | Resolver | undefined; HEADERS?: Headers | Resolver | undefined; ENCODE_PATH?: ((path: string) => string) | undefined; + NEXT?: NextFetchRequestConfig; + CACHE?: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload"; }; export const OpenAPI: OpenAPIConfig = { @@ -27,4 +29,6 @@ export const OpenAPI: OpenAPIConfig = { PASSWORD: undefined, HEADERS: undefined, ENCODE_PATH: undefined, + NEXT: undefined, + CACHE: undefined, }; diff --git a/src/templates/core/fetch/request.hbs b/src/templates/core/fetch/request.hbs index 4af6f9440..20ec63267 100644 --- a/src/templates/core/fetch/request.hbs +++ b/src/templates/core/fetch/request.hbs @@ -69,9 +69,13 @@ export const request = (config: OpenAPIConfig, options: ApiRequestOptions): C const formData = getFormData(options); const body = getRequestBody(options); const headers = await getHeaders(config, options); + const next = config.NEXT; + const cache = config.CACHE; if (!onCancel.isCancelled) { - const response = await sendRequest(config, options, url, body, formData, headers, onCancel); + const response = await sendRequest( + config, options, url, body, formData, headers, onCancel, next, cache + ); const responseBody = await getResponseBody(response); const responseHeader = getResponseHeader(response, options.responseHeader); diff --git a/src/templates/core/fetch/sendRequest.hbs b/src/templates/core/fetch/sendRequest.hbs index 73f71f428..a4f6ec8f6 100644 --- a/src/templates/core/fetch/sendRequest.hbs +++ b/src/templates/core/fetch/sendRequest.hbs @@ -5,7 +5,9 @@ export const sendRequest = async ( body: any, formData: FormData | undefined, headers: Headers, - onCancel: OnCancel + onCancel: OnCancel, + next: NextFetchRequestConfig | undefined, + cache?: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" ): Promise => { const controller = new AbortController(); @@ -14,6 +16,8 @@ export const sendRequest = async ( body: body ?? formData, method: options.method, signal: controller.signal, + next: next, + cache: cache }; if (config.WITH_CREDENTIALS) {