validator-api: tidy swagger stuff

This commit is contained in:
Jon Häggblad
2022-04-27 14:50:51 +02:00
parent 433604dec7
commit d3d5e327c7
4 changed files with 41 additions and 52 deletions
@@ -67,43 +67,39 @@ pub struct Interval {
length: Duration,
}
//impl JsonSchema for Interval {
// fn schema_name() -> String {
// "Interval".to_owned()
// }
//
// fn json_schema(gen: &mut SchemaGenerator) -> Schema {
// let mut schema_object = SchemaObject {
// instance_type: Some(InstanceType::Object.into()),
// ..SchemaObject::default()
// };
//
// let object_validation = schema_object.object();
// object_validation
// .properties
// .insert("id".to_owned(), gen.subschema_for::<u32>());
// object_validation
// .required
// .insert("id".to_owned());
//
// // WIP(JON): missing member
// //object_validation
// // .properties
// // .insert("start".to_owned(), gen.subschema_for::<OffsetDateTime>());
// //object_validation
// // .required
// // .insert("start".to_owned());
//
// object_validation
// .properties
// .insert("length".to_owned(), gen.subschema_for::<Duration>());
// object_validation
// .required
// .insert("length".to_owned());
//
// Schema::Object(schema_object)
// }
//}
impl JsonSchema for Interval {
fn schema_name() -> String {
"Interval".to_owned()
}
fn json_schema(gen: &mut SchemaGenerator) -> Schema {
let mut schema_object = SchemaObject {
instance_type: Some(InstanceType::Object.into()),
..SchemaObject::default()
};
let object_validation = schema_object.object();
object_validation
.properties
.insert("id".to_owned(), gen.subschema_for::<u32>());
object_validation.required.insert("id".to_owned());
// WIP(JON): missing JsonSchema impl for PrimitiveDateTime
//object_validation
// .properties
// .insert("start".to_owned(), gen.subschema_for::<PrimitiveDateTime>());
//object_validation
// .required
// .insert("start".to_owned());
object_validation
.properties
.insert("length".to_owned(), gen.subschema_for::<Duration>());
object_validation.required.insert("length".to_owned());
Schema::Object(schema_object)
}
}
impl Interval {
/// Initialize epoch in the contract with default values.
+3 -6
View File
@@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
use crate::nymd_client::Client;
use rocket_okapi::openapi_get_routes;
use ::time::OffsetDateTime;
use anyhow::Result;
use config::defaults::VALIDATOR_API_VERSION;
@@ -10,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;
@@ -180,7 +180,7 @@ impl<C> ValidatorCacheRefresher<C> {
}
impl ValidatorCache {
pub fn new() -> Self {
fn new() -> Self {
ValidatorCache {
initialised: Arc::new(AtomicBool::new(false)),
inner: Arc::new(RwLock::new(ValidatorCacheInner::new())),
@@ -189,13 +189,10 @@ impl ValidatorCache {
pub fn stage() -> AdHoc {
AdHoc::on_ignite("Validator Cache Stage", |rocket| async {
rocket
.manage(Self::new())
.mount(
rocket.manage(Self::new()).mount(
// this format! is so ugly...
format!("/{}", VALIDATOR_API_VERSION),
openapi_get_routes![
//routes![
routes::get_mixnodes,
routes::get_gateways,
routes::get_active_set,
+1 -2
View File
@@ -55,8 +55,7 @@ pub async fn get_epoch_reward_params(cache: &State<ValidatorCache>) -> Json<Epoc
Json(cache.epoch_reward_params().await.value)
}
// WIP(JON)
#[openapi(tag = "contract-cache", skip)]
#[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)
+4 -7
View File
@@ -9,9 +9,9 @@ use rocket::response::{self, Responder, Response};
use rocket::Request;
use rocket_okapi::gen::OpenApiGenerator;
use rocket_okapi::response::OpenApiResponderInner;
use schemars::JsonSchema;
use schemars::gen::SchemaGenerator;
use schemars::schema::{Schema, InstanceType};
use schemars::schema::{InstanceType, Schema};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::convert::TryFrom;
use std::fmt::{self, Display, Formatter};
@@ -269,19 +269,16 @@ impl JsonSchema for ErrorResponse {
object_validation
.properties
.insert("status".to_owned(), gen.subschema_for::<u16>());
object_validation
.required
.insert("status".to_owned());
object_validation.required.insert("status".to_owned());
Schema::Object(schema_object)
}
}
impl OpenApiResponderInner for ErrorResponse {
fn responses(_gen: &mut OpenApiGenerator) -> rocket_okapi::Result<Responses> {
let responses = Responses::default();
// WIP(JON)
// WIP(JON): handle responses correctly
Ok(responses)
}
}