use std::io::Write;
use schemars::schema_for;
use serde_json::json;
use crate::{config::StoredConfig, error::Error, output::Event};
pub const ZENOPS_VERSION: &str = env!("CARGO_PKG_VERSION");
pub fn run(stdout: &mut dyn Write) -> Result<(), Error> {
let bundle = json!({
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": format!("https://github.com/bjorn-ove/zenops/schema/v{ZENOPS_VERSION}"),
"title": "zenops schema bundle",
"zenops_version": ZENOPS_VERSION,
"schemas": {
"output_event": schema_for!(Event),
"config": schema_for!(StoredConfig),
}
});
let mut rendered = serde_json::to_vec_pretty(&bundle).map_err(Error::SchemaEmit)?;
rendered.push(b'\n');
stdout.write_all(&rendered).map_err(Error::SchemaWrite)?;
Ok(())
}