G: dedupe openapi helpers
This commit is contained in:
1 parent
e7f1d1a488
commit
55a2401f17
1 file changed
+63
-73
+63
-73
@@ -517,84 +517,48 @@ handwritten_schema!(
|
|||||||
handwritten_schema!(
|
handwritten_schema!(
|
||||||
ServerStatus,
|
ServerStatus,
|
||||||
"ServerStatus",
|
"ServerStatus",
|
||||||
ObjectBuilder::new()
|
check_properties(
|
||||||
.description(Some(
|
ObjectBuilder::new()
|
||||||
"\"Server up\": a TCP connect to the peer's host and port."
|
.description(Some(
|
||||||
))
|
"\"Server up\": a TCP connect to the peer's host and port."
|
||||||
.required("up")
|
))
|
||||||
.required("since")
|
.required("up")
|
||||||
.required("last_checked")
|
.required("since")
|
||||||
.required("last_error")
|
.required("last_checked")
|
||||||
.required("latency_ms")
|
.required("last_error")
|
||||||
.property("up", ObjectBuilder::new().schema_type(Type::Boolean))
|
.required("latency_ms"),
|
||||||
.property(
|
"Failure class such as `timeout` or `unreachable`; never a URL or a secret.",
|
||||||
"since",
|
)
|
||||||
nullable(Type::String)
|
.into()
|
||||||
.format(Some(date_time()))
|
|
||||||
.description(Some(SINCE_DOC)),
|
|
||||||
)
|
|
||||||
.property(
|
|
||||||
"last_checked",
|
|
||||||
nullable(Type::String).format(Some(date_time()))
|
|
||||||
)
|
|
||||||
.property(
|
|
||||||
"last_error",
|
|
||||||
nullable(Type::String).description(Some(
|
|
||||||
"Failure class such as `timeout` or `unreachable`; never a URL or a secret.",
|
|
||||||
)),
|
|
||||||
)
|
|
||||||
.property(
|
|
||||||
"latency_ms",
|
|
||||||
nullable(Type::Integer).minimum(Some(utoipa::Number::UInt(0))),
|
|
||||||
)
|
|
||||||
.into()
|
|
||||||
);
|
);
|
||||||
|
|
||||||
handwritten_schema!(
|
handwritten_schema!(
|
||||||
ApiStatus,
|
ApiStatus,
|
||||||
"ApiStatus",
|
"ApiStatus",
|
||||||
ObjectBuilder::new()
|
check_properties(
|
||||||
.description(Some(
|
ObjectBuilder::new()
|
||||||
"\"API running\": an authenticated `GET /api/v1/ping`. `up` is true also when the \
|
.description(Some(
|
||||||
peer answered 401, so a revoked token reads as `auth = rejected` rather than as an \
|
"\"API running\": an authenticated `GET /api/v1/ping`. `up` is true also when the \
|
||||||
outage.",
|
peer answered 401, so a revoked token reads as `auth = rejected` rather than as an \
|
||||||
))
|
outage.",
|
||||||
.required("up")
|
))
|
||||||
.required("since")
|
.required("up")
|
||||||
.required("last_checked")
|
.required("since")
|
||||||
.required("last_error")
|
.required("last_checked")
|
||||||
.required("latency_ms")
|
.required("last_error")
|
||||||
.required("auth")
|
.required("latency_ms")
|
||||||
.required("peer_version")
|
.required("auth")
|
||||||
.property("up", ObjectBuilder::new().schema_type(Type::Boolean))
|
.required("peer_version"),
|
||||||
.property(
|
"Failure class such as `http_500` or `token_file`; never a URL or a secret.",
|
||||||
"since",
|
)
|
||||||
nullable(Type::String)
|
.property("auth", Ref::from_schema_name("AuthState"))
|
||||||
.format(Some(date_time()))
|
.property(
|
||||||
.description(Some(SINCE_DOC)),
|
"peer_version",
|
||||||
)
|
nullable(Type::String).description(Some(
|
||||||
.property(
|
"Version the peer reported, when it has the ping route."
|
||||||
"last_checked",
|
)),
|
||||||
nullable(Type::String).format(Some(date_time()))
|
)
|
||||||
)
|
.into()
|
||||||
.property(
|
|
||||||
"last_error",
|
|
||||||
nullable(Type::String).description(Some(
|
|
||||||
"Failure class such as `http_500` or `token_file`; never a URL or a secret.",
|
|
||||||
)),
|
|
||||||
)
|
|
||||||
.property(
|
|
||||||
"latency_ms",
|
|
||||||
nullable(Type::Integer).minimum(Some(utoipa::Number::UInt(0))),
|
|
||||||
)
|
|
||||||
.property("auth", Ref::from_schema_name("AuthState"))
|
|
||||||
.property(
|
|
||||||
"peer_version",
|
|
||||||
nullable(Type::String).description(Some(
|
|
||||||
"Version the peer reported, when it has the ping route."
|
|
||||||
)),
|
|
||||||
)
|
|
||||||
.into()
|
|
||||||
);
|
);
|
||||||
|
|
||||||
handwritten_schema!(
|
handwritten_schema!(
|
||||||
@@ -656,6 +620,32 @@ fn date_time() -> SchemaFormat {
|
|||||||
SchemaFormat::Custom("date-time".into())
|
SchemaFormat::Custom("date-time".into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The properties both peer checks share: `up`, `since` and `last_checked`
|
||||||
|
/// (described by [`SINCE_DOC`]), `last_error` with its check-specific wording
|
||||||
|
/// and `latency_ms`. Added in document order so the keys stay where they were.
|
||||||
|
fn check_properties(builder: ObjectBuilder, last_error: &str) -> ObjectBuilder {
|
||||||
|
builder
|
||||||
|
.property("up", ObjectBuilder::new().schema_type(Type::Boolean))
|
||||||
|
.property(
|
||||||
|
"since",
|
||||||
|
nullable(Type::String)
|
||||||
|
.format(Some(date_time()))
|
||||||
|
.description(Some(SINCE_DOC)),
|
||||||
|
)
|
||||||
|
.property(
|
||||||
|
"last_checked",
|
||||||
|
nullable(Type::String).format(Some(date_time())),
|
||||||
|
)
|
||||||
|
.property(
|
||||||
|
"last_error",
|
||||||
|
nullable(Type::String).description(Some(last_error)),
|
||||||
|
)
|
||||||
|
.property(
|
||||||
|
"latency_ms",
|
||||||
|
nullable(Type::Integer).minimum(Some(utoipa::Number::UInt(0))),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
Reference in new issue
Block a user