Compare commits
2 Commits
8d1bf2dfb0
...
90ad7cfe45
| Author | SHA1 | Date | |
|---|---|---|---|
| 90ad7cfe45 | |||
| 235e32d29a |
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -221,7 +221,7 @@ checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66"
|
||||
|
||||
[[package]]
|
||||
name = "openapi-parser"
|
||||
version = "0.4.4"
|
||||
version = "0.4.5"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"env_logger",
|
||||
|
||||
@@ -4,7 +4,7 @@ description = "Extract schemas definitions tree from OpenAPI documents"
|
||||
authors = ["Pierre Hubert <pierre.hubert.git@communiquons.org>"]
|
||||
license = "MIT"
|
||||
repository = "https://gitea.communiquons.org/pierre/OpenAPI-Parser"
|
||||
version = "0.4.4"
|
||||
version = "0.4.5"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
21
src/main.rs
21
src/main.rs
@@ -2,6 +2,7 @@ use clap::{Parser, Subcommand};
|
||||
use openapi_parser::{
|
||||
build_tree, parse_schema, parse_schema_fix_example_issue, NodeType, ObjectChild, TreeNode,
|
||||
};
|
||||
use std::collections::HashSet;
|
||||
use std::fmt::Write;
|
||||
|
||||
/// Dump the tree structure of a schema element as dot file
|
||||
@@ -78,7 +79,17 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
fn recurse_export(node: &TreeNode, parent_name: &str, out: &mut String) {
|
||||
fn recurse_export(
|
||||
node: &TreeNode,
|
||||
parent_name: &str,
|
||||
out: &mut String,
|
||||
already_processed: &mut HashSet<String>,
|
||||
) {
|
||||
if already_processed.contains(&node.name) {
|
||||
return;
|
||||
}
|
||||
already_processed.insert(node.name.to_string());
|
||||
|
||||
if !parent_name.is_empty() && matches!(node.r#type, NodeType::Object { .. }) {
|
||||
writeln!(out, "\"{}\" -> \"{}\";", parent_name, node.name).unwrap();
|
||||
}
|
||||
@@ -87,11 +98,11 @@ fn recurse_export(node: &TreeNode, parent_name: &str, out: &mut String) {
|
||||
NodeType::Array { item } => {
|
||||
let mut item = item.clone();
|
||||
item.name.push_str(" []");
|
||||
recurse_export(&item, parent_name, out);
|
||||
recurse_export(&item, parent_name, out, already_processed);
|
||||
}
|
||||
NodeType::Object { children, .. } => {
|
||||
for child in children {
|
||||
recurse_export(&child.node, &node.name, out);
|
||||
recurse_export(&child.node, &node.name, out, already_processed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +113,9 @@ fn recurse_export(node: &TreeNode, parent_name: &str, out: &mut String) {
|
||||
fn graphviz_export(tree: &TreeNode) -> String {
|
||||
let mut out = "digraph G {\n".to_string();
|
||||
|
||||
recurse_export(tree, "", &mut out);
|
||||
let mut already_processed = HashSet::new();
|
||||
|
||||
recurse_export(tree, "", &mut out, &mut already_processed);
|
||||
|
||||
out.push_str("}\n");
|
||||
out
|
||||
|
||||
Reference in New Issue
Block a user