pub enum Schema {
Bool(bool),
Object(SchemaObject),
}
Expand description
A JSON Schema.
Variants
Bool(bool)
A trivial boolean JSON Schema.
The schema true
matches everything (always passes validation), whereas the schema false
matches nothing (always fails validation).
Object(SchemaObject)
A JSON Schema object.
Implementations
sourceimpl Schema
impl Schema
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
is a SchemaObject
with Some
reference
set, this returns true
.
Otherwise, returns false
.
sourcepub fn into_object(self) -> SchemaObject
pub fn into_object(self) -> SchemaObject
Converts the given schema (if it is a boolean schema) into an equivalent schema object.
If the given schema is already a schema object, this has no effect.
Example
use schemars::schema::{Schema, SchemaObject};
let bool_schema = Schema::Bool(true);
assert_eq!(bool_schema.into_object(), SchemaObject::default());
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Schema
impl<'de> Deserialize<'de> for Schema
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
Performs the conversion.
impl StructuralPartialEq for Schema
Auto Trait Implementations
impl RefUnwindSafe for Schema
impl Send for Schema
impl Sync for Schema
impl Unpin for Schema
impl UnwindSafe for Schema
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub 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.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more