[][src]Function schemafy_snapshot::generate

pub fn generate(
    root_name: Option<&str>,
    schema: &str
) -> Result<String, Box<dyn Error>>

Generate Rust types from a JSON schema.

If the root_name parameter is supplied, then a type will be generated from the root of the schema. If your schema does not define a root type, just pass None.

// build.rs
extern crate schemafy;

fn main() -> Result<(), Box<std::error::Error>> {
    let schema = std::fs::read_to_string("src/schema.json")?;
    let output = schemafy::generate(Some("Schema"), &schema)?;
    std::fs::write("src/schema.rs", output.as_bytes())?;
    Ok(())
}

This is a convenience method. For more options, use GenerateBuilder.