validateSchema<O> method

Future<O> validateSchema<O>(
  1. Schema<O> schema,
  2. Object? data
)

Check data with any schema and give its typed output.

Implementation

Future<O> validateSchema<O>(Schema<O> schema, Object? data) async {
  ParseResult<O> result = schema.isAsync
      ? await schema.safeParseAsync(data, messages: Dox().messages)
      : schema.safeParse(data, messages: Dox().messages);
  if (!result.success) throw ValidationException(message: result.errors);
  return result.value as O;
}