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

Drizzle Zod + lazy #255

Closed
samducker opened this issue Sep 8, 2024 · 2 comments
Closed

Drizzle Zod + lazy #255

samducker opened this issue Sep 8, 2024 · 2 comments

Comments

@samducker
Copy link

Hi in all of my schemas created with 'drizzle-zod'

They cause this library to throw this error

{
"message": "Unknown zod object type, please specify `type` and other OpenAPI props using `ZodSchema.openapi`.",
"data": {
"currentSchema": {
"typeName": "ZodLazy"
}
}
}

I have searched the issues here and not found a workaround for this apart from not using drizzle zod, which is not ideal

as the benefit of using it is that my database schema stays as the source of truth for my route definition schemas.

Do you have any workarounds or advice to overcome this issue?

@AGalabov
Copy link
Collaborator

AGalabov commented Sep 13, 2024

@samducker sadly we do not support z.lazy as of right now and this has been the case for a while. #191.

The main workaround would be to use the .openapi method and provide some manual documentation on your schema (assuming this is a one off scenario).

For example:

type Category = {
  name: string;
  subcategories: Category[];
};

const categorySchema: z.ZodType<Category> = z
  .object({
    name: z.string(),
    subcategories: z
      .lazy(() => categorySchema.array())
      .openapi({
        type: 'array',
        items: {
          $ref: '#/components/Category',
        },
      }),
  })
  .openapi('Category');

We are open to the idea of making it work. However time is scarce and I cannot give an estimate as to when we would be able to include such feature considering it would take some overhaul of our codebase

@AGalabov AGalabov mentioned this issue Sep 13, 2024
@AGalabov
Copy link
Collaborator

AGalabov commented Oct 4, 2024

@samducker I will close this task since it is a duplicate with #247 and has more tracking

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