hive-c0re: drop utoipa-swagger-ui, serve openapi.json directly

Swagger UI itself is nginx-hosted now (iris's 86a39c4c), so c0re
carrying its own vendored copy via utoipa-swagger-ui was a straight
duplicate — dropped the dependency (root Cargo.toml + hive-c0re's),
swapped the SwaggerUi::new(...).url(...) mount for a plain
/api/openapi.json GET route serving the same OpenApi doc as JSON.

Verified: cargo build/clippy/test -p hive-c0re clean, Cargo.lock
dropped utoipa-swagger-ui + utoipa-swagger-ui-vendored with no other
changes, nix fmt clean.
This commit is contained in:
damocles 2026-08-02 21:09:28 +02:00 committed by mara
commit f457d9ce7b
4 changed files with 16 additions and 124 deletions

View file

@ -7,18 +7,23 @@ use std::sync::Arc;
use anyhow::{Context, Result};
use axum::{
Json,
http::StatusCode,
response::{IntoResponse, Response},
routing::get,
};
use utoipa::OpenApi;
use utoipa_axum::{router::OpenApiRouter, routes};
use utoipa_swagger_ui::SwaggerUi;
use crate::coordinator::Coordinator;
use crate::lifecycle;
/// Root of the auto-generated `OpenAPI` spec (`/api/openapi.json`, browsable
/// at `/api/docs`) — see [`utoipa`]. Only routes carrying a
/// Root of the auto-generated `OpenAPI` spec, served raw at
/// `/api/openapi.json` — see [`utoipa`]. Swagger UI itself (browsable at
/// `/api/docs`) is nginx-hosted straight from the nix store now (see
/// `nix/host-modules/hive-gateway/vhosts.nix`'s `swaggerUiLocations`);
/// c0re only needs to serve the JSON this route generates, not the whole
/// vendored UI. Only routes carrying a
/// `#[utoipa::path(...)]` annotation show up; the rest of the (much
/// larger) route table below is undocumented for now. Deliberately
/// incremental: an unannotated route just doesn't appear in the spec,
@ -206,8 +211,15 @@ pub async fn serve(
.routes(routes!(state_snapshot::dashboard_stream))
.routes(routes!(state_snapshot::dashboard_history))
.split_for_parts();
// Just the JSON, not the UI — Swagger UI itself is nginx-hosted from
// the nix store (see the module doc comment above `ApiDoc`). `api`
// is `Clone`; each request gets its own owned copy for `Json` to
// serialize.
let app = router
.merge(SwaggerUi::new("/api/docs").url("/api/openapi.json", api))
.route(
"/api/openapi.json",
get(move || async move { Json(api.clone()) }),
)
.with_state(AppState {
coord,
webhook_secret,