diff --git a/utoipa-swagger-ui/Cargo.toml b/utoipa-swagger-ui/Cargo.toml index fb451c96..83a5f8ac 100644 --- a/utoipa-swagger-ui/Cargo.toml +++ b/utoipa-swagger-ui/Cargo.toml @@ -15,7 +15,7 @@ debug = [] debug-embed = ["rust-embed/debug-embed"] [dependencies] -rust-embed = { version = "8", features = ["interpolate-folder-path"] } +rust-embed = { version = "8" } mime_guess = { version = "2.0" } actix-web = { version = "4", optional = true, default-features = false } rocket = { version = "0.5.0-rc.3", features = ["json"], optional = true } diff --git a/utoipa-swagger-ui/build.rs b/utoipa-swagger-ui/build.rs index 49e3dcaa..eb65cd81 100644 --- a/utoipa-swagger-ui/build.rs +++ b/utoipa-swagger-ui/build.rs @@ -13,10 +13,8 @@ const SWAGGER_UI_DIST_ZIP: &str = "swagger-ui-5.3.1"; fn main() { println!("cargo:rerun-if-changed=res/{SWAGGER_UI_DIST_ZIP}.zip"); - println!("cargo:rustc-env=UTOIPA_SWAGGER_UI_VERSION={SWAGGER_UI_DIST_ZIP}"); let target_dir = env::var("OUT_DIR").unwrap(); - println!("cargo:rustc-env=UTOIPA_SWAGGER_DIR={}", &target_dir); let swagger_ui_zip = File::open( ["res", &format!("{SWAGGER_UI_DIST_ZIP}.zip")] @@ -29,6 +27,8 @@ fn main() { extract_within_path(&mut zip, [SWAGGER_UI_DIST_ZIP, "dist"], &target_dir).unwrap(); replace_default_url_with_config(&target_dir); + + write_embed_code(&target_dir, &SWAGGER_UI_DIST_ZIP); } fn extract_within_path( @@ -96,3 +96,17 @@ fn replace_default_url_with_config(target_dir: &str) { fs::write(&path, replaced_swagger_initializer.as_ref()).unwrap(); } + +fn write_embed_code(target_dir: &str, swagger_version: &str) { + let contents = format!( + r#" +// This file is auto-generated during compilation, do not modify +#[derive(RustEmbed)] +#[folder = "{}/{}/dist/"] +struct SwaggerUiDist; +"#, + target_dir, swagger_version + ); + let path = [target_dir, "embed.rs"].iter().collect::(); + fs::write(&path, &contents).unwrap(); +} diff --git a/utoipa-swagger-ui/src/lib.rs b/utoipa-swagger-ui/src/lib.rs index 1ad06339..211cf01e 100644 --- a/utoipa-swagger-ui/src/lib.rs +++ b/utoipa-swagger-ui/src/lib.rs @@ -120,9 +120,7 @@ use serde::Serialize; #[cfg(any(feature = "actix-web", feature = "rocket", feature = "axum"))] use utoipa::openapi::OpenApi; -#[derive(RustEmbed)] -#[folder = "$UTOIPA_SWAGGER_DIR/$UTOIPA_SWAGGER_UI_VERSION/dist/"] -struct SwaggerUiDist; +include!(concat!(env!("OUT_DIR"), "/embed.rs")); /// Entry point for serving Swagger UI and api docs in application. It provides /// builder style chainable configuration methods for configuring api doc urls.