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: String§description: Option<String>Implementations§
Source§impl Schema
impl Schema
Sourcepub fn new<T>(title: &str) -> Schemawhere
T: Schematic,
pub fn new<T>(title: &str) -> Schemawhere
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§
Source§impl Serialize for Schema
impl Serialize for Schema
Source§fn 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 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