The code generator for schemantic. It
generates type-safe data classes and runtime-accessible JSON Schemas from
abstract class definitions annotated with @Schema.
This package is a development-time dependency. The runtime API lives in the
schemantic package.
Installation
Add schemantic as a regular dependency, and schemantic_builder plus
build_runner as dev dependencies:
dart pub add schemantic
dart pub add dev:schemantic_builder
dart pub add dev:build_runner
Usage
- Define your schema using the
@Schemaannotation frompackage:schemantic:
import 'package:schemantic/schemantic.dart';
part 'user.g.dart';
@Schema()
abstract class $User {
String get name;
int? get age;
bool get isAdmin;
}
- Run the build runner to generate the implementation:
dart run build_runner build
See the schemantic README for full
documentation on the generated APIs.