Schema

Struct Schema 

Source
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: bool

Whether this schema is optional

§default: Option<Value>

Default value if not provided

Implementations§

Source§

impl Schema

Source

pub fn new() -> Self

Create a new empty schema

Source

pub fn with_type(value_type: ValueType) -> Self

Create a schema with a specific type

Source

pub fn rule(self, rule: SchemaRule) -> Self

Add a validation rule

Source

pub fn rules(self, rules: Vec<SchemaRule>) -> Self

Add multiple validation rules

Source

pub fn info(self, title: &str, description: &str) -> Self

Set title and description

Source

pub fn optional(self) -> Self

Mark schema as optional

Source

pub fn default_value(self, value: Value) -> Self

Set default value

Source

pub fn validate(&self, value: &Value, path: &str) -> ValidationResult<()>

Validate a value against this schema

Source

fn apply_rule( &self, rule: &SchemaRule, value: &Value, path: &str, ) -> ValidationResult<()>

Apply a single validation rule

Source

fn validate_type( &self, expected_type: &ValueType, value: &Value, path: &str, ) -> ValidationResult<()>

Validate value type

Source

fn validate_pattern( &self, regex: &Regex, value: &Value, path: &str, ) -> ValidationResult<()>

Validate regex pattern

Source

fn validate_length( &self, min: Option<usize>, max: Option<usize>, value: &Value, path: &str, ) -> ValidationResult<()>

Validate length constraints

Source

fn validate_range( &self, min: Option<f64>, max: Option<f64>, value: &Value, path: &str, ) -> ValidationResult<()>

Validate numeric range

Source

fn validate_enum( &self, allowed_values: &[Value], value: &Value, path: &str, ) -> ValidationResult<()>

Validate enum values

Source

fn validate_properties( &self, properties: &HashMap<String, Schema>, value: &Value, path: &str, ) -> ValidationResult<()>

Validate object properties

Source

fn validate_items( &self, item_schema: &Schema, value: &Value, path: &str, ) -> ValidationResult<()>

Validate array items

Source

fn validate_required( &self, required_props: &[String], value: &Value, path: &str, ) -> ValidationResult<()>

Validate required properties

Source

fn validate_additional_properties( &self, allowed: bool, value: &Value, _path: &str, ) -> ValidationResult<()>

Validate additional properties

Source

fn validate_custom( &self, name: &str, value: &Value, path: &str, ) -> ValidationResult<()>

Validate using custom function

Source

fn validate_conditional( &self, if_schema: &Schema, then_schema: Option<&Schema>, else_schema: Option<&Schema>, value: &Value, path: &str, ) -> ValidationResult<()>

Validate conditional logic

Source

fn validate_not( &self, schema: &Schema, value: &Value, path: &str, ) -> ValidationResult<()>

Validate negation (NOT)

Source

fn validate_any_of( &self, schemas: &[Schema], value: &Value, path: &str, ) -> ValidationResult<()>

Validate any of (OR)

Source

fn validate_all_of( &self, schemas: &[Schema], value: &Value, path: &str, ) -> ValidationResult<()>

Validate all of (AND)

Source

fn validate_one_of( &self, schemas: &[Schema], value: &Value, path: &str, ) -> ValidationResult<()>

Validate one of (XOR)

Trait Implementations§

Source§

impl Clone for Schema

Source§

fn clone(&self) -> Schema

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Schema

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Schema

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> 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> CloneToUninit for T
where T: Clone,

Source§

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
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

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

Uses borrowed data to replace owned data, usually by cloning. Read more
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.