zod_gen_derive 1.3.0

Derive macro for zod_gen - automatically generate Zod schemas from Rust types with serde rename support
Documentation

zod_gen_derive

Crates.io Documentation

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 zod_gen::ZodSchema;
use zod_gen_derive::ZodSchema;

#[derive(ZodSchema)]
struct User {
    id: u64,
    name: String,
    is_admin: bool,
}

#[derive(ZodSchema)]
enum Status {
    Active,
    Inactive,
}

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.