RefSchema

Struct RefSchema 

Source
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§

Source§

impl RefSchema

Source

pub fn new(name: impl Into<String>) -> Self

Creates a new schema reference.

This is typically called via Schema::ref_() rather than directly.

Source

pub fn name(&self) -> &str

Returns the name of the referenced schema.

Trait Implementations§

Source§

impl SchemaLike for RefSchema

Source§

type Output = Value

The output type produced by successful validation.
Source§

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>

Validates a value and returns the result as a serde_json::Value. Read more
Source§

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>

Validates a value with context and returns the result as a serde_json::Value. Read more
Source§

fn collect_refs(&self, refs: &mut Vec<String>)

Collects all schema reference names used by this schema. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S> ValueValidator for S
where S: SchemaLike,

Source§

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>

Validates a value with context and returns the result as a serde_json::Value. Read more
Source§

fn collect_refs(&self, refs: &mut Vec<String>)

Collects schema reference names. Read more