pub struct Schema {
pub title: Option<String>,
pub description: Option<String>,
pub rules: Vec<SchemaRule>,
pub optional: bool,
pub default: Option<Value>,
}Expand description
A complete schema definition
Fields§
§title: Option<String>Schema title/description
description: Option<String>Schema description
rules: Vec<SchemaRule>Validation rules for this schema
optional: boolWhether this schema is optional
default: Option<Value>Default value if not provided
Implementations§
Source§impl Schema
impl Schema
Sourcepub fn rule(self, rule: SchemaRule) -> Self
pub fn rule(self, rule: SchemaRule) -> Self
Add a validation rule
Sourcepub fn rules(self, rules: Vec<SchemaRule>) -> Self
pub fn rules(self, rules: Vec<SchemaRule>) -> Self
Add multiple validation rules
Sourcepub fn default_value(self, value: Value) -> Self
pub fn default_value(self, value: Value) -> Self
Set default value
Sourcepub fn validate(&self, value: &Value, path: &str) -> ValidationResult<()>
pub fn validate(&self, value: &Value, path: &str) -> ValidationResult<()>
Validate a value against this schema
Sourcefn apply_rule(
&self,
rule: &SchemaRule,
value: &Value,
path: &str,
) -> ValidationResult<()>
fn apply_rule( &self, rule: &SchemaRule, value: &Value, path: &str, ) -> ValidationResult<()>
Apply a single validation rule
Sourcefn validate_type(
&self,
expected_type: &ValueType,
value: &Value,
path: &str,
) -> ValidationResult<()>
fn validate_type( &self, expected_type: &ValueType, value: &Value, path: &str, ) -> ValidationResult<()>
Validate value type
Sourcefn validate_pattern(
&self,
regex: &Regex,
value: &Value,
path: &str,
) -> ValidationResult<()>
fn validate_pattern( &self, regex: &Regex, value: &Value, path: &str, ) -> ValidationResult<()>
Validate regex pattern
Sourcefn validate_length(
&self,
min: Option<usize>,
max: Option<usize>,
value: &Value,
path: &str,
) -> ValidationResult<()>
fn validate_length( &self, min: Option<usize>, max: Option<usize>, value: &Value, path: &str, ) -> ValidationResult<()>
Validate length constraints
Sourcefn validate_range(
&self,
min: Option<f64>,
max: Option<f64>,
value: &Value,
path: &str,
) -> ValidationResult<()>
fn validate_range( &self, min: Option<f64>, max: Option<f64>, value: &Value, path: &str, ) -> ValidationResult<()>
Validate numeric range
Sourcefn validate_enum(
&self,
allowed_values: &[Value],
value: &Value,
path: &str,
) -> ValidationResult<()>
fn validate_enum( &self, allowed_values: &[Value], value: &Value, path: &str, ) -> ValidationResult<()>
Validate enum values
Sourcefn validate_properties(
&self,
properties: &HashMap<String, Schema>,
value: &Value,
path: &str,
) -> ValidationResult<()>
fn validate_properties( &self, properties: &HashMap<String, Schema>, value: &Value, path: &str, ) -> ValidationResult<()>
Validate object properties
Sourcefn validate_items(
&self,
item_schema: &Schema,
value: &Value,
path: &str,
) -> ValidationResult<()>
fn validate_items( &self, item_schema: &Schema, value: &Value, path: &str, ) -> ValidationResult<()>
Validate array items
Sourcefn validate_required(
&self,
required_props: &[String],
value: &Value,
path: &str,
) -> ValidationResult<()>
fn validate_required( &self, required_props: &[String], value: &Value, path: &str, ) -> ValidationResult<()>
Validate required properties
Sourcefn validate_additional_properties(
&self,
allowed: bool,
value: &Value,
_path: &str,
) -> ValidationResult<()>
fn validate_additional_properties( &self, allowed: bool, value: &Value, _path: &str, ) -> ValidationResult<()>
Validate additional properties
Sourcefn validate_custom(
&self,
name: &str,
value: &Value,
path: &str,
) -> ValidationResult<()>
fn validate_custom( &self, name: &str, value: &Value, path: &str, ) -> ValidationResult<()>
Validate using custom function
Sourcefn validate_conditional(
&self,
if_schema: &Schema,
then_schema: Option<&Schema>,
else_schema: Option<&Schema>,
value: &Value,
path: &str,
) -> ValidationResult<()>
fn validate_conditional( &self, if_schema: &Schema, then_schema: Option<&Schema>, else_schema: Option<&Schema>, value: &Value, path: &str, ) -> ValidationResult<()>
Validate conditional logic
Sourcefn validate_not(
&self,
schema: &Schema,
value: &Value,
path: &str,
) -> ValidationResult<()>
fn validate_not( &self, schema: &Schema, value: &Value, path: &str, ) -> ValidationResult<()>
Validate negation (NOT)
Sourcefn validate_any_of(
&self,
schemas: &[Schema],
value: &Value,
path: &str,
) -> ValidationResult<()>
fn validate_any_of( &self, schemas: &[Schema], value: &Value, path: &str, ) -> ValidationResult<()>
Validate any of (OR)
Sourcefn validate_all_of(
&self,
schemas: &[Schema],
value: &Value,
path: &str,
) -> ValidationResult<()>
fn validate_all_of( &self, schemas: &[Schema], value: &Value, path: &str, ) -> ValidationResult<()>
Validate all of (AND)
Sourcefn validate_one_of(
&self,
schemas: &[Schema],
value: &Value,
path: &str,
) -> ValidationResult<()>
fn validate_one_of( &self, schemas: &[Schema], value: &Value, path: &str, ) -> ValidationResult<()>
Validate one of (XOR)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Schema
impl RefUnwindSafe for Schema
impl Send for Schema
impl Sync for Schema
impl Unpin for Schema
impl UnwindSafe for Schema
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