pub struct RefSchema { /* private fields */ }Expand description
A schema that references another schema by name.
RefSchema enables schema reuse and recursive structures by referencing schemas stored in a registry. During validation, the reference is resolved to the actual schema.
References can only be validated through a registry using SchemaRegistry::validate().
Attempting to validate without a registry produces an error.
§Example
use postmortem::{Schema, SchemaRegistry};
use serde_json::json;
let registry = SchemaRegistry::new();
// Register a base schema
registry.register("UserId", Schema::integer().positive()).unwrap();
// Use a reference in another schema
registry.register("User", Schema::object()
.field("id", Schema::ref_("UserId"))
.field("name", Schema::string())
).unwrap();
let result = registry.validate("User", &json!({
"id": 42,
"name": "Alice"
})).unwrap();
assert!(result.is_success());Implementations§
Trait Implementations§
Source§impl SchemaLike for RefSchema
impl SchemaLike for RefSchema
Source§fn validate(
&self,
_value: &Value,
path: &JsonPath,
) -> Validation<Value, SchemaErrors>
fn validate( &self, _value: &Value, path: &JsonPath, ) -> Validation<Value, SchemaErrors>
Validates a value against this schema. Read more
Source§fn validate_to_value(
&self,
value: &Value,
path: &JsonPath,
) -> Validation<Value, SchemaErrors>
fn validate_to_value( &self, value: &Value, path: &JsonPath, ) -> Validation<Value, SchemaErrors>
Validates a value and returns the result as a
serde_json::Value. Read moreSource§fn validate_with_context(
&self,
value: &Value,
path: &JsonPath,
context: &ValidationContext,
) -> Validation<Value, SchemaErrors>
fn validate_with_context( &self, value: &Value, path: &JsonPath, context: &ValidationContext, ) -> Validation<Value, SchemaErrors>
Validates a value with registry context for schema reference resolution. Read more
Source§fn validate_to_value_with_context(
&self,
value: &Value,
path: &JsonPath,
context: &ValidationContext,
) -> Validation<Value, SchemaErrors>
fn validate_to_value_with_context( &self, value: &Value, path: &JsonPath, context: &ValidationContext, ) -> Validation<Value, SchemaErrors>
Validates a value with context and returns the result as a
serde_json::Value. Read moreAuto Trait Implementations§
impl Freeze for RefSchema
impl RefUnwindSafe for RefSchema
impl Send for RefSchema
impl Sync for RefSchema
impl Unpin for RefSchema
impl UnwindSafe for RefSchema
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
Mutably borrows from an owned value. Read more
Source§impl<S> ValueValidator for Swhere
S: SchemaLike,
impl<S> ValueValidator for Swhere
S: SchemaLike,
Source§fn validate_value(
&self,
value: &Value,
path: &JsonPath,
) -> Validation<Value, SchemaErrors>
fn validate_value( &self, value: &Value, path: &JsonPath, ) -> Validation<Value, SchemaErrors>
Validates a value and returns the result as a
serde_json::Value.Source§fn validate_value_with_context(
&self,
value: &Value,
path: &JsonPath,
context: &ValidationContext,
) -> Validation<Value, SchemaErrors>
fn validate_value_with_context( &self, value: &Value, path: &JsonPath, context: &ValidationContext, ) -> Validation<Value, SchemaErrors>
Validates a value with context and returns the result as a
serde_json::Value. Read more