pub struct Schema { /* private fields */ }Expand description
A JSON Schema object, built a field at a time.
Only the subset every provider agrees on is modelled — an object of named,
typed, described fields, some required. Anything more exotic can still be
handed over with Schema::raw.
Implementations§
Source§impl Schema
impl Schema
pub fn object() -> Schema
Sourcepub fn raw(schema: Json) -> Schema
pub fn raw(schema: Json) -> Schema
Use a schema written out by hand, for shapes this builder does not cover.
Sourcepub fn describe(self, description: impl Into<String>) -> Schema
pub fn describe(self, description: impl Into<String>) -> Schema
Describe the object itself, which some models read as extra instruction.
pub fn string(self, name: &str, description: &str) -> Schema
pub fn integer(self, name: &str, description: &str) -> Schema
pub fn number(self, name: &str, description: &str) -> Schema
pub fn boolean(self, name: &str, description: &str) -> Schema
Sourcepub fn one_of(self, name: &str, description: &str, values: &[&str]) -> Schema
pub fn one_of(self, name: &str, description: &str, values: &[&str]) -> Schema
A string field limited to a fixed set of values.
Sourcepub fn array_of(self, name: &str, description: &str, item_type: &str) -> Schema
pub fn array_of(self, name: &str, description: &str, item_type: &str) -> Schema
An array whose items are all of one primitive type.
Sourcepub fn optional(self) -> Schema
pub fn optional(self) -> Schema
Make the field just added optional.
Fields are required by default because that is what a caller means far
more often, and because an optional field a model omits is a None the
handler has to think about.
pub fn is_empty(&self) -> bool
Trait Implementations§
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 UnsafeUnpin 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