Allègement du graphe

This commit is contained in:
Pierre HUBERT 2023-02-03 09:06:05 +01:00
parent 8f2b55fede
commit 115f907113

View File

@ -51,17 +51,19 @@ fn main() {
}
fn recurse_export(node: &TreeNode, parent_name: &str, out: &mut String) {
if !parent_name.is_empty() && node.r#type.can_have_children() {
writeln!(out, "\"{}\" -> \"{}\";", parent_name, node.print_name()).unwrap();
if !parent_name.is_empty() && matches!(node.r#type, NodeType::Object { .. }) {
writeln!(out, "\"{}\" -> \"{}\";", parent_name, node.name).unwrap();
}
match &node.r#type {
NodeType::Array { item } => {
recurse_export(item, &node.print_name(), out);
let mut item = item.clone();
item.name.push_str(" []");
recurse_export(&item, parent_name, out);
}
NodeType::Object { children, .. } => {
for child in children {
recurse_export(child, &node.print_name(), out);
recurse_export(child, &node.name, out);
}
}