@automatons/typescript-zod
v1.0.10
Published
[](https://github.com/openapi-automatons/typescript-zod/actions/workflows/ci-cd.yml) [.
Generated schemas
Each model becomes a XxxSchema plus an inferred type Xxx. The most natural place to use them
is the boundary where untrusted data enters your app — i.e. the request body you are about to
send (form input), validated at mutation time:
import { NewPetSchema, type NewPet } from "./models";
// validate user/form input before sending it
const body: NewPet = NewPetSchema.parse(formValues); // or .safeParse for non-throwing
await api.createPet(body);It drops straight into react-hook-form…
const form = useForm<NewPet>({ resolver: zodResolver(NewPetSchema) });…and pairs with the generated mutation from
@automatons/typescript-client-react-query:
const { mutate } = useCreatePet();
const onSubmit = (values: unknown) => mutate([NewPetSchema.parse(values)]);The same schemas can also be used defensively on responses to catch backend / contract drift (optional — the generated client already types responses from the spec):
const pet = PetSchema.parse(await response.json());How can I use @automatons/typescript-zod?
This library is designed to be used by openapi-automatons. Please read the readme of openapi-automatons for how to use it.
