validate method
Future<void>
validate(
- EngineContext context,
- Map<
String, String> rules, { - bool bail = false,
- Map<
String, String> ? messages,
override
Validates the JSON body of the request against a set of rules.
This method first decodes the JSON body using _decodedBody, then creates a Validator
with the provided rules, and finally validates the decoded JSON. If there are any validation
errors, a ValidationError is thrown.
context - The EngineContext containing the request information.
rules - A Map of validation rules to apply to the JSON body.
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);
final registry = requireValidationRegistry(context.container);
final validator = Validator.make(
rules,
registry: registry,
bail: bail,
messages: messages,
);
final errors = validator.validate(decoded);
if (errors.isNotEmpty) {
throw ValidationError(errors);
}
}