#[cfg(not(feature = "schemars-export"))]
fn main() {
eprintln!(
"export_schema requires the `schemars-export` feature:\n \
cargo run -p oharness-core --example export_schema \
--features schemars-export"
);
std::process::exit(2);
}
#[cfg(feature = "schemars-export")]
fn main() -> std::io::Result<()> {
use oharness_core::Event;
use std::path::PathBuf;
let schema = schemars::schema_for!(Event);
let json = serde_json::to_string_pretty(&schema).expect("serialize schema");
let json = format!("{json}\n");
let out: PathBuf = [env!("CARGO_MANIFEST_DIR"), "schema", "events-v1.0.json"]
.iter()
.collect();
std::fs::create_dir_all(out.parent().unwrap())?;
std::fs::write(&out, json.as_bytes())?;
println!("wrote {}", out.display());
Ok(())
}