MCPcopy Index your code
hub / github.com/InfinitiBit/graphbit / validate_against_rule

Method validate_against_rule

core/src/validation.rs:366–398  ·  view source on GitHub ↗

Validate data against a validation rule

(&self, data: &str, rule: &ValidationRule)

Source from the content-addressed store, hash-verified

364
365 /// Validate data against a validation rule
366 pub fn validate_against_rule(&self, data: &str, rule: &ValidationRule) -> ValidationResult {
367 let mut result = ValidationResult::success();
368
369 // Schema validation
370 if let Some(schema) = &rule.schema {
371 let schema_result = self.validate_against_schema(data, schema);
372 result.merge(schema_result);
373 }
374
375 // Custom validator
376 if let Some(validator_name) = &rule.validator_function {
377 if let Some(validator) = self.custom_validators.get(validator_name) {
378 match validator.validate(data, &rule.config) {
379 Ok(custom_result) => result.merge(custom_result),
380 Err(e) => {
381 result.add_error(ValidationError::new(
382 "custom_validator",
383 format!("Custom validation failed: {e}"),
384 "CUSTOM_VALIDATION_ERROR",
385 ));
386 }
387 }
388 } else {
389 result.add_error(ValidationError::new(
390 "validator",
391 format!("Unknown validator: {validator_name}"),
392 "UNKNOWN_VALIDATOR",
393 ));
394 }
395 }
396
397 result
398 }
399}
400
401impl Default for TypeValidator {

Calls 5

mergeMethod · 0.80
add_errorMethod · 0.80
getMethod · 0.45
validateMethod · 0.45