pub struct Schema {
pub schema: Option<Draft>,
pub id: Option<String>,
pub title: String,
pub description: Option<String>,
/* private fields */
}Expand description
This is a structure representing the JSON schema itself.
Create Schema
See the documentation top for usage.
To JSON schema string
#[derive(Debug, Schematic)]
struct Example {
#[rschema(field(
title = "Dummy",
description = "Dummy field",
))]
dummy: String,
}
fn main() -> rschema::Result<()> {
let schema_str = Schema::new::<Example>("Example")
.to_string()?;
assert_eq!(
schema_str,
r#"{"title":"Example","type":"object","properties":{"dummy":{"title":"Dummy","description":"Dummy field","type":"string"}},"additionalProperties":false}"#
);
Ok(())
}Use to_string_pretty to generate as a pretty-prited string.
Fields
schema: Option<Draft>id: Option<String>title: Stringdescription: Option<String>Implementations
sourceimpl Schema
impl Schema
sourcepub fn new<T>(title: &str) -> Schema where
T: Schematic,
pub fn new<T>(title: &str) -> Schema where
T: Schematic,
Create a schema object from the given type T.
sourcepub fn description(&mut self, description: impl Into<String>) -> &mut Schema
pub fn description(&mut self, description: impl Into<String>) -> &mut Schema
Add a description about this schema.
sourcepub fn to_string_pretty(&self) -> Result<String, Error>
pub fn to_string_pretty(&self) -> Result<String, Error>
Trait Implementations
sourceimpl Serialize for Schema
impl Serialize for Schema
sourcefn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
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 · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more