Struct schemars::schema::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§

default 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,

§

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>,

§

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>,

§

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>,