Skip to main content

mina_node_native/http_server/routes/
mod.rs

1//! Route handlers for the axum HTTP server.
2//!
3//! Each submodule groups related endpoints by functionality.
4
5use utoipa::OpenApi;
6use utoipa_axum::router::OpenApiRouter;
7
8use super::{openapi, AppState};
9
10pub mod discovery;
11pub mod graphql;
12pub mod scan_state;
13pub mod snark_pool;
14pub mod snarker;
15pub mod state;
16pub mod stats;
17pub mod status;
18pub mod transaction;
19
20#[cfg(feature = "p2p-webrtc")]
21pub mod webrtc;
22
23/// Builds the OpenAPI router with all documented routes.
24///
25/// This is used by both the HTTP server and for generating the OpenAPI spec.
26pub fn openapi_router() -> OpenApiRouter<AppState> {
27    let router = OpenApiRouter::with_openapi(openapi::ApiDoc::openapi())
28        .merge(status::routes())
29        .merge(state::routes())
30        .merge(stats::routes())
31        .merge(scan_state::routes())
32        .merge(snark_pool::routes())
33        .merge(snarker::routes())
34        .merge(transaction::routes())
35        .merge(discovery::routes());
36
37    #[cfg(feature = "p2p-webrtc")]
38    let router = router.merge(webrtc::routes());
39
40    router
41}
42
43/// Returns the OpenAPI specification for the HTTP API.
44///
45/// This builds the same spec that the running server uses,
46/// without requiring a running server or AppState instance.
47pub fn openapi_spec() -> utoipa::openapi::OpenApi {
48    let (_router, api) = openapi_router().split_for_parts();
49    api
50}