pub struct ValidationRule {
pub name: String,
pub rule_type: ValidationRuleType,
pub config: String,
pub level: ValidationLevel,
pub description: Option<String>,
pub active: bool,
pub applies_to: Vec<SchemaType>,
pub subject_patterns: Vec<String>,
}Expand description
Content validation rule for custom schema validation
Validation rules extend beyond compatibility checking to enforce organizational policies and data quality requirements.
§Examples
use rivven_schema::types::{ValidationRule, ValidationRuleType, ValidationLevel};
// Require a "doc" field in all Avro schemas
let doc_required = ValidationRule::new(
"doc-required",
ValidationRuleType::FieldRequired,
r#"{"field": "doc"}"#,
).with_level(ValidationLevel::Error);
// Enforce naming convention
let naming_rule = ValidationRule::new(
"pascal-case",
ValidationRuleType::NamingConvention,
r#"{"pattern": "^[A-Z][a-zA-Z0-9]*$"}"#,
);Fields§
§name: StringUnique rule name
rule_type: ValidationRuleTypeRule type
config: StringRule configuration (JSON)
level: ValidationLevelValidation level
description: Option<String>Description of what the rule checks
active: boolWhether the rule is active
applies_to: Vec<SchemaType>Schema types this rule applies to (empty = all)
subject_patterns: Vec<String>Subjects this rule applies to (regex patterns, empty = all)
Implementations§
Source§impl ValidationRule
impl ValidationRule
Sourcepub fn new(
name: impl Into<String>,
rule_type: ValidationRuleType,
config: impl Into<String>,
) -> Self
pub fn new( name: impl Into<String>, rule_type: ValidationRuleType, config: impl Into<String>, ) -> Self
Create a new validation rule
Sourcepub fn with_level(self, level: ValidationLevel) -> Self
pub fn with_level(self, level: ValidationLevel) -> Self
Set the validation level
Sourcepub fn with_description(self, description: impl Into<String>) -> Self
pub fn with_description(self, description: impl Into<String>) -> Self
Set the description
Sourcepub fn with_active(self, active: bool) -> Self
pub fn with_active(self, active: bool) -> Self
Set the active state
Sourcepub fn with_schema_types(self, types: Vec<SchemaType>) -> Self
pub fn with_schema_types(self, types: Vec<SchemaType>) -> Self
Add schema types this rule applies to
Sourcepub fn with_subject_patterns(self, patterns: Vec<String>) -> Self
pub fn with_subject_patterns(self, patterns: Vec<String>) -> Self
Add subject patterns this rule applies to
Sourcepub fn for_subjects(self, patterns: Vec<String>) -> Self
pub fn for_subjects(self, patterns: Vec<String>) -> Self
Alias for with_subject_patterns for convenience
Sourcepub fn for_schema_types(self, types: Vec<SchemaType>) -> Self
pub fn for_schema_types(self, types: Vec<SchemaType>) -> Self
Alias for with_schema_types for convenience
Sourcepub fn applies(&self, schema_type: SchemaType, subject: &str) -> bool
pub fn applies(&self, schema_type: SchemaType, subject: &str) -> bool
Check if this rule applies to the given schema type and subject
Sourcepub fn rule_type(&self) -> ValidationRuleType
pub fn rule_type(&self) -> ValidationRuleType
Get the rule type
Sourcepub fn level(&self) -> ValidationLevel
pub fn level(&self) -> ValidationLevel
Get the validation level
Sourcepub fn description(&self) -> Option<&str>
pub fn description(&self) -> Option<&str>
Get the description
Trait Implementations§
Source§impl Clone for ValidationRule
impl Clone for ValidationRule
Source§fn clone(&self) -> ValidationRule
fn clone(&self) -> ValidationRule
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more