#Zod schema

1 messages · Page 1 of 1 (latest)

prime tusk
#

descriptions: z.array(
z
.object({
type: z.string(),
service: z.string(),
richText: z.string(),
})
),
I have an array of objects in zod schema, I want to make service required when type === "service" and I want to make richText required when type === "richText", how can I do that

fallen briarBOT
#

Hi @prime tusk. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Hmm, I don't know enough to give you a confident answer yet. The knowledge sources provided do not contain specific information on how to conditionally require fields in a Zod schema based on the value of another field in the same object.

However, Zod is a powerful schema validation library and it might support this kind of conditional validation. I would recommend checking the Zod documentation (https://zod.dev/) or relevant resources for more information.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: