validate static method

ZapValidationResult validate(
  1. Map<String, Object?> document, {
  2. Map<String, Object?>? schema,
})

Validates document (already JSON-decoded) against the schema for its type field, or against schema when given.

Never throws — structural problems are DATA (issues), not exceptions; the host turns them into error envelopes.

Implementation

static ZapValidationResult validate(
  Map<String, Object?> document, {
  Map<String, Object?>? schema,
}) {
  final resolved = schema ?? _schemaFor(document);
  if (resolved == null) {
    return ZapValidationResult(
      issues: [
        ZapValidationIssue(
          path: 'type',
          message:
              'unknown message type '
              '"${document['type']}"; must be one of '
              '${zapMessageTypes.join('|')}',
        ),
      ],
    );
  }
  return _validateValue(document, resolved, '');
}