Struct rschema_core::Schema
source · [−]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
sourceimpl 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 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