pub trait ConfigValidator {
// Required methods
fn yaml_type(&self) -> YamlType;
fn validate_structure(&self) -> Vec<Diagnostic>;
fn validate_semantics(&self) -> Vec<Diagnostic>;
// Provided method
fn validate(&self) -> ValidationResult { ... }
}Expand description
Trait that all configuration validators implement.
Adding a new config type involves:
- Creating a struct that deserializes from YAML via serde
- Implementing this trait with structure and semantic validation
- Registering the type in
yaml_validator::detect_yaml_type()
§Example
ⓘ
use shared::models::validation::{ConfigValidator, Diagnostic, Severity, YamlType};
struct MyConfig {
name: String,
}
impl ConfigValidator for MyConfig {
fn yaml_type(&self) -> YamlType {
YamlType::Generic
}
fn validate_structure(&self) -> Vec<Diagnostic> {
if self.name.is_empty() {
vec![Diagnostic {
severity: Severity::Error,
message: "name cannot be empty".to_string(),
path: Some("name".to_string()),
}]
} else {
vec![]
}
}
fn validate_semantics(&self) -> Vec<Diagnostic> {
vec![]
}
}Required Methods§
Sourcefn validate_structure(&self) -> Vec<Diagnostic>
fn validate_structure(&self) -> Vec<Diagnostic>
Structural validation — errors mean the config is invalid.
Returns diagnostics for issues that make the configuration syntactically or structurally invalid (missing required fields, wrong types, etc.).
Sourcefn validate_semantics(&self) -> Vec<Diagnostic>
fn validate_semantics(&self) -> Vec<Diagnostic>
Semantic validation — best-practice warnings, hints, and info.
Returns diagnostics for issues that are technically valid but may indicate misconfiguration or deviate from best practices (e.g., replicas=1, missing resource limits).
Provided Methods§
Sourcefn validate(&self) -> ValidationResult
fn validate(&self) -> ValidationResult
Full validation: structure + semantics combined.