Skip to content

Schema reference ​

Start with a factory, then add checks and compose it into larger shapes. Import these APIs from package:acanthis/acanthis.dart. Top-level factories are also available through the Acanthis facade.

dart
final email = string().trim().email();
final account = object({'email': email, 'tags': string().list()});

Types ​

SchemaParsed outputReference
string()StringStrings
number(), integer(), doubleType()num, int, doubleNumbers
boolean()boolBooleans
date()DateTimeDates
object({...})Map<String, Object?>Objects
record(keys, values)Map<K, V>Records
list(element) or element.list()List<T>Lists
tuple([...])Heterogeneous listTuples
schema.nullable()T?Nullable values
literal(value)The declared literal typeLiterals
union<T>([...])TUnions
variant<T>(guard: ..., schema: ...)TGuarded branches
template([...])StringTemplates
lazy((parent) => ...)The bound child outputRecursive objects
instance<T>()Existing TInstances
classSchema<I, T>()...build()Constructed TClasses

Objects do not infer Dart classes from field names. The child schemas define parsed values; class schemas provide explicit mapping into domain types.

Composition ​

dart
final name = string().min(2);
final shortName = name.max(12);
final names = name.list();
final nullableName = name.nullable();
final nameOrId = name.or<Object?>([integer()]);
final nameAndAge = name.and([integer()]);

Native fluent methods return new schemas. A check or transform added to shortName does not modify name. Modifier order matters: .nullable().list() permits null elements; .list().nullable() permits a null list.

Operations ​

TaskAPI and guide
Parse input or check validityparse, tryParse, validate
Change optional fields, defaults, or PATCH behaviorPresence and defaults
Add a predicate or several issuesCustom validation
Change values or output typesTransforms, coercion, and pipes
Compare parsed object fieldsCross-field rules
Revalidate incremental editsLive validation
Attach descriptionsMetadata
Share schemas through typed keysRegistries
Generate validated samplesMock data
Export or import a JSON contractJSON Schema and OpenAPI

Custom schemas ​

Extend Schema<Input, Output> when defining a new schema implementation. Implement raw-value parse(Object?) and outcome-returning tryParse(Object?). Capabilities such as checks, defaults, lists, and nullability are opt-in mixins. The factory alias AcanthisType is not a generic schema base.

See the repository's docs/v2/ reference notes for implementation contracts. Most application schemas can be built from native types and pipes.

Built by Avesbox · Made for Dart & Flutter