Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose zod schema for parsing errors #3417

Open
marceloverdijk opened this issue Apr 18, 2024 · 1 comment
Open

expose zod schema for parsing errors #3417

marceloverdijk opened this issue Apr 18, 2024 · 1 comment

Comments

@marceloverdijk
Copy link

marceloverdijk commented Apr 18, 2024

When using zod it can return various errors when parsing.

I would be nice if the zod library itself would expose a zod schema for these errors (dogfooding).

This could be very useful when e.g. using zod-openapi to use it as error response schema in a 400/422.

import * as z from "zod";

..

    responses: {
      200: {
        description: 'OK',
        content: {
          'application/json': {
            schema: PetSchema,
          },
        },
      },
      400: {
        description: 'Invalid request',
        content: {
          'application/json': {
            schema: z
              .object({
                errors: z.array(z.errorSchema), // <-- what is proposed to be exposed by zod
              }),
          },
        },
      },
@m10rten
Copy link
Contributor

m10rten commented Apr 30, 2024

Maybe a stringed variant of the schema satisfies your needs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants