Under heavy development
StitchAPI
GuidesValidation & drift

Standard Schema

Bring any Standard Schema validator — Zod, Valibot, ArkType — for validation and inferred types.

Reach for this when you already have a schema and want a stitch to validate against it — StitchAPI is validator-agnostic, so any Standard Schema validator (Zod, Valibot, ArkType), a plain predicate, or a Validator works, adapted by the single toValidator() helper.

Example

import { ,  } from 'stitchapi';
import {  } from 'zod';

const  = .({ : .(), : .() });

const  = <{ : number; : string }>({
    : 'https://api.example.com',
    : '/users/{id}',
    : (),
});

The output schema runs against each response; pairing it with the stitch<{ id: number; name: string }> generic types the validated result.

Options

A config's input and output fields are typed as Validator, so a raw z.object(...) is not directly assignable — wrap it with toValidator(). That helper is the single adapter: it coerces Zod (safeParse), any Standard Schema (~standard), or a plain predicate into the Validator the config expects.

Valibot and ArkType need no special handling — they implement Standard Schema, so they go through the same toValidator() call identically. Pass an already-built Validator straight through.

Pair toValidator() with the stitch<T>() generic so the typed result and the runtime check come from one source.

See also

On this page