aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md4
-rw-r--r--Cargo.toml10
-rw-r--r--README.md5
-rw-r--r--docs/api.md3
-rw-r--r--docs/architecture.md2
-rw-r--r--docs/development.md5
-rw-r--r--src/api/mod.rs16
7 files changed, 31 insertions, 14 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fe0ba3e..81db46c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -36,6 +36,10 @@ it from the release before ([`docs/operations.md`](docs/operations.md),
([`docs/configuration.md`](docs/configuration.md),
[Importing values](docs/configuration.md#importing-values)).
+* The Swagger UI (`/swagger-ui`) is a feature, `swagger-ui`, no longer built into every
+ node: a build that is to serve it names the feature. `/openapi.yaml` is served as
+ before ([`docs/development.md`](docs/development.md)).
+
* `--libp2p-ping-interval`: how often libp2p pings each connection, 15 s as before
unless given, `0` for once as it opens; and `--worker-threads`: how many threads take
the node's work in turns, as many as the machine has cores unless given. Both for
diff --git a/Cargo.toml b/Cargo.toml
index f970ab9..93046a3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -42,8 +42,12 @@ tor = [
"dep:tor-rtcompat",
"dep:safelog",
]
-# Every feature above but tokio-console, for development: builds, checks and tests with
-# one set of features don't rebuild what another set built. Not a default.
+# The Swagger UI showing the API (`/swagger-ui`): its files are built into the node.
+# Without it, the node serves the description alone (`/openapi.yaml`).
+swagger-ui = ["dep:utoipa-swagger-ui"]
+# Every feature above but tokio-console and swagger-ui, for development: builds, checks
+# and tests with one set of features don't rebuild what another set built. Not a
+# default.
most = ["dashboard", "federation", "libp2p", "mycelium", "tor"]
[dependencies]
@@ -102,7 +106,7 @@ tokio = { version = "1.53", features = ["full"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt"] }
url = "2.5"
-utoipa-swagger-ui = { version = "10", features = ["axum"] }
+utoipa-swagger-ui = { version = "10", features = ["axum"], optional = true }
uuid = { version = "1", features = ["v4"] }
# A quick development loop (docs/development.md): line numbers in backtraces but no
diff --git a/README.md b/README.md
index 4e61ec4..c26a6cd 100644
--- a/README.md
+++ b/README.md
@@ -41,7 +41,8 @@ coordination on it.
```sh
# The transports are cargo features: mycelium, libp2p, tor (any, at least one);
-# dashboard adds the live page (`/admin/dashboard`).
+# dashboard adds the live page (`/admin/dashboard`), swagger-ui a page showing the API
+# (`/swagger-ui`).
cargo build --release --features mycelium,dashboard
# An HTTP API user (Argon2 hash; e.g. with the `argon2` command-line tool).
@@ -112,7 +113,7 @@ What changed from one release to the next: [`CHANGELOG.md`](CHANGELOG.md).
* [`docs/api.md`](docs/api.md): the store API for applications: consistency, concurrent writes,
streams.
* [`docs/openapi.yaml`](docs/openapi.yaml): the HTTP API (also served at `/openapi.yaml`, with a Swagger
- UI at `/swagger-ui`).
+ UI at `/swagger-ui` in a build with the feature `swagger-ui`).
**Working on continuum**
diff --git a/docs/api.md b/docs/api.md
index 957030f..75442b3 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -2,7 +2,8 @@
What an application can rely on when it reads and writes through a node's HTTP API. The
endpoints and their answers, one by one, are in [`openapi.yaml`](openapi.yaml) (served by every node at
-`/openapi.yaml`, with a Swagger UI at `/swagger-ui`); this page is about what they mean
+`/openapi.yaml`, and shown by a Swagger UI at `/swagger-ui` where a node is built with the
+feature `swagger-ui`); this page is about what they mean
together.
## The model
diff --git a/docs/architecture.md b/docs/architecture.md
index 124fcf5..00db38a 100644
--- a/docs/architecture.md
+++ b/docs/architecture.md
@@ -163,7 +163,7 @@ Prometheus), `document` (backup export), `log` (filter at runtime), `config`
Argon2), [`dashboard/`](../src/api/dashboard/) (with the `dashboard` feature: the page and its events;
[`dashboard.md`](dashboard.md)), and [`mod.rs`](../src/api/mod.rs) (router, protocol-path rules). The remake routes
come from [`remake/api.rs`](../src/remake/api.rs). [`docs/openapi.yaml`](openapi.yaml) describes it all; nodes serve it at
-`/openapi.yaml`, with a Swagger UI at `/swagger-ui`.
+`/openapi.yaml`, with a Swagger UI at `/swagger-ui` where built with the feature `swagger-ui`.
**Top level** — continuum is a library: its `run` ([`lib.rs`](../src/lib.rs)), which the node's
binary ([`main.rs`](../src/main.rs)) calls, reads the configuration, picks the starting document and
diff --git a/docs/development.md b/docs/development.md
index 7a8f7e6..b782511 100644
--- a/docs/development.md
+++ b/docs/development.md
@@ -22,6 +22,11 @@ and dependencies with it (`--features libp2p` builds neither `reqwest` and the d
supervision of Mycelium, nor arti; among Mycelium's tests is a swarm simulated on its
envelope).
+The Swagger UI (`/swagger-ui`) is a feature too, `swagger-ui`, and not among `most`: its
+files, some megabytes, are built into the node, and its build fetches them from GitHub
+(`SWAGGER_UI_DOWNLOAD_URL` names another place, a `file://` URL among them). A node
+without it serves the API's description alone (`/openapi.yaml`).
+
The benchmarks are ignored tests named `bench_*`: the document's (writes and sync
messages, what signing and checking every change would cost: `bench_change_signatures`,
knowing every change's paths: `bench_change_paths`, and judging every change while
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));