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

Create a schema object from the given type T.

Add a description about this schema.

Specify $schema.

Specify $id.

Generate a JSON schema string.

Errors

Internally calls serde_json::to_string, so this can fail if it fails. Read more

Generate a pretty-printed JSON schema string.

Errors

Internally calls serde_json::to_string_pretty, so this can fail if it fails. Read more

Write a JSON schema string to a file.

Errors

This call can fail if its own to_string call or writing to a file fails.

Write a pretty-printed JSON schema string to a file.

Errors

This call can fail if its own to_string_pretty call or writing to a file fails.

Trait Implementations

Formats the value using the given formatter. Read more

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.