share the forge and schedule wire types through swarm-controller-api
swarmctl hand-mirrored the controller's forge make-admin response and the /api/schedules bodies. Both now import them from a new serde-only crate, swarm-controller-api, the way hivectl and hive-c0re share hive-host-sock. ToSchema sits behind its schema feature, which only the controller turns on. The wire format is unchanged: round-trip tests in the new crate pin each type against the JSON the controller and swarmctl produced, and the controller's OpenAPI document for these routes is byte-identical. Files: swarm-controller-api/ is the new crate; swarm-controller and swarmctl (src, Cargo.toml, Cargo.lock, root Cargo.toml) switch to it; CLAUDE.md lists the crate and which swarmctl shapes are still local mirrors; swarmctl/README.md says the forge and schedule bodies come from the crate, so none of its lines still call them mirrored. Part of #5472.
This commit is contained in:
parent
22b9c570ba
commit
be92bc0835
17 changed files with 529 additions and 377 deletions
42
swarm-controller-api/src/forge.rs
Normal file
42
swarm-controller-api/src/forge.rs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
//! `POST /api/forge/users/{name}/admin`.
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// What `POST /api/forge/users/{name}/admin` found.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schema", derive(utoipa::ToSchema))]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ForgeAdminChange {
|
||||
Promoted,
|
||||
AlreadyAdmin,
|
||||
}
|
||||
|
||||
/// Success body of `POST /api/forge/users/{name}/admin`.
|
||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schema", derive(utoipa::ToSchema))]
|
||||
pub struct MakeForgeAdminResponse {
|
||||
pub change: ForgeAdminChange,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{ForgeAdminChange, MakeForgeAdminResponse};
|
||||
|
||||
#[test]
|
||||
fn both_changes_round_trip() {
|
||||
for (change, wire) in [
|
||||
(ForgeAdminChange::Promoted, r#"{"change":"promoted"}"#),
|
||||
(
|
||||
ForgeAdminChange::AlreadyAdmin,
|
||||
r#"{"change":"already_admin"}"#,
|
||||
),
|
||||
] {
|
||||
let resp = MakeForgeAdminResponse { change };
|
||||
assert_eq!(serde_json::to_string(&resp).unwrap(), wire);
|
||||
assert_eq!(
|
||||
serde_json::from_str::<MakeForgeAdminResponse>(wire).unwrap(),
|
||||
resp
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue