From 1de11da61a106187748c4b79e1d7b63e3b9d172f Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 2 Dec 2026 01:16:49 +0000 Subject: The Swagger UI is a feature, swagger-ui, and not among most Its files were built into every node, some megabytes of each binary, and its build fetches them from GitHub. A build that is to serve /swagger-ui names the feature; /openapi.yaml is served as before. Development builds (most) leave it out. --- src/api/mod.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/api/mod.rs b/src/api/mod.rs index c4265fb..82b5010 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -36,6 +36,7 @@ use axum::{ }; use serde_json::{Value as JsonValue, json}; use tracing::{error, warn}; +#[cfg(feature = "swagger-ui")] use utoipa_swagger_ui::SwaggerUi; use crate::api::auth::{AuthState, basic_auth}; @@ -140,17 +141,18 @@ pub(crate) fn router(state: AppState, auth_state: AuthState, debug_api: bool) -> // Outermost: pages of other origins, and their preflights, which bring no // credentials. .layer(middleware::from_fn_with_state(state.clone(), cors::cors)) - // The hand-written spec (`docs/openapi.yaml`), and the Swagger UI showing it. - .merge( - // Relative to the UI's page (`/swagger-ui/`), so it is found behind a proxy that - // serves the API under a path of its own too. - SwaggerUi::new("/swagger-ui") - .config(utoipa_swagger_ui::Config::from("../openapi.yaml")), - ) + // The hand-written spec (`docs/openapi.yaml`). .route("/openapi.yaml", get(openapi_spec)) // Logging in by key: a challenge, and the token for it signed, without a password. .route("/auth/challenge", axum::routing::post(login::challenge)) .route("/auth/login/key", axum::routing::post(login::login_key)); + // The Swagger UI showing the spec, where it is built in. + #[cfg(feature = "swagger-ui")] + let router = router.merge( + // Relative to the UI's page (`/swagger-ui/`), so it is found behind a proxy that + // serves the API under a path of its own too. + SwaggerUi::new("/swagger-ui").config(utoipa_swagger_ui::Config::from("../openapi.yaml")), + ); // A party's login by its key, on a node holding a federated store. #[cfg(feature = "federation")] let router = router.route("/auth/login/party", axum::routing::post(login::login_party)); -- cgit v1.3.1