From 19947ab727e835ed808d287b19f8ceeed440d974 Mon Sep 17 00:00:00 2001 From: Max Kutschka <2004maximilian@web.de> Date: Wed, 8 Jan 2025 07:42:25 +0100 Subject: [PATCH] suggestion: custom aide build-script to autoupdate Static Files --- crates/aide/Cargo.toml | 5 +++++ crates/aide/build.rs | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 crates/aide/build.rs diff --git a/crates/aide/Cargo.toml b/crates/aide/Cargo.toml index 76e8889c..17cc4278 100644 --- a/crates/aide/Cargo.toml +++ b/crates/aide/Cargo.toml @@ -8,6 +8,7 @@ license = "MIT OR Apache-2.0" repository = "https://github.com/tamasfe/aide" description = "A code-first API documentation library" readme = "README.md" +build = "build.rs" [dependencies] indexmap = { version = "2.1", features = ["serde"] } @@ -38,6 +39,7 @@ redoc = [] swagger = [] scalar = [] skip_serializing_defaults = [] +update_docs = [] axum = ["dep:axum", "bytes", "http", "dep:tower-layer", "dep:tower-service", "serde_qs?/axum"] axum-headers = ["axum-extra/typed-header"] @@ -59,6 +61,9 @@ jwt-authorizer = ["dep:jwt-authorizer"] serde = { version = "1.0.144", features = ["derive"] } tokio = { version = "1.21.0", features = ["macros", "rt-multi-thread"] } +[build-dependencies] +reqwest = { version = "0.12.12", features = ["blocking"]} + [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "docsrs"] diff --git a/crates/aide/build.rs b/crates/aide/build.rs new file mode 100644 index 00000000..61f716fd --- /dev/null +++ b/crates/aide/build.rs @@ -0,0 +1,22 @@ +use std::env; + +static UPDATE_DOCS_DB: [(&str, &str); 2] = [ + ("./res/swagger/swagger-ui.css", "https://raw.githubusercontent.com/swagger-api/swagger-ui/refs/heads/master/dist/swagger-ui.css"), + ("./res/swagger/swagger-ui-bundle.js", "https://raw.githubusercontent.com/swagger-api/swagger-ui/refs/heads/master/dist/swagger-ui-bundle.js"), +]; + +fn main() { + if env::var("CARGO_FEATURE_UPDATE_DOCS").is_ok() { + for entry in UPDATE_DOCS_DB.iter() { + println!("cargo:rerun-if-changed={}", entry.0); + update_docs(entry); + } + } +} + +fn update_docs(entry: &(&str, &str)) { + reqwest::blocking::get(entry.1) + .unwrap() + .copy_to(&mut std::fs::File::create(entry.0).unwrap()) + .unwrap(); +}