Autogenerate only the models of the API for the backend-server

This commit is contained in:
2025-05-30 22:26:18 +02:00
parent 597a960bf1
commit 6950ac62e8
9 changed files with 95 additions and 289 deletions

24
backend-actix/build.rs Normal file
View File

@@ -0,0 +1,24 @@
use std::{fs::{self, File}, io::Write, process::Command};
fn main() {
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 = fs::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());
file.write(line.as_bytes()).unwrap();
}
}