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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)