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
inner: Arc<dyn Fn(&Value, &JsonPath) -> Validation<Value, SchemaErrors> + Send + Sync>validator: Arc<dyn ValueValidator>Trait Implementations§
Source§impl Clone for CombinatorSchema
impl Clone for CombinatorSchema
Source§fn clone(&self) -> CombinatorSchema
fn clone(&self) -> CombinatorSchema
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl SchemaLike for CombinatorSchema
impl SchemaLike for CombinatorSchema
Source§fn validate(
&self,
value: &Value,
path: &JsonPath,
) -> Validation<Value, SchemaErrors>
fn validate( &self, value: &Value, path: &JsonPath, ) -> Validation<Value, SchemaErrors>
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>
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>
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>
serde_json::Value. Read moreSource§impl ToJsonSchema for CombinatorSchema
impl ToJsonSchema for CombinatorSchema
Source§fn to_json_schema(&self) -> Value
fn to_json_schema(&self) -> Value
Auto Trait Implementations§
impl Freeze for CombinatorSchema
impl !RefUnwindSafe for CombinatorSchema
impl Send for CombinatorSchema
impl Sync for CombinatorSchema
impl Unpin for CombinatorSchema
impl !UnwindSafe for CombinatorSchema
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)Source§impl<S> ValueValidator for Swhere
S: SchemaLike + ToJsonSchema,
impl<S> ValueValidator for Swhere
S: SchemaLike + ToJsonSchema,
Source§fn validate_value(
&self,
value: &Value,
path: &JsonPath,
) -> Validation<Value, SchemaErrors>
fn validate_value( &self, value: &Value, path: &JsonPath, ) -> Validation<Value, SchemaErrors>
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>
serde_json::Value. Read more