zlayer_types/api/
volumes.rs1use std::collections::HashMap;
8
9use serde::{Deserialize, Serialize};
10use utoipa::ToSchema;
11
12#[derive(Debug, Deserialize, Serialize, ToSchema)]
14pub struct CreateVolumeRequest {
15 pub name: String,
17 #[serde(default, skip_serializing_if = "Option::is_none")]
20 pub size: Option<String>,
21 #[serde(default, skip_serializing_if = "Option::is_none")]
24 pub tier: Option<String>,
25 #[serde(default, skip_serializing_if = "Option::is_none")]
27 pub labels: Option<HashMap<String, String>>,
28}
29
30#[derive(Debug, Serialize, Deserialize, ToSchema)]
33pub struct VolumeInfo {
34 pub name: String,
36 pub path: String,
38 #[serde(skip_serializing_if = "Option::is_none")]
43 pub size_bytes: Option<u64>,
44 #[serde(default, skip_serializing_if = "HashMap::is_empty")]
46 pub labels: HashMap<String, String>,
47 pub created_at: String,
50 #[serde(default, skip_serializing_if = "Vec::is_empty")]
53 pub in_use_by: Vec<String>,
54}
55
56#[derive(Debug, Serialize, Deserialize, ToSchema)]
61pub struct VolumeSummary {
62 pub name: String,
64 pub path: String,
66 pub size_bytes: Option<u64>,
68}
69
70#[derive(Debug, Deserialize)]
72pub struct DeleteVolumeQuery {
73 #[serde(default)]
76 pub force: bool,
77}
78
79#[cfg(test)]
80mod tests {
81 use super::*;
82
83 #[test]
84 fn test_volume_info_serialization() {
85 let info = VolumeInfo {
86 name: "test-vol".to_string(),
87 path: "/data/volumes/test-vol".to_string(),
88 size_bytes: Some(1024),
89 labels: HashMap::from([("owner".to_string(), "zarc".to_string())]),
90 created_at: "2026-04-20T00:00:00Z".to_string(),
91 in_use_by: vec!["c1".to_string()],
92 };
93
94 let json = serde_json::to_string(&info).unwrap();
95 assert!(json.contains("test-vol"));
96 assert!(json.contains("1024"));
97 assert!(json.contains("owner"));
98 assert!(json.contains("in_use_by"));
99 }
100
101 #[test]
102 fn test_volume_summary_legacy_serialization() {
103 let summary = VolumeSummary {
106 name: "legacy".to_string(),
107 path: "/data/volumes/legacy".to_string(),
108 size_bytes: Some(1024),
109 };
110 let json = serde_json::to_string(&summary).unwrap();
111 assert!(json.contains("legacy"));
112 }
113
114 #[test]
115 fn test_delete_volume_query_defaults() {
116 let query: DeleteVolumeQuery = serde_json::from_str("{}").unwrap();
117 assert!(!query.force);
118 }
119
120 #[test]
121 fn test_delete_volume_query_force() {
122 let query: DeleteVolumeQuery = serde_json::from_str(r#"{"force": true}"#).unwrap();
123 assert!(query.force);
124 }
125}