zodart 1.1.0

SDKdartflutter
Platformandroidioswindowslinuxmacosweb

Type-safe schema validation with static type inference and a parse-first design.

Internal README

Code generation

Build runner build

  • ZodArt internally uses Freezed package to avoid boilerplate and improve DX.
  • ZodArt generator is exposed to package users and to generate internal examples.

Files generated by Freezed are not explicitly required by the ZodArt generator, but the codebase depends on them, so they must be built before the ZodArt generator runs.

This causes problems because ZodArt generator is defined in build.yaml for exposure to end users and there's currently no supported way to force build_runner to run builders in a defined order.

To avoid this problem *.freezed.dart should be treated as 'normal files':

  1. Comment out the build.yaml file
  2. Build freezed files: dart run build_runner build --delete-conflicting-outputs
  3. Remove .dart_tool folder
  4. Run dart pub get
  5. Uncomment build.yaml file
  6. Generate *.zodart.dart files: dart run build_runner watch --delete-conflicting-outputs

Source generator testing

ZodArt uses source_gen package to generate code for annotated classes and to test the generated code source_gen_test package is used.

This package uses golden code files to test the generated code. These files are saved at test/src/code_generation/goldens/.

To regenerate a golden file run: SOURCE_GEN_TEST_UPDATE_GOLDENS=1 dart test <PATH_TO_THE_TEST_FILE>.dart

E.g. SOURCE_GEN_TEST_UPDATE_GOLDENS=1 dart test test/src/code_generation/full_schema_test.dart