OpenAPI-Parser/src/main.rs

35 lines
1.0 KiB
Rust
Raw Normal View History

2023-02-02 11:14:01 +00:00
use clap::Parser;
use openapi_parser::{build_tree, parse_schema};
2023-02-02 11:14:01 +00:00
/// 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<String>,
/// The name of the structure to dump
#[arg(short, long, default_value = "Pet")]
struct_name: String,
}
2023-02-02 09:06:39 +00:00
fn main() {
2023-02-02 11:14:01 +00:00
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);
2023-02-02 11:14:01 +00:00
let tree = build_tree(&args.struct_name, schema.components.as_ref().unwrap());
println!("{:#?}", tree);
}