pub struct SchemaRegistry { /* private fields */ }Expand description
JSON Schema registry for per-tenant payload validation.
Registry of per-tenant JSON Schema validators, keyed by (project, kind).
Obtain an instance with SchemaRegistry::empty (for tests / configs
without schema entries) or SchemaRegistry::load (production path).
Implementations§
Source§impl SchemaRegistry
impl SchemaRegistry
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Returns an empty registry that accepts any payload for any project.
Used by tests and by tokens configs that omit [[schema]] tables.
Sourcepub async fn load(entries: &[ProjectSchemaEntry]) -> Result<Self, SchemaError>
pub async fn load(entries: &[ProjectSchemaEntry]) -> Result<Self, SchemaError>
Loads schema files from disk and compiles them with jsonschema.
entries must already have their path fields resolved to absolute
paths (i.e. relative to the tokens config’s parent directory, not to
the current working directory).
§Errors
Returns SchemaError::Io if a file cannot be read, or
SchemaError::Parse if the file content is not valid JSON or fails
to compile as a JSON Schema.
Sourcepub fn validate(
&self,
project: &str,
kind: SchemaKind,
payload: &Value,
) -> Result<(), SchemaError>
pub fn validate( &self, project: &str, kind: SchemaKind, payload: &Value, ) -> Result<(), SchemaError>
Validates payload against the schema registered for (project, kind).
Returns Ok(()) when no schema is registered for the pair
(accept-by-default — tenants without a schema are not gated). Returns
SchemaError::Validation when a registered schema rejects the
payload, with all collected errors.
Trait Implementations§
Source§impl Clone for SchemaRegistry
impl Clone for SchemaRegistry
Source§fn clone(&self) -> SchemaRegistry
fn clone(&self) -> SchemaRegistry
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for SchemaRegistry
impl !RefUnwindSafe for SchemaRegistry
impl Send for SchemaRegistry
impl Sync for SchemaRegistry
impl Unpin for SchemaRegistry
impl UnsafeUnpin for SchemaRegistry
impl !UnwindSafe for SchemaRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request