2025-06-03 19:50:43 +02:00

29 lines
901 B
Rust

use std::{fs::{exists, read_dir, remove_dir_all, File}, io::Write, process::Command};
fn main() {
if exists("src/models").unwrap() {
remove_dir_all("src/models").unwrap();
}
let _ =
Command::new("openapi-generator")
.args(["generate", "-i", "gamenight-api.yaml", "-g", "rust", "--global-property", "models"])
.output()
.expect("Failed to generate models sources for the gamenight API");
let mut file = File::create("src/models/mod.rs").unwrap();
let paths = read_dir("./src/models").unwrap();
for path in paths {
let path = path.unwrap();
let path = path.path();
let stem = path.file_stem().unwrap();
if stem == "mod" {
continue
}
let line = format!("pub mod {};\n", stem.to_str().unwrap());
let _ = file.write(line.as_bytes()).unwrap();
}
}