openlark_workflow/v2/custom_field/
models.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
7#[serde(rename_all = "snake_case")]
8pub enum CustomFieldType {
9 Text,
11 Number,
13 Date,
15 Person,
17 Checkbox,
19 Select,
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
25pub struct CustomFieldConfig {
26 #[serde(rename = "type")]
28 pub field_type: CustomFieldType,
29 #[serde(skip_serializing_if = "Option::is_none")]
31 pub options: Option<Vec<String>>,
32}
33
34impl Default for CustomFieldConfig {
35 fn default() -> Self {
36 Self {
37 field_type: CustomFieldType::Text,
38 options: None,
39 }
40 }
41}
42
43#[derive(Debug, Clone, Serialize, Default)]
45pub struct CreateCustomFieldBody {
46 pub name: String,
48 pub config: CustomFieldConfig,
50}
51
52#[derive(Debug, Clone, Serialize, Default)]
54pub struct UpdateCustomFieldBody {
55 #[serde(skip_serializing_if = "Option::is_none")]
57 pub name: Option<String>,
58 #[serde(skip_serializing_if = "Option::is_none")]
60 pub config: Option<CustomFieldConfig>,
61}
62
63#[derive(Debug, Clone, Deserialize)]
65pub struct CreateCustomFieldResponse {
66 pub field_guid: String,
68 pub name: String,
70 pub config: CustomFieldConfig,
72 pub created_at: String,
74 pub updated_at: String,
76}
77
78#[derive(Debug, Clone, Deserialize)]
80pub struct GetCustomFieldResponse {
81 pub field_guid: String,
83 pub name: String,
85 pub config: CustomFieldConfig,
87 pub created_at: String,
89 pub updated_at: String,
91}
92
93#[derive(Debug, Clone, Deserialize)]
95pub struct UpdateCustomFieldResponse {
96 pub field_guid: String,
98 pub name: String,
100 pub config: CustomFieldConfig,
102 pub updated_at: String,
104}
105
106#[derive(Debug, Clone, Deserialize)]
108pub struct DeleteCustomFieldResponse {
109 pub success: bool,
111 pub field_guid: String,
113}
114
115#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
117pub struct CustomFieldItem {
118 pub field_guid: String,
120 pub name: String,
122 pub config: CustomFieldConfig,
124 pub created_at: String,
126 pub updated_at: String,
128}
129
130#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
132pub struct ListCustomFieldsResponse {
133 #[serde(default)]
135 pub has_more: bool,
136 #[serde(skip_serializing_if = "Option::is_none")]
138 pub page_token: Option<String>,
139 #[serde(skip_serializing_if = "Option::is_none")]
141 pub total: Option<i32>,
142 #[serde(default)]
144 pub items: Vec<CustomFieldItem>,
145}
146
147#[cfg(test)]
148#[allow(unused_imports)]
149mod tests {
150
151 #[test]
152 fn test_serialization_roundtrip() {
153 let json = r#"{"test": "value"}"#;
155 assert!(serde_json::from_str::<serde_json::Value>(json).is_ok());
156 }
157
158 #[test]
159 fn test_deserialization_from_json() {
160 let json = r#"{"field": "data"}"#;
162 let value: serde_json::Value = serde_json::from_str(json).expect("JSON 反序列化失败");
163 assert_eq!(value["field"], "data");
164 }
165}