ZOD

I want the final response of the API to look something like this:
{
  "user": {
      "email": string,
      "name": string,
  },
  "parent": { "email": string, "name": string } | null
}

So the parent can be nullable, I define my schema like this:
export const getUserByIdResponseSchema = z.object({
  user: z.object(userCore),
  parent: z.object(userCore).nullable(),
});

When the parent is null, it gets returned null like normal, but when there is actually a parent, this is the fastify error I'm getting. Any idea on how to fix this?
image.png
Was this page helpful?