zod_gen_derive
Derive macro for zod_gen - automatically generate Zod schemas from Rust types.
Features
#[derive(ZodSchema)]procedural macro- Supports structs with named fields
- Supports Serde enum representations (externally tagged, internally tagged, adjacently tagged, untagged) and generates appropriate unions/discriminated unions
- Automatic dependency resolution
Usage
use ZodSchema;
use ZodSchema;
Serde enum representations
- Externally tagged (default) →
z.union([ ... ]) - Internally tagged (
#[serde(tag = "...")]) →z.discriminatedUnion(...) - Adjacently tagged (
#[serde(tag = "...", content = "...")]) →z.discriminatedUnion(...) - Untagged (
#[serde(untagged)]) →z.union([ ... ])
Internally tagged enums do not allow tuple variants, and internally tagged newtype variants must wrap object-like payloads.
For more examples and documentation, see the main repository.