validate static method
Validates the given schemaId
against the given value
. If the
optional validate
parameter is not true
then this will no-op and
immediately return with true
.
It should be noted that this validation is a relatively expensive
operation. For that reason, this defaults to performing the validation
when in the debug build and skipping validation for release builds. This
optimization can be overridden by setting debugOnly
to false
.
As a note, if the enabled value is false
then both the debugOnly
and
the validate
values will be ignored and validation will always be
skipped.
Implementation
static bool validate({
bool debugOnly = true,
required String schemaId,
required dynamic value,
bool validate = true,
}) {
var result = true;
if (enabled == true) {
if (validate == true) {
if (_initialized != true) {
_initialized = true;
SchemaCache().addSchemas(Schemas.all);
}
if (debugOnly == true) {
assert(() {
result = _validate(
schemaId: schemaId,
value: value,
);
return true;
}());
} else {
result = _validate(
schemaId: schemaId,
value: value,
);
}
}
}
return result;
}