diff --git a/crates/gpapi/src/gateway/mod.rs b/crates/gpapi/src/gateway/mod.rs index 5d0ef61..f536ef0 100644 --- a/crates/gpapi/src/gateway/mod.rs +++ b/crates/gpapi/src/gateway/mod.rs @@ -23,6 +23,7 @@ pub(crate) struct PriorityRule { pub struct Gateway { pub(crate) name: String, pub(crate) address: String, + #[serde(default)] pub(crate) kind: GatewayKind, pub(crate) priority: u32, pub(crate) priority_rules: Vec, @@ -44,6 +45,12 @@ impl GatewayKind { } } +impl Default for GatewayKind { + fn default() -> Self { + Self::External + } +} + #[derive(Debug, Serialize, Deserialize, Type, Clone, Copy, PartialEq, Eq)] #[serde(rename_all = "camelCase")] pub enum GatewaySelection { @@ -60,6 +67,12 @@ impl GatewaySelection { } } +impl Default for GatewaySelection { + fn default() -> Self { + Self::Auto + } +} + #[derive(Debug, Clone)] pub struct GatewayLoginContext { host: String, @@ -163,3 +176,23 @@ impl Gateway { self.kind } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn deserializes_gateway_without_kind_as_external() { + let gateway: Gateway = serde_json::from_str( + r#"{ + "name": "US East", + "address": "us-east.example.com", + "priority": 1, + "priorityRules": [] + }"#, + ) + .unwrap(); + + assert_eq!(gateway.kind(), GatewayKind::External); + } +}