Skip to main content

Code generation

Due to Dart’s limitations with reflection, and the Dart team halting development on macros, code generation remains the most practical approach to metaprogramming in Dart.

Many major Dart packages—such as riverpod, freezed, and drift—heavily rely on code generation to simplify and automate boilerplate.

Why code generation?

While ZodArt works perfectly without code generation, using it is highly recommended:

  • 🛠️ Automatically generates a type-safe ZObject mapper — no more magic strings
  • 🧩 Handles nested schemas and arrays automatically
  • 🏗️ Automatically generates schema output classes if needed
  • 🔄 Supports mapping to existing Freezed or custom classes
  • 🔍 Exposes type-safe property access to simplify field-specific issue handling
  • ✨ Significantly reduces boilerplate and improves developer experience

🔗 See a full example with code generation
🔗 Or view an example without code generation