use clap::Parser; use openapi_parser::{build_tree, parse_schema}; /// Dump the tree structure of a schema element as dot file #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] struct Args { /// The name of the file to dump /// /// If this value is unspecified, the default petstore schema /// is used instead #[arg(short, long)] file_name: Option, /// The name of the structure to dump #[arg(short, long, default_value = "Pet")] struct_name: String, } fn main() { env_logger::init_from_env(env_logger::Env::new().default_filter_or("info")); let args = Args::parse(); let file_content = match args.file_name { None => include_str!("../examples/petstore.yaml").to_string(), Some(path) => std::fs::read_to_string(path).expect("Unable to load schema file!"), }; let schema = parse_schema(&file_content); let tree = build_tree(&args.struct_name, schema.components.as_ref().unwrap()); println!("{:#?}", tree); }