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>>
The type
keyword.
See JSON Schema Validation 6.1.1. “type” and JSON Schema 4.2.1. Instance Data Model.
format: Option<String>
The format
keyword.
See JSON Schema Validation 7. A Vocabulary for Semantic Content With “format”.
enum_values: Option<Vec<Value>>
The enum
keyword.
const_value: Option<Value>
The const
keyword.
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>
The $ref
keyword.
extensions: Map<String, Value>
Arbitrary extra properties which are not part of the JSON Schema specification, or which schemars
does not support.
Implementations
sourceimpl SchemaObject
impl SchemaObject
sourcepub fn new_ref(reference: String) -> Self
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.
sourcepub fn is_ref(&self) -> bool
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
.
sourcepub fn has_type(&self, ty: InstanceType) -> bool
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.
sourcepub fn metadata(&mut self) -> &mut Metadata
pub fn metadata(&mut self) -> &mut Metadata
Returns a mutable reference to this schema’s Metadata
, creating it if it was None
.
sourcepub fn subschemas(&mut self) -> &mut SubschemaValidation
pub fn subschemas(&mut self) -> &mut SubschemaValidation
Returns a mutable reference to this schema’s SubschemaValidation
, creating it if it was None
.
sourcepub fn number(&mut self) -> &mut NumberValidation
pub fn number(&mut self) -> &mut NumberValidation
Returns a mutable reference to this schema’s NumberValidation
, creating it if it was None
.
sourcepub fn string(&mut self) -> &mut StringValidation
pub fn string(&mut self) -> &mut StringValidation
Returns a mutable reference to this schema’s StringValidation
, creating it if it was None
.
sourcepub fn array(&mut self) -> &mut ArrayValidation
pub fn array(&mut self) -> &mut ArrayValidation
Returns a mutable reference to this schema’s ArrayValidation
, creating it if it was None
.
sourcepub fn object(&mut self) -> &mut ObjectValidation
pub fn object(&mut self) -> &mut ObjectValidation
Returns a mutable reference to this schema’s ObjectValidation
, creating it if it was None
.
Trait Implementations
sourceimpl Clone for SchemaObject
impl Clone for SchemaObject
sourcefn clone(&self) -> SchemaObject
fn clone(&self) -> SchemaObject
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for SchemaObject
impl Debug for SchemaObject
sourceimpl Default for SchemaObject
impl Default for SchemaObject
sourcefn default() -> SchemaObject
fn default() -> SchemaObject
Returns the “default value” for a type. Read more
sourceimpl<'de> Deserialize<'de> for SchemaObject where
SchemaObject: Default,
impl<'de> Deserialize<'de> for SchemaObject where
SchemaObject: Default,
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl From<Schema> for SchemaObject
impl From<Schema> for SchemaObject
sourceimpl From<SchemaObject> for Schema
impl From<SchemaObject> for Schema
sourcefn from(o: SchemaObject) -> Self
fn from(o: SchemaObject) -> Self
Converts to this type from the input type.
sourceimpl PartialEq<SchemaObject> for SchemaObject
impl PartialEq<SchemaObject> for SchemaObject
sourcefn eq(&self, other: &SchemaObject) -> bool
fn eq(&self, other: &SchemaObject) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &SchemaObject) -> bool
fn ne(&self, other: &SchemaObject) -> bool
This method tests for !=
.
sourceimpl Serialize for SchemaObject
impl Serialize for SchemaObject
impl StructuralPartialEq for SchemaObject
Auto Trait Implementations
impl RefUnwindSafe for SchemaObject
impl Send for SchemaObject
impl Sync for SchemaObject
impl Unpin for SchemaObject
impl UnwindSafe for SchemaObject
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more