ocsf_codegen/
objects.rs

1use serde::{Deserialize, Serialize};
2
3use crate::module::Module;
4use crate::*;
5
6// TODO: objects from the objects dir
7
8#[derive(Debug, Serialize, Deserialize)]
9struct ObjectDef {
10    caption: String,
11    description: String,
12    name: String,
13    extends: Option<String>,
14    // #[serde(skip)]
15    attributes: HashMap<String, Value>,
16
17    constraints: Option<HashMap<String, Vec<String>>>,
18}
19
20pub fn generate_objects(paths: &DirPaths, root_module: &mut Module) -> Result<(), Box<dyn Error>> {
21    // let mut output_scope = codegen::Scope::new();
22    let object_module = root_module
23        .children
24        .get_mut("objects")
25        .expect("Couldn't get objects module from root?");
26
27    object_module.scope.writeln("//* hello world");
28
29    for filename in find_files(&format!("{}objects/", &paths.schema_path)) {
30        debug!("Object file: {filename:?}");
31
32        let file_value = read_file_to_value(&filename)?;
33        let objectdef: ObjectDef = serde_json::from_value(file_value)?;
34
35        trace!("Object Def: {objectdef:#?}");
36    }
37
38    write_source_file(
39        &format!("{}src/objects.rs", paths.destination_path),
40        &object_module.scope.to_string(),
41    )
42}