pub struct SchemaRegistry { /* private fields */ }Expand description
Registry for loading and storing schemas
Implementations§
Source§impl SchemaRegistry
impl SchemaRegistry
Sourcepub fn new() -> SchemaRegistry
pub fn new() -> SchemaRegistry
Create a new empty schema registry
Sourcepub fn from_directory(
schemas_dir: &Path,
) -> Result<SchemaRegistry, ValidationError>
pub fn from_directory( schemas_dir: &Path, ) -> Result<SchemaRegistry, ValidationError>
Sourcepub fn from_schemas(
schemas: &[(&str, &str)],
) -> Result<SchemaRegistry, ValidationError>
pub fn from_schemas( schemas: &[(&str, &str)], ) -> Result<SchemaRegistry, ValidationError>
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)],
) -> Result<(), ValidationError>
pub fn add_schemas( &mut self, schemas: &[(&str, &str)], ) -> Result<(), ValidationError>
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,
) -> Result<(), ValidationError>
pub fn validate_values( &self, namespace: &str, values: &Value, ) -> Result<(), ValidationError>
Validate an entire values object for a namespace
Sourcepub fn validate_option(
&self,
namespace: &str,
key: &str,
value: &Value,
) -> Result<(), ValidationError>
pub fn validate_option( &self, namespace: &str, key: &str, value: &Value, ) -> Result<(), ValidationError>
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,
) -> Result<(HashMap<String, HashMap<String, Value>>, HashMap<String, String>), ValidationError>
pub fn load_values_json( &self, values_dir: &Path, ) -> Result<(HashMap<String, HashMap<String, Value>>, HashMap<String, String>), ValidationError>
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.