Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/templates/client.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
4 changes: 4 additions & 0 deletions src/templates/core/OpenAPI.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export type OpenAPIConfig = {
PASSWORD?: string | Resolver<string> | undefined;
HEADERS?: Headers | Resolver<Headers> | 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 = {
Expand All @@ -27,4 +29,6 @@ export const OpenAPI: OpenAPIConfig = {
PASSWORD: undefined,
HEADERS: undefined,
ENCODE_PATH: undefined,
NEXT: undefined,
CACHE: undefined,
};
6 changes: 5 additions & 1 deletion src/templates/core/fetch/request.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,13 @@ export const request = <T>(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);

Expand Down
6 changes: 5 additions & 1 deletion src/templates/core/fetch/sendRequest.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Response> => {
const controller = new AbortController();

Expand All @@ -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) {
Expand Down