### Union Schema Parsing Example Source: https://acanthis.serinus.app/defining-schemas.html Demonstrates parsing values against a union schema. The schema accepts values that match any of the types defined in the union. ```dart final union = string().union([ number(), boolean(), ]); union.parse('Acanthis'); // ✅ union.parse(5); // ✅ union.parse(true); // ✅ union.parse([1, 2, 3]); // ❌ throws ValidationError ``` -------------------------------- ### Variadic Tuple Parsing Example Source: https://acanthis.serinus.app/defining-schemas.html Demonstrates parsing data into a variadic tuple schema. The last element of the tuple schema accepts any number of elements of its specified type. ```dart final tuple = string().tuple([ string(), number(), ]).variadic(); tuple.parse([ 'Acanthis', 'Dart', 5, 10, 15, 20, ]); // ✅ ``` -------------------------------- ### Add Acanthis Dependency using Dart CLI Source: https://acanthis.serinus.app/introduction.html Install the Acanthis package using the dart pub add command. This is the recommended way to add dependencies to your project. ```bash dart pub add acanthis ``` -------------------------------- ### Implement Fallback Pattern with Variants Source: https://acanthis.serinus.app/defining-schemas.html Use `variant()` to define a fallback or default case in a `union()`. Place the most specific or expected types first, and the most general or fallback types last. This example handles numeric input as strings or raw numbers. ```dart final numericInput = union([ variant( name: 'numberLike', guard: (v) => v is String && double.tryParse(v) != null, schema: string().pipe(number(), transform: double.parse), ), variant( name: 'rawNumber', guard: (v) => v is num, schema: number(), ), ]); ``` -------------------------------- ### Mix Variants and Plain Types in Union Source: https://acanthis.serinus.app/defining-schemas.html Combine `variant()` with plain schema types within a `union()`. Variants are evaluated first based on their guards, followed by plain types. This example handles string IDs, points, or booleans. ```dart final idOrPointOrBool = union([ variant( name: 'idString', guard: (v) => v is String && v.startsWith('id:'), schema: string().pattern(RegExp(r'^id:\d+$')), ), variant( name: 'point', guard: (v) => v is Map && v.containsKey('x') && v.containsKey('y'), schema: object({ 'x': number().finite(), 'y': number().finite(), }), ), boolean(), // plain type (checked after matching variants) ]); ``` -------------------------------- ### Define Tagged Union with Variants Source: https://acanthis.serinus.app/defining-schemas.html Use `variant()` within `union()` to create discriminated branches. Guards selectively attempt schemas, improving error clarity and performance. This example models 'circle' and 'rectangle' shapes. ```dart final shape = union([ variant( name: 'circle', guard: (v) => v is Map && v['type'] == 'circle', schema: object({ 'type': string().exact('circle'), 'radius': number().positive(), }), ), variant( name: 'rectangle', guard: (v) => v is Map && v['type'] == 'rectangle', schema: object({ 'type': string().exact('rectangle'), 'width': number().positive(), 'height': number().positive(), }), ), ]); shape.parse({'type': 'circle', 'radius': 10}); // ✅ shape.parse({'type': 'rectangle', 'width': 5, 'height': 7}); // ✅ shape.parse({'type': 'triangle'}); // ❌ ValidationError (no variant matched) ``` -------------------------------- ### Customize Acanthis Validator Error Messages Source: https://acanthis.serinus.app/error-customization.html Use the 'message' parameter for static error strings and 'messageBuilder' for dynamic messages based on the check value. This example demonstrates customizing messages for required fields, minimum number values, and email format validation. ```dart import 'package:acanthis/acanthis.dart'; void main() { final schema = AcanthisObject({ 'name': AcanthisString().required(message: 'Name is required'), 'age': AcanthisNumber().min(18, messageBuilder: (value) => 'You must be at least $value years old'), 'email': AcanthisString().email(message: 'Invalid email address'), }); final result = schema.validate({ 'name': '', 'age': 16, 'email': 'invalid-email', }); print(result.errors); // [Name is required, You must be at least 18 years old, Invalid email address] } ``` -------------------------------- ### Add Metadata to Schema Source: https://acanthis.serinus.app/metadata.html Use the `meta` method on a schema object to attach metadata. The `MetadataEntry` class is used to define the metadata, such as a description. ```dart final schema = object({ 'name': string(), 'age': int(), }).meta(MetadataEntry( description: 'This is a schema for a person.', )); ``` -------------------------------- ### Create a Basic Object Schema Source: https://acanthis.serinus.app/defining-schemas.html Use `object()` to create a schema for validating and transforming objects. Properties are required by default. ```dart object({ 'name': string().min(3), 'age': number().positive(), }); ``` -------------------------------- ### Tuple Schema from Type Source: https://acanthis.serinus.app/defining-schemas.html Create a tuple schema by chaining `tuple()` to a base schema type. The first schema in the list defines the type for creating the tuple. ```dart final tuple = string().tuple([ string(), number(), boolean(), ]); // [string(), string(), number(), boolean()] ``` -------------------------------- ### Create Schemas for Template Literals with `template()` Source: https://acanthis.serinus.app/defining-schemas.html Use `template()` to define schemas that match template literal strings containing placeholders. The function accepts a list of schemas corresponding to the placeholders. ```dart enum SizeUnit { px, em, rem } final sizeSchema = template([ number(), string().enumerated(SizeUnit.values), ]); sizeSchema.parse('12px'); // ✅ sizeSchema.parse('5em'); // ✅ sizeSchema.parse('20rem'); // ✅ sizeSchema.parse('15pt'); // ❌ ValidationError ``` -------------------------------- ### Class Schema Definition and Validation Source: https://acanthis.serinus.app/defining-schemas.html Build a typed pipeline using `classSchema` to validate input shape, map to a class, and optionally validate the mapped class instance. Use `validateWith` and `instance()` for post-mapping validation. ```dart class User { final String name; final int age; User(this.name, this.age); } final buildUser = classSchema, User>() .input(object({ 'name': string().min(3), 'age': number().positive(), })) .map((data) => User(data['name'], data['age'])) .validateWith( instance() .field('name', (u) => u.name, string().max(50)) .field('age', (u) => u.age, number().gte(18)), ) .build(); final user = buildUser.parse({ 'name': 'Alice', 'age': 30, }); // ✅ returns User instance ``` -------------------------------- ### Pick Properties from an Object Schema Source: https://acanthis.serinus.app/defining-schemas.html Use `pick()` to create a new schema containing only specified properties from an existing object schema. ```dart final person = object({ 'name': string().min(3), 'age': number().positive(), }); final personWithoutAge = person.pick(['name']); ``` -------------------------------- ### Variadic Tuple Schema Source: https://acanthis.serinus.app/defining-schemas.html Create a variadic tuple schema using the `variadic()` method. This allows for a fixed number of initial elements followed by a variable number of elements of the same type. ```dart final tuple = string().tuple([ string(), number(), ]).variadic(); ``` -------------------------------- ### Defining a schema Source: https://acanthis.serinus.app/basic-usage.html Schemas are blueprints for validating data. Here's how to define a schema for a user object. ```APIDOC ## Defining a schema A schema is a blueprint for validating data, before we do anything else, we need to define one. For this example, we will create a schema for a user object. dart ```dart import 'package:acanthis/acanthis.dart'; final userSchema = object({ 'name': string().min(3), 'age': number().positive(), 'email': string().email(), }); ``` ``` -------------------------------- ### Create List Schemas from Types Source: https://acanthis.serinus.app/defining-schemas.html You can create a list schema directly from a type validator using the `.list()` method. ```dart string().list(); ``` ```dart number().list(); ``` ```dart boolean().list(); ``` -------------------------------- ### Generate Pretty-Printed JSON Schema Source: https://acanthis.serinus.app/json-schema.html Use the `toPrettyJsonSchema()` method to generate a formatted JSON string of the schema, with an optional `indent` parameter for controlling the indentation level. This is useful for human-readable schema output. ```dart final schema = object({ 'name': string(), 'age': number(), }).toPrettyJsonSchema(); ``` -------------------------------- ### Define a User Schema Source: https://acanthis.serinus.app/basic-usage.html Define a schema for a user object with name, age, and email fields. The name must be at least 3 characters long, age must be positive, and email must be a valid email format. ```dart import 'package:acanthis/acanthis.dart'; final userSchema = object({ 'name': string().min(3), 'age': number().positive(), 'email': string().email(), }); ``` -------------------------------- ### Add Acanthis Dependency to pubspec.yaml Source: https://acanthis.serinus.app/introduction.html Alternatively, add Acanthis as a dependency in your pubspec.yaml file. Ensure you are using a compatible version. ```yaml dependencies: acanthis: ^1.2.0 ``` -------------------------------- ### Add Custom Synchronous Validation with refine() Source: https://acanthis.serinus.app/defining-schemas.html Use the `refine()` method to attach a synchronous custom validation function to a schema. The `onCheck` function must return a boolean, and an optional `error` message can be provided for failed validations. ```dart final person = object({ 'name': string().min(3), 'age': number().positive(), }).refine(onCheck: (value) => value['age'] > 4, error: 'Age is lower than 4', name: 'ageCheck'); ``` -------------------------------- ### Acanthis Nullable Schemas with Default Values Source: https://acanthis.serinus.app/defining-schemas.html Make any schema nullable and provide a default value using the `nullable(defaultValue: ...)` method. This is useful for optional fields. ```dart string().nullable(defaultValue: 'default'); number().nullable(defaultValue: 5); boolean().nullable(defaultValue: true); date().nullable(defaultValue: DateTime.now()); ... ``` -------------------------------- ### Provide Default Values with `withDefault()` Source: https://acanthis.serinus.app/defining-schemas.html Use `withDefault()` to specify a fallback value when validation fails. This behavior is only active with `tryParse()` or `tryParseAsync()`. `parse()` and `parseAsync()` will throw a `ValidationError`. ```dart final name = string().min(2).max(100).withDefault('Unknown'); name.tryParse('A'); // returns 'Unknown' name.tryParse('Acanthis'); // returns 'Acanthis' ``` -------------------------------- ### Asynchronously Try Parsing Valid User Data Source: https://acanthis.serinus.app/basic-usage.html Use `tryParseAsync` for schemas with asynchronous checks to validate data without exceptions. It returns a `Future` resolving to an `AcanthisParseResult`. ```dart userSchema.tryParseAsync({ 'name': 'Francesco', 'age': 32, 'email': 'test@example.com', }); // => Future ``` -------------------------------- ### Generate Basic Open API Schema Source: https://acanthis.serinus.app/open-api-schema.html Use the `toOpenApiSchema` method on an Acanthis object definition to generate a basic Open API schema. This schema describes the structure of the defined type. ```dart final schema = object({ 'name': string(), 'age': number(), }).toOpenApiSchema(); // => Map // => { // type: 'object', // properties: { // name: {type: 'string'}, // age: {type: 'number'} // }, // required: ['name', 'age'], // } ``` -------------------------------- ### Cross-field Validation with Refs Source: https://acanthis.serinus.app/defining-schemas.html Define reusable references and create a refinement that can access them for cross-field logic. Use `refineWithRefs` to supply a `RefAccessor` for reading registered references by name. ```dart class Order { final int quantity; final double unitPrice; Order(this.quantity, this.unitPrice); } final orderSchema = instance() .field('quantity', (o) => o.quantity, number().positive()) .field('unitPrice', (o) => o.unitPrice, number().positive()) .withRefs((r) => r .ref('qty', (o) => o.quantity) .ref('price', (o) => o.unitPrice) ) .refineWithRefs( (o, refs) => refs('qty') * refs('price') <= 1000, 'Total exceeds limit', name: 'totalLimit', ); ``` -------------------------------- ### tryParse() Source: https://acanthis.serinus.app/basic-usage.html Attempts to parse the value without throwing exceptions. Returns an `AcanthisParseResult` object indicating success or failure. Use `tryParseAsync` if using `AsyncCheck`. ```APIDOC ### `tryParse()` `AcanthisParseResult tryParse(T value)` To avoid throwing exceptions, you can use the `tryParse` method. This method will return an `AcanthisParseResult` object that contains the result of the parsing. dart ```dart userSchema.tryParse({ 'name': 'Francesco', 'age': 32, 'email': 'test@example.com', }); // => AcanthisParseResult(success: true, value: { name: Francesco, age: 32, email: test@example.com }, errors: {}, metadata: null) userSchema.parse({ 'name': 'Francesco', 'age': -32, 'email': 'test@example.com', }); // => AcanthisParseResult(success: false, value: null, errors: { age: 'Value must be positive' }, metadata: null) ``` INFO If you use any of the `AsyncCheck`, then you need to use the `tryParseAsync` method instead of `tryParse`. ``` -------------------------------- ### parseAsync() Source: https://acanthis.serinus.app/basic-usage.html Asynchronously parses the value, returning a `Future` that resolves to the parsed value. Use this when your schema includes asynchronous checks. ```APIDOC ### `parseAsync()` `Future parseAsync(T value)` This method behaves exactly like `parse`, but it returns a `Future` that resolves to the parsed value. dart ```dart userSchema.parseAsync({ 'name': 'Francesco', 'age': 32, 'email': 'test@example.com', }); // => Future<{ name: Francesco, age: 32, email: test@example.com }> ``` ``` -------------------------------- ### Try Parsing Invalid User Data Source: https://acanthis.serinus.app/basic-usage.html Demonstrates `tryParse` returning an `AcanthisParseResult` with `success: false` and error details when the data is invalid, such as a negative age. ```dart userSchema.parse({ 'name': 'Francesco', 'age': -32, 'email': 'test@example.com', }); // => AcanthisParseResult(success: false, value: null, errors: { age: 'Value must be positive' }, metadata: null) ``` -------------------------------- ### Union Schema Definition Source: https://acanthis.serinus.app/defining-schemas.html Create a union schema using `union()` to define a type that can be one of several specified types. The `union()` method accepts a list of schemas. ```dart final union = union([ string(), number(), boolean(), ]); ``` -------------------------------- ### Add Custom Asynchronous Validation with refineAsync() Source: https://acanthis.serinus.app/defining-schemas.html Use `refineAsync()` to add an asynchronous custom validation function to a schema. The `onCheck` callback should return a `Future`, allowing for validation logic that involves asynchronous operations. ```dart final person = object({ 'name': string().min(3), 'age': number().positive(), }).refineAsync(onCheck: (value) async => value['age'] > 4, error: 'Age is lower than 4', name: 'ageCheck'); ``` -------------------------------- ### parse() Source: https://acanthis.serinus.app/basic-usage.html Parses the value and returns a new instance of the parsed value. Throws a `ValidationError` if the value is invalid. Use `parseAsync` if using `AsyncCheck`. ```APIDOC ### `parse()` `T parse(T value)` Parses the value and returns a new instance of parsed value of type `T`. dart ```dart userSchema.parse({ 'name': 'Francesco', 'age': 32, 'email': 'test@example.com', }); // => { name: Francesco, age: 32, email: test@example.com } ``` If the value is invalid, a `ValidationError` will be thrown. dart ```dart userSchema.parse({ 'name': 'Francesco', 'age': -32, 'email': 'test@example.com', }); // => ValidationError: {'age': 'Value must be positive'} ``` INFO If you use any of the `AsyncCheck`, then you need to use the `parseAsync` method instead of `parse`. ``` -------------------------------- ### Unwrap List Element Type Source: https://acanthis.serinus.app/defining-schemas.html Use the `unwrap()` method on a list schema to retrieve the schema for its individual elements. ```dart final list = string().list(); final elementType = list.unwrap(); // string() ``` -------------------------------- ### tryParseAsync() Source: https://acanthis.serinus.app/basic-usage.html Asynchronously attempts to parse the value, returning a `Future` that resolves to an `AcanthisParseResult`. Use this for schemas with asynchronous checks to handle results without exceptions. ```APIDOC ### `tryParseAsync()` `Future tryParseAsync(T value)` This method behaves exactly like `tryParse`, but it returns a `Future` that resolves to the `AcanthisParseResult` object. dart ```dart userSchema.tryParseAsync({ 'name': 'Francesco', 'age': 32, 'email': 'test@example.com', }); // => Future ``` ``` -------------------------------- ### Validate Lists with `list()` Source: https://acanthis.serinus.app/defining-schemas.html Use `list()` to create schemas for validating and transforming lists. You can specify constraints like minimum length, maximum length, exact length, and element validation. ```dart list(string()).min(5); ``` ```dart list(string()).max(10); ``` ```dart list(string()).length(5); ``` ```dart list(string()).everyOf(['Acanthis', 'Dart']); ``` ```dart list(string()).anyOf(['Acanthis', 'Dart']); ``` ```dart list(string()).unique(); ``` -------------------------------- ### Add Custom Transformation with pipe() Source: https://acanthis.serinus.app/defining-schemas.html Use the `pipe()` method to chain a transformation function to a schema. This allows converting a value from one type to another during validation. The `transform` function defines how the value is converted. ```dart final name = string().pipe(number(), transform: (value) => int.parse(value)); ``` -------------------------------- ### Validate Object Property Counts Source: https://acanthis.serinus.app/defining-schemas.html Use `maxProperties()` and `minProperties()` to enforce limits on the number of properties an object can have. ```dart object({}).maxProperties(5); ``` ```dart object({}).minProperties(5); ``` -------------------------------- ### Fixed-Length Tuple Schema Source: https://acanthis.serinus.app/defining-schemas.html Define a tuple schema with specific types for each index. The `tuple()` method takes a list of schemas for each element. ```dart final tuple = tuple([ string(), number(), boolean(), ]); ``` -------------------------------- ### Create a Loose Object Schema with Passthrough Source: https://acanthis.serinus.app/defining-schemas.html Use `passthrough()` to allow additional properties in an object schema without validation. You can optionally specify a type to validate these extra properties. ```dart object({ 'name': string().min(3), 'age': number().positive(), }).passthrough(); ``` ```dart final person = object({ 'name': string().min(3), 'age': number().positive(), }).passthrough(type: string()); object.parse({ 'name': 'Acanthis', 'age': 5, 'email': 'test@example.com' }); // ✅ object.parse({ 'name': 'Acanthis', 'age': 5, 'email': 5 }); // ❌ throws ValidationError ``` -------------------------------- ### Asynchronously Parse Valid User Data Source: https://acanthis.serinus.app/basic-usage.html Use `parseAsync` for schemas that include asynchronous validation checks. It returns a `Future` that resolves to the parsed value. ```dart userSchema.parseAsync({ 'name': 'Francesco', 'age': 32, 'email': 'test@example.com', }); // => Future<{ name: Francesco, age: 32, email: test@example.com }> ``` -------------------------------- ### Define Optional Object Properties Source: https://acanthis.serinus.app/defining-schemas.html Use `optionals()` to specify properties that are not required in an object schema. ```dart object({ 'name': string().min(3), 'age': number().positive(), 'email': string().email(), }).optionals([ 'email', ]); ``` -------------------------------- ### Try Parsing Valid User Data Source: https://acanthis.serinus.app/basic-usage.html Use `tryParse` to validate data without throwing exceptions. It returns an `AcanthisParseResult` object indicating success or failure, along with the parsed value or errors. ```dart userSchema.tryParse({ 'name': 'Francesco', 'age': 32, 'email': 'test@example.com', }); // => AcanthisParseResult(success: true, value: { name: Francesco, age: 32, email: test@example.com }, errors: {}, metadata: null) ``` -------------------------------- ### Generate Open API Schema for Nullable Types Source: https://acanthis.serinus.app/open-api-schema.html To represent nullable fields in an Open API schema, use the `.nullable()` method on the type definition. This adds the `nullable: true` property to the schema. ```dart final schema = object({ 'name': string().nullable(), }).toOpenApiSchema(); // => { // type: 'object', // properties: { // name: {type: 'string', nullable: true} // }, // required: ['name'], // } ``` -------------------------------- ### Extend an Object Schema Source: https://acanthis.serinus.app/defining-schemas.html Use `extend()` to add new properties to an existing object schema. Existing properties will not be overwritten. ```dart object({ 'name': string().min(3), 'age': number().positive(), }).extend({ 'email': string().email(), }); ``` -------------------------------- ### Convert Acanthis Schema with Metadata to JSON Schema Source: https://acanthis.serinus.app/json-schema.html Metadata added to an Acanthis schema, such as `title` and `description`, is directly translated into the corresponding fields in the generated JSON Schema. ```dart final schema = object({ 'name': string(), 'age': number(), }).meta(MetadataEntry( title: 'Person', description: 'This is a schema for a person.', )).toJsonSchema(); ``` -------------------------------- ### Parse Valid User Data Source: https://acanthis.serinus.app/basic-usage.html Use the `parse` method to validate and transform data according to the defined schema. If the data is valid, it returns the parsed value; otherwise, it throws a `ValidationError`. ```dart userSchema.parse({ 'name': 'Francesco', 'age': 32, 'email': 'test@example.com', }); // => { name: Francesco, age: 32, email: test@example.com } ``` -------------------------------- ### Parse Invalid User Data Source: https://acanthis.serinus.app/basic-usage.html Demonstrates how `parse` throws a `ValidationError` when the provided data does not conform to the schema, such as a negative age. ```dart userSchema.parse({ 'name': 'Francesco', 'age': -32, 'email': 'test@example.com', }); // => ValidationError: {'age': 'Value must be positive'} ``` -------------------------------- ### Literal Value Schema Source: https://acanthis.serinus.app/defining-schemas.html Define a schema that matches a specific literal value using `literal()`. This schema does not expose additional checks and only matches the exact value provided. ```dart final numeric = literal(1); ``` -------------------------------- ### Make Object Properties Nullable with `partial()` Source: https://acanthis.serinus.app/defining-schemas.html Use `partial()` to make all properties of an object schema nullable. The `deep` parameter can be used to make nested properties nullable as well. ```dart final person = object({ 'name': string().min(3), 'age': number().positive(), }); final personPartial = person.partial(); ``` ```dart final person = object({ 'name': string().min(3), 'age': number().positive(), 'address': object({ 'city': string().min(3), 'country': string().min(3), }) }); final personPartial = person.partial(deep: true); ``` -------------------------------- ### Convert Acanthis Recursive Type to JSON Schema `$ref` Source: https://acanthis.serinus.app/json-schema.html Acanthis handles recursive types during schema generation by employing the `$ref` keyword, allowing the schema to reference itself within its definition. ```dart final schema = object({ 'name': string(), 'children': lazy((parent) => parent.list()) }).toJsonSchema(); ``` -------------------------------- ### Merge Object Schemas Source: https://acanthis.serinus.app/defining-schemas.html Use `merge()` to combine two object schemas. Properties from the second schema will overwrite existing properties with the same name. ```dart object({ 'name': string().min(3), 'age': number().positive(), }).merge({ 'email': string().email(), }); ``` -------------------------------- ### Acanthis Numeric Transformations Source: https://acanthis.serinus.app/defining-schemas.html Apply transformations to numeric schemas, such as calculating powers. ```dart number().pow(2); ``` -------------------------------- ### Define Recursive Object Schemas with `lazy()` Source: https://acanthis.serinus.app/defining-schemas.html Use `lazy()` to define schemas for recursive data structures like trees or linked lists, allowing a schema to refer to itself. ```dart final tree = object({ 'value': number(), 'children': lazy((parent) => parent.list()), }); ``` -------------------------------- ### Convert Acanthis Schema to JSON Schema Source: https://acanthis.serinus.app/json-schema.html Use the `toJsonSchema` method to convert an Acanthis schema object into a Map representing its JSON Schema equivalent. This is useful for generating schema definitions for external use. ```dart final schema = object({ 'name': string(), 'age': number(), }).toJsonSchema(); // => Map ``` -------------------------------- ### Convert Acanthis Number to JSON Schema Integer Source: https://acanthis.serinus.app/json-schema.html To generate a JSON Schema with an 'integer' type from an Acanthis `number()` schema, use the `.integer()` check. Otherwise, a `number()` schema without this check converts to JSON Schema's 'number' type. ```dart final schema = object({ 'age': number().integer(), }).toJsonSchema(); ``` -------------------------------- ### Acanthis String Transformations Source: https://acanthis.serinus.app/defining-schemas.html Apply these transformations to modify string values, such as changing case or encoding/decoding. ```dart string().toUpperCase(); string().toLowerCase(); string().encode(); string().decode(); ``` -------------------------------- ### Acanthis Nullable Schemas with Enumerated Values Source: https://acanthis.serinus.app/defining-schemas.html Combine `nullable()` with other validators like `enumerated()`. Note that `null` and any provided default value are automatically included in the enumerated list. ```dart string().nullable().enumerated(['Acanthis', 'Dart']); ``` -------------------------------- ### Acanthis Email Validation Source: https://acanthis.serinus.app/defining-schemas.html Use the `email()` method to specifically validate if a string is a correctly formatted email address. It relies on the `email_validator` package. ```dart string().email(); ``` -------------------------------- ### Acanthis String Validators Source: https://acanthis.serinus.app/defining-schemas.html Use these validators for common string checks like length, patterns, case, and content. `notEmpty()` replaces the deprecated `required()`. ```dart string().min(5); string().max(10); string().length(5); string().pattern(RegExp('^[a-zA-Z0-9]+$')); // string().pattern('^[a-zA-Z0-9]+$'); equivalent to the previous example string().contains('Acanthis'); string().startsWith('Acanthis'); string().endsWith('Acanthis'); string().upperCase(); string().lowerCase(); string().mixedCase(); string().notEmpty(); string().digits(); string().letters(); string().alphanumeric(); string().alphanumericWithSpaces(); string().specialCharacters(); string().allCharacters(); string().contained(TestEnum.values); string().contained(['Acanthis', 'Dart']); string().exact('Acanthis'); ``` -------------------------------- ### Acanthis Date Validators Source: https://acanthis.serinus.app/defining-schemas.html Validate date values against specific ranges or time differences using `min()`, `max()`, and `differsFrom*()` methods. ```dart date().min(DateTime.now()); date().max(DateTime.now()); date().differsFromNow(Duration(days: 5)); date().differsFrom(DateTime.now(), Duration(days: 5)); ``` -------------------------------- ### Validate Dart Class Instances with `instance()` Source: https://acanthis.serinus.app/defining-schemas.html Use `instance()` to validate Dart objects directly without converting them to Maps. Field validators are attached via getters, and the original instance is returned unchanged. ```dart class User { final String name; final int age; final String? email; User(this.name, this.age, this.email); } final userSchema = instance() .field('name', (u) => u.name, string().min(3)) .field('age', (u) => u.age, number().positive()) .field('email', (u) => u.email, string().email(), optional: true); userSchema.parse(User('Alice', 30, null)); // ✅ userSchema.parse(User('A', 30, null)); // ❌ ValidationError (name.min) ``` -------------------------------- ### Omit Properties from an Object Schema Source: https://acanthis.serinus.app/defining-schemas.html Use `omit()` to create a new schema excluding specified properties from an existing object schema. ```dart final person = object({ 'name': string().min(3), 'age': number().positive(), }); final personWithoutName = person.omit(['name']); ``` -------------------------------- ### Acanthis String Format Validators Source: https://acanthis.serinus.app/defining-schemas.html Validate strings against common formats like email, URL, UUID, and more. These ensure the string adheres to a specific structure. ```dart string().email(); string().url(); string().uri(); string().uuid(); string().dateTime(); string().time(); string().nanoid(); string().hexColor(); string().base64(); string().cuid(); string().cuid2(); string().ulid(); string().jwt(); string().card(); ``` -------------------------------- ### Convert Acanthis Nullable Type to JSON Schema `oneOf` Source: https://acanthis.serinus.app/json-schema.html Nullable types in Acanthis are converted to JSON Schema using the `oneOf` keyword, allowing the schema to accept either the specified type or `null`. ```dart final schema = object({ 'name': string().nullable(), }).toJsonSchema(); ``` -------------------------------- ### Acanthis Numeric Validators Source: https://acanthis.serinus.app/defining-schemas.html Validate numeric values using `number()`, `integer()`, or `double()`. Supports range checks, sign, divisibility, and specific numeric properties like NaN or infinity. ```dart number().gt(5); number().gte(10); number().lt(5); number().lte(10); number().positive(); number().negative(); number().nonNegative(); number().nonPositive(); number().multipleOf(5); number().integer(); number().double(); number().nonNan(); number().nan(); number().finite(); number().infinite(); number().enumerated([1, 2, 3]); number().exact(5); ``` -------------------------------- ### Acanthis Boolean Validators Source: https://acanthis.serinus.app/defining-schemas.html Validate boolean values using `isTrue()` or `isFalse()` to ensure they match the expected boolean state. ```dart boolean().isTrue(); boolean().isFalse(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.