to_json_schema/
to-json-schema.rs1use jsona::dom::{Keys, Node};
2use jsona_schema::Schema;
3fn main() {
4 let mut args = std::env::args();
5 let jsona_file = args
6 .nth(1)
7 .expect("Usage: to-json-schema <jsona-file> [keys]");
8 let keys = args.next();
9 let jsona_file_path = std::path::Path::new(&jsona_file);
10 let jsona_content = std::fs::read_to_string(jsona_file_path).unwrap();
11 let node: Node = jsona_content.parse().unwrap();
12 let schema: Schema = Schema::try_from(&node).unwrap();
13 let result = match keys {
14 Some(keys) => {
15 let keys: Keys = keys.parse().unwrap();
16 serde_json::to_string_pretty(&schema.pointer(&keys)).unwrap()
17 }
18 None => serde_json::to_string_pretty(&schema).unwrap(),
19 };
20 println!("{}", result);
21}