Can output parsed tree as JSON
This commit is contained in:
parent
9be4e5ee89
commit
250fdb9f82
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -230,6 +230,8 @@ dependencies = [
|
||||
"env_logger",
|
||||
"log",
|
||||
"okapi",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_yaml",
|
||||
]
|
||||
|
||||
|
@ -10,4 +10,6 @@ log = "0.4.17"
|
||||
env_logger = "0.10.0"
|
||||
clap = { version = "4.1.1", features = ["derive"] }
|
||||
okapi = "0.7.0-rc.1"
|
||||
serde = { version = "1.0.152", features = ["derive"] }
|
||||
serde_yaml = "0.9.17"
|
||||
serde_json = "1.0.91"
|
||||
|
@ -29,7 +29,8 @@ fn expect_schema_object(s: &Schema) -> &SchemaObject {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, serde::Serialize)]
|
||||
#[serde(tag = "type")]
|
||||
pub enum NodeType {
|
||||
Null,
|
||||
Boolean,
|
||||
@ -40,9 +41,10 @@ pub enum NodeType {
|
||||
Integer,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, serde::Serialize)]
|
||||
pub struct TreeNode {
|
||||
pub name: String,
|
||||
#[serde(flatten)]
|
||||
pub r#type: NodeType,
|
||||
}
|
||||
|
||||
|
16
src/main.rs
16
src/main.rs
@ -1,4 +1,4 @@
|
||||
use clap::Parser;
|
||||
use clap::{Parser, Subcommand};
|
||||
use openapi_parser::{build_tree, parse_schema};
|
||||
|
||||
/// Dump the tree structure of a schema element as dot file
|
||||
@ -15,6 +15,16 @@ struct Args {
|
||||
/// The name of the structure to dump
|
||||
#[arg(short, long, default_value = "Pet")]
|
||||
struct_name: String,
|
||||
|
||||
/// The action to perform
|
||||
#[clap(subcommand)]
|
||||
action: Action,
|
||||
}
|
||||
|
||||
#[derive(Subcommand, Debug)]
|
||||
enum Action {
|
||||
/// Dump as JSON
|
||||
Json,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@ -30,5 +40,7 @@ fn main() {
|
||||
let schema = parse_schema(&file_content);
|
||||
let tree = build_tree(&args.struct_name, schema.components.as_ref().unwrap());
|
||||
|
||||
println!("{:#?}", tree);
|
||||
match args.action {
|
||||
Action::Json => println!("{}", serde_json::to_string(&tree).unwrap()),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user