validate method
Future<void>
validate(
- EngineContext context,
- Map<
String, String> rules, { - bool bail = false,
- Map<
String, String> ? messages,
override
Validates the request body against the given rules.
This method decodes the request body, creates a Validator with the provided rules,
and validates the decoded body. If there are validation errors, a ValidationError is thrown.
context is the EngineContext of the request.
rules is a Map of validation rules.
Returns a Future that completes when validation is done.
Implementation
@override
Future<void> validate(
EngineContext context,
Map<String, String> rules, {
bool bail = false,
Map<String, String>? messages,
}) async {
final decoded = await _decodedBody(context); // Decode the request body.
final registry = requireValidationRegistry(context.container);
final validator = Validator.make(
rules,
registry: registry,
bail: bail,
messages: messages,
); // Create a validator with the rules.
final errors = validator.validate(decoded); // Validate the decoded body.
if (errors.isNotEmpty) {
throw ValidationError(errors); // Throw an error if validation fails.
}
}