-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Documentation for ZodCodeGenerator #335
Comments
I'm afraid it's very intentional, in fact all that functionality was just removed in the newest version of Zod 3. It was something I was playing around with, but I don't think it makes sense for that to be in the core library. That said, if you (or anyone else reading this) wanted to split that out into a separate utility, I'd be happy to link to it in the readme. You can use my old implementation as a starting point (though it'll need some refactoring to work with the newest Zod 3 version, which eliminated the |
This seems like something I would need...maybe? I am looking for a way to iterate over a Zod schema. To be precise: What would be the best way to approach this? |
Zod now exports a type called export type ZodFirstPartySchemaTypes =
| ZodString
| ZodNumber
| ZodBigInt
| ZodBoolean
| ZodDate
| ZodUndefined
| ZodNull
| ZodAny
| ZodUnknown
| ZodNever
| ZodVoid
| ZodArray<any>
| ZodObject<any>
| ZodUnion<any>
| ZodIntersection<any, any>
| ZodTuple
| ZodRecord
| ZodMap
| ZodSet
| ZodFunction<any, any>
| ZodLazy<any>
| ZodLiteral<any>
| ZodEnum<any>
| ZodEffects<any>
| ZodNativeEnum<any>
| ZodOptional<any>
| ZodNullable<any>
| ZodPromise<any>; If you have an generic instance of ZodType, just cast it to const codegen = (_schema: z.ZodTypeAny)=>{
const schema: ZodFirstPartySchemaTypes = _schema as any;
if (schema instanceof ZodString) {
schema._def.isEmail;
}else if(schema instanceof ZodNumber){
// etc
}
} TypeScript is smart enough to properly type |
Thank you very much for your insights :) |
I'm working on an RPC library for personal use, where I'm currently relying on io-ts. I just found out about Zod's much more convenient way to work with optional parameters and would love to switch, but I'm dependent on being able to generate valid client code. Here's an example to describe the use case: https://github.com/farcry-ts/farcry#example |
I recently discovered the ZodCodeGenerator while browsing the source, and after discovering how to use it with some trial and error am keen to make use of it for some code generation within a project I'm on. However, I noticed there was no documentation for it and don't wish to rely on a feature which may not be considered part of the libraries stable API.
Is the lack of documentation intentional or accidental?
The text was updated successfully, but these errors were encountered: