-
-
Notifications
You must be signed in to change notification settings - Fork 553
Open
Labels
fetchFetch client related issueFetch client related issueworkaroundA workaround has been providedA workaround has been providedzodZod related issueZod related issue
Description
Description
When using a custom mutator, runtimeValidation is completely bypassed (Code source).
Current behavior
override.fetch.runtimeValidation is ignored when custom mutator is passed
Proposed behavior
override.fetch.runtimeValidation is used and can be passed to custom mutator
Proposed solution
Pass the Zod schema as an additional parameter to the custom mutator:
// Current mutator signature
export const httpClient = async <T>(url: string, options?: RequestInit): Promise<T>
// Proposed: add optional schema parameter
export const httpClient = async <T>(
url: string,
options?: RequestInit,
schema?: ZodSchema<T>
): Promise<T> => {
const response = await fetch(...)
const data = await response.json()
return schema ? schema.parse(data) : data
}This would allow users who need custom auth/headers/error handling to still benefit from runtime validation.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
fetchFetch client related issueFetch client related issueworkaroundA workaround has been providedA workaround has been providedzodZod related issueZod related issue