Skip to content

Commit

Permalink
add fetcherOption to enable responseValidator
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardos77 committed Apr 14, 2024
1 parent 4d6ddcc commit 2f33022
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions plugins/typescript/src/templates/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export const getContext = (prefix: string, componentsFile: string) =>
* Query params to inject in the fetcher
*/
queryParams?: {};
/**
* Enable response validation
*/
responseValidatorEnabled?: boolean
};
queryOptions: {
/**
Expand Down
3 changes: 2 additions & 1 deletion plugins/typescript/src/templates/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export async function ${camel(prefix)}Fetch<
queryParams,
signal,
responseValidator,
responseValidatorEnabled,
}: ${pascal(prefix)}FetcherOptions<
TBody,
THeaders,
Expand Down Expand Up @@ -118,7 +119,7 @@ export async function ${camel(prefix)}Fetch<
if (response.headers.get('content-type')?.includes('json')) {
const json = await response.json();
if (responseValidator) {
if (responseValidator && responseValidatorEnabled) {
return responseValidator(json);
} else {
return json;
Expand Down

0 comments on commit 2f33022

Please sign in to comment.