CombinatorSchema

Enum CombinatorSchema 

Source
pub enum CombinatorSchema {
    OneOf {
        schemas: Vec<Arc<dyn Fn(&Value, &JsonPath) -> Validation<Value, SchemaErrors> + Send + Sync>>,
        validators: Vec<Arc<dyn ValueValidator>>,
    },
    AnyOf {
        schemas: Vec<Arc<dyn Fn(&Value, &JsonPath) -> Validation<Value, SchemaErrors> + Send + Sync>>,
        validators: Vec<Arc<dyn ValueValidator>>,
    },
    AllOf {
        schemas: Vec<Arc<dyn Fn(&Value, &JsonPath) -> Validation<Value, SchemaErrors> + Send + Sync>>,
        validators: Vec<Arc<dyn ValueValidator>>,
    },
    Optional {
        inner: Arc<dyn Fn(&Value, &JsonPath) -> Validation<Value, SchemaErrors> + Send + Sync>,
        validator: Arc<dyn ValueValidator>,
    },
}
Expand description

Schema combinators for composing validation logic.

CombinatorSchema provides four composition patterns:

  • OneOf: Exactly one schema must match (discriminated unions)
  • AnyOf: At least one schema must match (flexible unions)
  • AllOf: All schemas must match (intersection)
  • Optional: Value can be null

Each combinator implements SchemaLike and can be used anywhere a schema is expected.

Variants§

§

OneOf

Exactly one schema must match.

Validates the value against all schemas. Succeeds if exactly one matches, fails if none or multiple match. Ideal for discriminated unions where a value must be one of several distinct types.

Fields

§validators: Vec<Arc<dyn ValueValidator>>
§

AnyOf

At least one schema must match.

Validates the value against schemas in order, short-circuiting on the first match. Fails only if none match. More permissive than OneOf.

Fields

§validators: Vec<Arc<dyn ValueValidator>>
§

AllOf

All schemas must match.

Validates the value against all schemas. Succeeds only if all pass, accumulating errors from any that fail. Useful for schema composition and intersection.

Fields

§validators: Vec<Arc<dyn ValueValidator>>
§

Optional

Value can be null.

Null values pass validation. Non-null values are validated against the inner schema.

Fields

§validator: Arc<dyn ValueValidator>

Trait Implementations§

Source§

impl Clone for CombinatorSchema

Source§

fn clone(&self) -> CombinatorSchema

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl SchemaLike for CombinatorSchema

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

impl ToJsonSchema for CombinatorSchema

Source§

fn to_json_schema(&self) -> Value

Converts this schema to a JSON Schema representation. Read more

Auto Trait Implementations§

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.
Source§

impl<S> ValueValidator for S

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

fn to_json_schema(&self) -> Value

Converts this schema to JSON Schema format. Read more