1use serde::Deserialize;
2
3use crate::*;
4
5#[derive(Deserialize)]
6struct VersionFile {
7 version: String,
8}
9
10pub fn add_version_element(
11 paths: &DirPaths,
12 output_scope: &mut codegen::Scope,
13) -> Result<(), Box<dyn Error>> {
14 let version_file = read_file_to_value(&format!("{}version.json", paths.schema_path))?;
15
16 let schema_version: VersionFile = serde_json::from_value(version_file)?;
17 debug!("OCSF Schema Version: {}", schema_version.version);
18 output_scope.raw(format!(
19 "/// This was the schema version that the code was generated from ({}).",
20 &schema_version.version
21 ));
22 output_scope.raw(format!(
23 "pub static OCSF_SCHEMA_VERSION: &str = {:?};\n\n",
24 schema_version.version
25 ));
26
27 Ok(())
28}
29
30