Add swagger for validator-api (#1239)
* validator-api: add swagger openapi * Lock file
This commit is contained in:
@@ -9,6 +9,7 @@ use mixnet_contract_common::reward_params::EpochRewardParams;
|
||||
use mixnet_contract_common::{
|
||||
GatewayBond, IdentityKey, IdentityKeyRef, Interval, MixNodeBond, RewardedSetNodeStatus,
|
||||
};
|
||||
use rocket_okapi::openapi_get_routes;
|
||||
|
||||
use rocket::fairing::AdHoc;
|
||||
use serde::Serialize;
|
||||
@@ -191,7 +192,7 @@ impl ValidatorCache {
|
||||
rocket.manage(Self::new()).mount(
|
||||
// this format! is so ugly...
|
||||
format!("/{}", VALIDATOR_API_VERSION),
|
||||
routes![
|
||||
openapi_get_routes![
|
||||
routes::get_mixnodes,
|
||||
routes::get_gateways,
|
||||
routes::get_active_set,
|
||||
|
||||
@@ -6,28 +6,34 @@ use mixnet_contract_common::reward_params::EpochRewardParams;
|
||||
use mixnet_contract_common::{GatewayBond, Interval, MixNodeBond};
|
||||
use rocket::serde::json::Json;
|
||||
use rocket::State;
|
||||
use rocket_okapi::openapi;
|
||||
use std::collections::HashSet;
|
||||
|
||||
#[openapi(tag = "contract-cache")]
|
||||
#[get("/mixnodes")]
|
||||
pub async fn get_mixnodes(cache: &State<ValidatorCache>) -> Json<Vec<MixNodeBond>> {
|
||||
Json(cache.mixnodes().await)
|
||||
}
|
||||
|
||||
#[openapi(tag = "contract-cache")]
|
||||
#[get("/gateways")]
|
||||
pub async fn get_gateways(cache: &State<ValidatorCache>) -> Json<Vec<GatewayBond>> {
|
||||
Json(cache.gateways().await)
|
||||
}
|
||||
|
||||
#[openapi(tag = "contract-cache")]
|
||||
#[get("/mixnodes/rewarded")]
|
||||
pub async fn get_rewarded_set(cache: &State<ValidatorCache>) -> Json<Vec<MixNodeBond>> {
|
||||
Json(cache.rewarded_set().await.value)
|
||||
}
|
||||
|
||||
#[openapi(tag = "contract-cache")]
|
||||
#[get("/mixnodes/active")]
|
||||
pub async fn get_active_set(cache: &State<ValidatorCache>) -> Json<Vec<MixNodeBond>> {
|
||||
Json(cache.active_set().await.value)
|
||||
}
|
||||
|
||||
#[openapi(tag = "contract-cache")]
|
||||
#[get("/mixnodes/blacklisted")]
|
||||
pub async fn get_blacklisted_mixnodes(
|
||||
cache: &State<ValidatorCache>,
|
||||
@@ -35,6 +41,7 @@ pub async fn get_blacklisted_mixnodes(
|
||||
Json(cache.mixnodes_blacklist().await.map(|c| c.value))
|
||||
}
|
||||
|
||||
#[openapi(tag = "contract-cache")]
|
||||
#[get("/gateways/blacklisted")]
|
||||
pub async fn get_blacklisted_gateways(
|
||||
cache: &State<ValidatorCache>,
|
||||
@@ -42,11 +49,13 @@ pub async fn get_blacklisted_gateways(
|
||||
Json(cache.gateways_blacklist().await.map(|c| c.value))
|
||||
}
|
||||
|
||||
#[openapi(tag = "contract-cache")]
|
||||
#[get("/epoch/reward_params")]
|
||||
pub async fn get_epoch_reward_params(cache: &State<ValidatorCache>) -> Json<EpochRewardParams> {
|
||||
Json(cache.epoch_reward_params().await.value)
|
||||
}
|
||||
|
||||
#[openapi(tag = "contract-cache")]
|
||||
#[get("/epoch/current")]
|
||||
pub async fn get_current_epoch(cache: &State<ValidatorCache>) -> Json<Option<Interval>> {
|
||||
Json(cache.current_epoch().await.value)
|
||||
|
||||
Reference in New Issue
Block a user