validator-api: reenable swagger openapi (#1249)
* validator-api: reenable swagger openapi * rustfmt * validator-api: rename openapi tag to status
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
// Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use rocket::fairing::AdHoc;
|
||||
use rocket_okapi::openapi_get_routes;
|
||||
use okapi::openapi3::OpenApi;
|
||||
use rocket::Route;
|
||||
use rocket_okapi::{openapi_get_routes_spec, settings::OpenApiSettings};
|
||||
use std::time::Duration;
|
||||
|
||||
pub(crate) mod local_guard;
|
||||
@@ -15,39 +16,32 @@ pub(crate) const FIFTEEN_MINUTES: Duration = Duration::from_secs(900);
|
||||
pub(crate) const ONE_HOUR: Duration = Duration::from_secs(3600);
|
||||
pub(crate) const ONE_DAY: Duration = Duration::from_secs(86400);
|
||||
|
||||
pub(crate) fn stage_full() -> AdHoc {
|
||||
AdHoc::on_ignite("Node Status API Stage", |rocket| async {
|
||||
rocket.mount(
|
||||
"/v1/status",
|
||||
openapi_get_routes![
|
||||
routes::mixnode_report,
|
||||
routes::gateway_report,
|
||||
routes::mixnode_uptime_history,
|
||||
routes::gateway_uptime_history,
|
||||
routes::mixnode_core_status_count,
|
||||
routes::gateway_core_status_count,
|
||||
routes::get_mixnode_status,
|
||||
routes::get_mixnode_reward_estimation,
|
||||
routes::get_mixnode_stake_saturation,
|
||||
routes::get_mixnode_inclusion_probability,
|
||||
routes::get_mixnode_avg_uptime,
|
||||
routes::get_mixnode_avg_uptimes,
|
||||
],
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
// in the minimal variant we would not have access to endpoints relying on existence
|
||||
// of the network monitor and the associated storage
|
||||
pub(crate) fn stage_minimal() -> AdHoc {
|
||||
AdHoc::on_ignite("Node Status API Stage", |rocket| async {
|
||||
rocket.mount(
|
||||
"/v1/status",
|
||||
openapi_get_routes![
|
||||
routes::get_mixnode_status,
|
||||
routes::get_mixnode_stake_saturation,
|
||||
routes::get_mixnode_inclusion_probability,
|
||||
],
|
||||
)
|
||||
})
|
||||
pub(crate) fn node_status_routes(
|
||||
settings: &OpenApiSettings,
|
||||
enabled: bool,
|
||||
) -> (Vec<Route>, OpenApi) {
|
||||
if enabled {
|
||||
openapi_get_routes_spec![
|
||||
settings: routes::mixnode_report,
|
||||
routes::gateway_report,
|
||||
routes::mixnode_uptime_history,
|
||||
routes::gateway_uptime_history,
|
||||
routes::mixnode_core_status_count,
|
||||
routes::gateway_core_status_count,
|
||||
routes::get_mixnode_status,
|
||||
routes::get_mixnode_reward_estimation,
|
||||
routes::get_mixnode_stake_saturation,
|
||||
routes::get_mixnode_inclusion_probability,
|
||||
routes::get_mixnode_avg_uptime,
|
||||
routes::get_mixnode_avg_uptimes,
|
||||
]
|
||||
} else {
|
||||
// in the minimal variant we would not have access to endpoints relying on existence
|
||||
// of the network monitor and the associated storage
|
||||
openapi_get_routes_spec![
|
||||
routes::get_mixnode_status,
|
||||
routes::get_mixnode_stake_saturation,
|
||||
routes::get_mixnode_inclusion_probability,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ use validator_api_requests::models::{
|
||||
|
||||
use super::models::Uptime;
|
||||
|
||||
#[openapi(tag = "mixnode")]
|
||||
#[openapi(tag = "status")]
|
||||
#[get("/mixnode/<identity>/report")]
|
||||
pub(crate) async fn mixnode_report(
|
||||
storage: &State<ValidatorApiStorage>,
|
||||
@@ -33,7 +33,7 @@ pub(crate) async fn mixnode_report(
|
||||
.map_err(|err| ErrorResponse::new(err.to_string(), Status::NotFound))
|
||||
}
|
||||
|
||||
#[openapi(tag = "mixnode")]
|
||||
#[openapi(tag = "status")]
|
||||
#[get("/gateway/<identity>/report")]
|
||||
pub(crate) async fn gateway_report(
|
||||
storage: &State<ValidatorApiStorage>,
|
||||
@@ -46,7 +46,7 @@ pub(crate) async fn gateway_report(
|
||||
.map_err(|err| ErrorResponse::new(err.to_string(), Status::NotFound))
|
||||
}
|
||||
|
||||
#[openapi(tag = "mixnode")]
|
||||
#[openapi(tag = "status")]
|
||||
#[get("/mixnode/<identity>/history")]
|
||||
pub(crate) async fn mixnode_uptime_history(
|
||||
storage: &State<ValidatorApiStorage>,
|
||||
@@ -59,7 +59,7 @@ pub(crate) async fn mixnode_uptime_history(
|
||||
.map_err(|err| ErrorResponse::new(err.to_string(), Status::NotFound))
|
||||
}
|
||||
|
||||
#[openapi(tag = "mixnode")]
|
||||
#[openapi(tag = "status")]
|
||||
#[get("/gateway/<identity>/history")]
|
||||
pub(crate) async fn gateway_uptime_history(
|
||||
storage: &State<ValidatorApiStorage>,
|
||||
@@ -72,7 +72,7 @@ pub(crate) async fn gateway_uptime_history(
|
||||
.map_err(|err| ErrorResponse::new(err.to_string(), Status::NotFound))
|
||||
}
|
||||
|
||||
#[openapi(tag = "mixnode")]
|
||||
#[openapi(tag = "status")]
|
||||
#[get("/mixnode/<identity>/core-status-count?<since>")]
|
||||
pub(crate) async fn mixnode_core_status_count(
|
||||
storage: &State<ValidatorApiStorage>,
|
||||
@@ -90,7 +90,7 @@ pub(crate) async fn mixnode_core_status_count(
|
||||
})
|
||||
}
|
||||
|
||||
#[openapi(tag = "mixnode")]
|
||||
#[openapi(tag = "status")]
|
||||
#[get("/gateway/<identity>/core-status-count?<since>")]
|
||||
pub(crate) async fn gateway_core_status_count(
|
||||
storage: &State<ValidatorApiStorage>,
|
||||
@@ -108,7 +108,7 @@ pub(crate) async fn gateway_core_status_count(
|
||||
})
|
||||
}
|
||||
|
||||
#[openapi(tag = "mixnode")]
|
||||
#[openapi(tag = "status")]
|
||||
#[get("/mixnode/<identity>/status")]
|
||||
pub(crate) async fn get_mixnode_status(
|
||||
cache: &State<ValidatorCache>,
|
||||
@@ -119,7 +119,7 @@ pub(crate) async fn get_mixnode_status(
|
||||
})
|
||||
}
|
||||
|
||||
#[openapi(tag = "mixnode")]
|
||||
#[openapi(tag = "status")]
|
||||
#[get("/mixnode/<identity>/reward-estimation")]
|
||||
pub(crate) async fn get_mixnode_reward_estimation(
|
||||
cache: &State<ValidatorCache>,
|
||||
@@ -175,7 +175,7 @@ pub(crate) async fn get_mixnode_reward_estimation(
|
||||
}
|
||||
}
|
||||
|
||||
#[openapi(tag = "mixnode")]
|
||||
#[openapi(tag = "status")]
|
||||
#[get("/mixnode/<identity>/stake-saturation")]
|
||||
pub(crate) async fn get_mixnode_stake_saturation(
|
||||
cache: &State<ValidatorCache>,
|
||||
@@ -204,7 +204,7 @@ pub(crate) async fn get_mixnode_stake_saturation(
|
||||
}
|
||||
}
|
||||
|
||||
#[openapi(tag = "mixnode")]
|
||||
#[openapi(tag = "status")]
|
||||
#[get("/mixnode/<identity>/inclusion-probability")]
|
||||
pub(crate) async fn get_mixnode_inclusion_probability(
|
||||
cache: &State<ValidatorCache>,
|
||||
@@ -254,7 +254,7 @@ async fn average_mixnode_uptime(
|
||||
})
|
||||
}
|
||||
|
||||
#[openapi(tag = "mixnode")]
|
||||
#[openapi(tag = "status")]
|
||||
#[get("/mixnode/<identity>/avg_uptime")]
|
||||
pub(crate) async fn get_mixnode_avg_uptime(
|
||||
cache: &State<ValidatorCache>,
|
||||
@@ -270,7 +270,7 @@ pub(crate) async fn get_mixnode_avg_uptime(
|
||||
}))
|
||||
}
|
||||
|
||||
#[openapi(tag = "mixnode")]
|
||||
#[openapi(tag = "status")]
|
||||
#[get("/mixnodes/avg_uptime")]
|
||||
pub(crate) async fn get_mixnode_avg_uptimes(
|
||||
cache: &State<ValidatorCache>,
|
||||
|
||||
Reference in New Issue
Block a user