Skip to content

Allow runtimeValidation with custom mutators by passing Zod schema #2858

@Inv1x

Description

@Inv1x

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.

Metadata

Metadata

Assignees

Labels

fetchFetch client related issueworkaroundA workaround has been providedzodZod related issue

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions