Schema<O> class abstract

Base class of every schema. O is the output type.

Subclasses implement parseType (type check and coercion) and jsonSchemaBase. The fluent schemas extend BaseSchema. A generated DTO schema extends it directly, so it can be const.

Implemented types

Constructors

Schema()
const

Properties

description → String?
Text for docs. Set with .describe().
no setter
examples → List<Object?>
Example values for docs. Set with .example().
no setter
hashCode → int
The hash code for this object.
no setterinherited
isAsync → bool
true when this schema or a child has async rules.
no setter
isOptional → bool
true when the value may be missing in an object.
no setter
rules → List<Rule<O>>
Rules that run after the type check.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
vendor → String
Name of the library that made the schema. Dox schemas use dox.
no setteroverride
version → int
Version of the Standard Schema interface. Always 1.
no setteroverride

Methods

addRequiredIssue(Object? input, ParseState state, List<Object> path) → void
Add the required issue.
addTypeIssue({required String code, required String fallback, required Object? input, required ParseState state, required List<Object> path}) → void
Add a wrong type issue, like "must be a string".
defaultTo(O value) → DefaultSchema<O>
Use value when the input is missing. (default is a reserved word in Dart.)
jsonSchemaBase() → Map<String, dynamic>
JSON Schema keys for the type, like {'type': 'string'}.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
nullable() → NullableSchema<O>
The value may be null. It must still be present in an object.
nullish() → OptionalSchema<O?>
The value may be missing or null.
optional() → OptionalSchema<O>
The value may be missing. null is still not allowed.
parse(Object? input, {MessageResolver? messages}) → O
Return the typed output or throw ValidationException.
parseAsync(Object? input, {MessageResolver? messages}) → Future<O>
Async version of parse. Needed for async rules.
parseType(Object? input, ParseState state, List<Object> path) → Object?
Check the type and return the output, or invalid. input is never null or undefined here.
parseTypeAsync(Object? input, ParseState state, List<Object> path) → Future<Object?>
Async version of parseType. Container schemas override it.
parseValue(Object? input, ParseState state, List<Object> path) → Object?
Parse one value: check missing values, the type, then the rules.
parseValueAsync(Object? input, ParseState state, List<Object> path) → Future<Object?>
Async version of parseValue.
runRules(Object? output, int issuesBefore, ParseState state, List<Object> path) → Object?
Run rules on output. Skipped when the value already has issues.
runRulesAsync(Object? output, int issuesBefore, ParseState state, List<Object> path) → Future<Object?>
Async version of runRules.
safeParse(Object? input, {MessageResolver? messages}) → ParseResult<O>
Return a ParseResult. It never throws for bad input.
safeParseAsync(Object? input, {MessageResolver? messages}) → Future<ParseResult<O>>
Async version of safeParse.
toJsonSchema() → Map<String, dynamic>
JSON Schema (draft 2020-12, OpenAPI 3.1) for this schema.
toString() → String
A string representation of this object.
inherited
transform<T>(T transformer(O value)) → TransformSchema<O, T>
Change the output after it passes validation.
validate(Object? value) → FutureOr<StandardResult<O>>
Standard Schema entry point.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited