diff --git a/crates/aide/Cargo.toml b/crates/aide/Cargo.toml index 76e8889..17cc427 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 0000000..61f716f --- /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(); +}