pub struct SchemaRegistry { /* private fields */ }Expand description
Registry for loading and storing schemas
Implementations§
Source§impl SchemaRegistry
impl SchemaRegistry
Sourcepub fn from_directory(schemas_dir: &Path) -> ValidationResult<Self>
pub fn from_directory(schemas_dir: &Path) -> ValidationResult<Self>
Sourcepub fn from_schemas(schemas: &[(&str, &str)]) -> ValidationResult<Self>
pub fn from_schemas(schemas: &[(&str, &str)]) -> ValidationResult<Self>
Build a registry from in-memory schema JSON strings.
Each entry is a (namespace, json) pair. Applies the same validation
pipeline as from_directory (meta-schema check, constraint injection,
validator compilation) without reading from the filesystem.
Sourcepub fn add_schemas(&mut self, schemas: &[(&str, &str)]) -> ValidationResult<()>
pub fn add_schemas(&mut self, schemas: &[(&str, &str)]) -> ValidationResult<()>
Add in-memory (namespace, json) schemas to whatever is already loaded.
Errors on an already-present namespace, so an in-memory schema can’t
silently shadow one loaded from disk.
Sourcepub fn validate_values(
&self,
namespace: &str,
values: &Value,
) -> ValidationResult<()>
pub fn validate_values( &self, namespace: &str, values: &Value, ) -> ValidationResult<()>
Validate an entire values object for a namespace
Sourcepub fn validate_option(
&self,
namespace: &str,
key: &str,
value: &Value,
) -> ValidationResult<()>
pub fn validate_option( &self, namespace: &str, key: &str, value: &Value, ) -> ValidationResult<()>
Validate one option value against the named namespace schema.
This is the narrow validation boundary for callers that write a single
option and do not have a complete values document. It uses the same
schema parsing and validation pipeline as validate_values.
Sourcepub fn get(&self, namespace: &str) -> Option<&Arc<NamespaceSchema>>
pub fn get(&self, namespace: &str) -> Option<&Arc<NamespaceSchema>>
Get a namespace schema by name
Sourcepub fn schemas(&self) -> &HashMap<String, Arc<NamespaceSchema>>
pub fn schemas(&self) -> &HashMap<String, Arc<NamespaceSchema>>
Get all loaded schemas (for schema evolution validation)
Sourcepub fn load_values_json(
&self,
values_dir: &Path,
) -> ValidationResult<(ValuesByNamespace, HashMap<String, String>)>
pub fn load_values_json( &self, values_dir: &Path, ) -> ValidationResult<(ValuesByNamespace, HashMap<String, String>)>
Load and validate JSON values from a directory. Allows extra unknown option values to accommodate deployment race conditions
Expects structure: {values_dir}/{namespace}/values.json
Values file must have format: {"options": {"key": value, ...}, "generated_at": "..."}
Skips namespaces without a values.json file.
Returns the values and a map of namespace -> generated_at timestamp.
Sourcepub fn strip_unknown_keys(&self, namespace: &str, values: &Value) -> Value
pub fn strip_unknown_keys(&self, namespace: &str, values: &Value) -> Value
Remove keys from values that are not defined in the namespace schema. Logs a warning for each removed key. Returns the filtered values object.