MCPcopy Create free account
hub / github.com/apache/avro-rs / SchemaNamespaceValidator

Interface SchemaNamespaceValidator

avro/src/validator.rs:136–158  ·  view source on GitHub ↗

A trait that validates schema namespaces. To register a custom one use [`set_schema_namespace_validator`].

Source from the content-addressed store, hash-verified

134///
135/// To register a custom one use [`set_schema_namespace_validator`].
136pub trait SchemaNamespaceValidator: Send + Sync {
137 /// The regex used to validate the schema namespace.
138 ///
139 /// The default implementation uses the Avro specified regex.
140 fn regex(&self) -> &'static Regex {
141 static NAMESPACE_ONCE: OnceLock<Regex> = OnceLock::new();
142 NAMESPACE_ONCE.get_or_init(|| {
143 Regex::new(r"^([A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)*)?$").unwrap()
144 })
145 }
146
147 /// Validates a schema namespace.
148 ///
149 /// Should return [`Details::InvalidNamespace`] if it is invalid.
150 fn validate(&self, namespace: &str) -> AvroResult<()> {
151 let regex = SchemaNamespaceValidator::regex(self);
152 if !regex.is_match(namespace) {
153 Err(Details::InvalidNamespace(namespace.to_string(), regex.as_str()).into())
154 } else {
155 Ok(())
156 }
157 }
158}
159
160impl SchemaNamespaceValidator for SpecificationValidator {}
161

Callers

nothing calls this directly

Implementers 2

validator.rsavro/src/validator.rs
validators.rsavro/tests/validators.rs

Calls

no outgoing calls

Tested by

no test coverage detected