schemars::schema

Struct SchemaObject

Source
pub struct SchemaObject {
    pub metadata: Option<Box<Metadata>>,
    pub instance_type: Option<SingleOrVec<InstanceType>>,
    pub format: Option<String>,
    pub enum_values: Option<Vec<Value>>,
    pub const_value: Option<Value>,
    pub subschemas: Option<Box<SubschemaValidation>>,
    pub number: Option<Box<NumberValidation>>,
    pub string: Option<Box<StringValidation>>,
    pub array: Option<Box<ArrayValidation>>,
    pub object: Option<Box<ObjectValidation>>,
    pub reference: Option<String>,
    pub extensions: Map<String, Value>,
}
Expand description

A JSON Schema object.

Fields§

§metadata: Option<Box<Metadata>>

Properties which annotate the SchemaObject which typically have no effect when an object is being validated against the schema.

§instance_type: Option<SingleOrVec<InstanceType>>§format: Option<String>§enum_values: Option<Vec<Value>>§const_value: Option<Value>§subschemas: Option<Box<SubschemaValidation>>

Properties of the SchemaObject which define validation assertions in terms of other schemas.

§number: Option<Box<NumberValidation>>

Properties of the SchemaObject which define validation assertions for numbers.

§string: Option<Box<StringValidation>>

Properties of the SchemaObject which define validation assertions for strings.

§array: Option<Box<ArrayValidation>>

Properties of the SchemaObject which define validation assertions for arrays.

§object: Option<Box<ObjectValidation>>

Properties of the SchemaObject which define validation assertions for objects.

§reference: Option<String>§extensions: Map<String, Value>

Arbitrary extra properties which are not part of the JSON Schema specification, or which schemars does not support.

Implementations§

Source§

impl SchemaObject

Source

pub fn new_ref(reference: String) -> Self

Creates a new $ref schema.

The given reference string should be a URI reference. This will usually be a JSON Pointer in URI Fragment representation.

Source

pub fn is_ref(&self) -> bool

Returns true if self is a $ref schema.

If self has Some reference set, this returns true. Otherwise, returns false.

Source

pub fn has_type(&self, ty: InstanceType) -> bool

Returns true if self accepts values of the given type, according to the [instance_type] field.

This is a basic check that always returns true if no instance_type is specified on the schema, and does not check any subschemas. Because of this, both {} and {"not": {}} accept any type according to this method.

Source

pub fn metadata(&mut self) -> &mut Metadata

Returns a mutable reference to this schema’s Metadata, creating it if it was None.

Source

pub fn subschemas(&mut self) -> &mut SubschemaValidation

Returns a mutable reference to this schema’s SubschemaValidation, creating it if it was None.

Source

pub fn number(&mut self) -> &mut NumberValidation

Returns a mutable reference to this schema’s NumberValidation, creating it if it was None.

Source

pub fn string(&mut self) -> &mut StringValidation

Returns a mutable reference to this schema’s StringValidation, creating it if it was None.

Source

pub fn array(&mut self) -> &mut ArrayValidation

Returns a mutable reference to this schema’s ArrayValidation, creating it if it was None.

Source

pub fn object(&mut self) -> &mut ObjectValidation

Returns a mutable reference to this schema’s ObjectValidation, creating it if it was None.

Trait Implementations§

Source§

impl Clone for SchemaObject

Source§

fn clone(&self) -> SchemaObject

Returns a copy 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 SchemaObject

Source§

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

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

impl Default for SchemaObject

Source§

fn default() -> SchemaObject

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

impl<'de> Deserialize<'de> for SchemaObject

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<Schema> for SchemaObject

Source§

fn from(schema: Schema) -> Self

Converts to this type from the input type.
Source§

impl From<SchemaObject> for Schema

Source§

fn from(o: SchemaObject) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for SchemaObject

Source§

fn eq(&self, other: &SchemaObject) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for SchemaObject

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for SchemaObject

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

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

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

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,