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 description(&mut self, description: impl Into<String>) -> &mut Self
pub fn description(&mut self, description: impl Into<String>) -> &mut Self
Add a description about this schema.
Sourcepub fn to_string_pretty(&self) -> Result<String>
pub fn to_string_pretty(&self) -> Result<String>
Trait Implementations§
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