use std::{fs, path::Path}; use typify::{TypeSpace, TypeSpaceSettings}; const SCHEMA_URL: &'static str = "https://raw.githubusercontent.com/versa-protocol/schema"; const SCHEMA_PATH: &'static str = "data/receipt.schema.json"; const SCHEMA_VERSION: &'static str = "1.8.0"; // Update this to the latest version fn main() { let schema_url = format!("{}/{}/{}", SCHEMA_URL, SCHEMA_VERSION, SCHEMA_PATH); // let content = std::fs::read_to_string("../example.json").unwrap(); // get content from url using reqwest as text let content = match reqwest::blocking::get(&schema_url) { Ok(res) => match res.text() { Ok(text) => text, Err(e) => { println!("Error fetching schema version {}: {:?}", SCHEMA_VERSION, e); return; } }, Err(e) => { println!("Error fetching schema version {}: {:?}", SCHEMA_VERSION, e); return; } }; let schema = serde_json::from_str::(&content).unwrap(); let mut type_space = TypeSpace::new(TypeSpaceSettings::default().with_struct_builder(true)); type_space.add_root_schema(schema).unwrap(); let contents = prettyplease::unparse(&syn::parse2::(type_space.to_stream()).unwrap()) .replace("chrono::naive::NaiveDate", "String"); let mut out_file = Path::new("src").to_path_buf(); out_file.push("receipt.rs"); fs::write(out_file, contents).unwrap(); }