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§
source§impl 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§
source§impl<'de> Deserialize<'de> for Schema
impl<'de> Deserialize<'de> for Schema
source§fn 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
source§impl From<Schema> for SchemaObject
impl From<Schema> for SchemaObject
source§impl From<SchemaObject> for Schema
impl From<SchemaObject> for Schema
source§fn from(o: SchemaObject) -> Self
fn from(o: SchemaObject) -> Self
Converts to this type from the input type.
impl StructuralPartialEq for Schema
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)