Import
What they do
Schema adapters wrap external validation libraries into aSchemaAdapter<T> interface so you can pass them to ApiClient’s validateResponse option. The client calls adapter.parse(data) after every successful response — if parsing fails, the error propagates immediately.
SchemaAdapter<T>
zodAdapter and valibotAdapter are convenience wrappers for the two most popular schema libraries.
zodAdapter
parse method, you can also pass a Zod schema directly — the adapter simply adds type safety.
Zod example
valibotAdapter
parse function. Unlike Zod, Valibot separates the schema definition from the parse function, so both must be provided.
Valibot example
Type guard
isSchemaAdapter(obj) returns true if the object has a parse function — useful when you accept both ValidationSchema and SchemaAdapter in generic code.
Comparison
When to use zodAdapter
When to use zodAdapter
- You already use Zod in your project
- You want
.parse()+.safeParse()error messages - You need transforms (
.transform(),.default(),.refine())
When to use valibotAdapter
When to use valibotAdapter
- You prefer Valibot’s tree-shakeable, functional API
- You want a smaller bundle footprint for validation
When to use ResponseValidator instead
When to use ResponseValidator instead
- You want zero external dependencies
- You only need structural type checks and simple constraints
- See ResponseValidator
Schema adapters are optional. If you don’t pass
validateResponse, ApiClient returns the raw parsed JSON without validation.