openlark-docs 0.15.0-rc.2

飞书开放平台云文档服务模块 - 文档、表格、知识库API (202 APIs, 100% 覆盖,不含旧版本)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
/// Sheets v3 API 共享模型定义
///
/// 包含所有 Sheets v3 API 共享的数据结构、枚举和类型定义
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;

// ============================================================================
// 基础类型定义
// ============================================================================

/// 电子表格令牌类型
pub type SpreadsheetToken = String;

/// 工作表ID类型
pub type SheetId = String;

/// 筛选视图ID类型
pub type FilterViewId = String;

/// 浮动图片ID类型
pub type FloatImageId = String;

/// 浮动图片令牌类型
pub type FloatImageToken = String;

/// 范围类型
pub type Range = String;

/// 单元格引用类型
pub type CellReference = String;

// ============================================================================
// 工作表相关模型
// ============================================================================

/// 工作表属性
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SheetProperty {
    /// 工作表标题
    pub title: String,
    /// 工作表索引
    pub index: i32,
    /// 工作表ID
    pub sheet_id: Option<String>,
    /// 工作表颜色
    pub sheet_color: Option<String>,
    /// 工作表是否隐藏
    pub hidden: Option<bool>,
    /// 网格属性
    pub grid_properties: Option<GridProperties>,
}

/// 网格属性
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GridProperties {
    /// 冻结行数
    pub frozen_row_count: Option<i32>,
    /// 冻结列数
    pub frozen_column_count: Option<i32>,
    /// 是否隐藏网格线
    pub hide_gridlines: Option<bool>,
}

/// 工作表信息
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SheetInfo {
    /// 工作表ID
    pub sheet_id: String,
    /// 工作表标题
    pub title: String,
    /// 工作表索引
    pub index: i32,
    /// 工作表颜色
    pub sheet_color: Option<String>,
    /// 工作表是否隐藏
    pub hidden: Option<bool>,
    /// 网格属性
    pub grid_properties: Option<GridProperties>,
}

// ============================================================================
// 电子表格相关模型
// ============================================================================

/// 电子表格基础信息
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SpreadsheetInfo {
    /// 电子表格令牌
    pub spreadsheet_token: String,
    /// 电子表格标题
    pub title: String,
    /// 创建时间
    pub create_time: String,
    /// 更新时间
    pub update_time: Option<String>,
    /// 时区
    pub time_zone: Option<String>,
    /// 语言
    pub locale: Option<String>,
    /// 工作表列表
    pub sheets: Option<Vec<SheetInfo>>,
}

/// 时区配置
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TimeZone {
    /// 时区标识符,如 "Asia/Shanghai"
    pub time_zone: String,
}

/// 语言配置
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Locale {
    /// 语言代码,如 "zh_CN"
    pub locale: String,
}

/// 创建电子表格请求
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateSpreadsheetRequest {
    /// 电子表格标题
    pub title: String,
    /// 工作表初始配置列表
    pub sheets: Option<Vec<SheetProperty>>,
    /// 时区设置
    pub time_zone: Option<TimeZone>,
    /// 语言设置
    pub locale: Option<Locale>,
    /// 文件夹路径(可选)
    pub folder_path: Option<String>,
    /// 自定义属性
    pub properties: Option<HashMap<String, Value>>,
}

impl Default for CreateSpreadsheetRequest {
    fn default() -> Self {
        Self {
            title: "未命名电子表格".to_string(),
            sheets: None,
            time_zone: None,
            locale: None,
            folder_path: None,
            properties: None,
        }
    }
}

/// 更新电子表格属性请求
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpdateSpreadsheetRequest {
    /// 电子表格标题
    pub title: Option<String>,
    /// 时区设置
    pub time_zone: Option<TimeZone>,
    /// 语言设置
    pub locale: Option<Locale>,
    /// 自定义属性
    pub properties: Option<HashMap<String, Value>>,
}

// ============================================================================
// 筛选相关模型
// ============================================================================

/// 筛选条件
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FilterCondition {
    /// 列标识符 (A, B, C...)
    pub column_id: String,
    /// 筛选操作符
    pub operator: String,
    /// 筛选值
    pub value: Option<serde_json::Value>,
    /// 是否忽略大小写
    pub ignore_case: Option<bool>,
}

/// 创建筛选请求
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateFilterRequest {
    /// 筛选范围
    pub range: Range,
    /// 筛选条件列表
    pub conditions: Option<Vec<FilterCondition>>,
}

/// 更新筛选请求
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpdateFilterRequest {
    /// 筛选条件列表
    pub conditions: Option<Vec<FilterCondition>>,
}

/// 筛选信息
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FilterInfo {
    /// 筛选ID
    pub filter_id: String,
    /// 筛选范围
    pub range: Range,
    /// 筛选条件列表
    pub conditions: Option<Vec<FilterCondition>>,
    /// 创建时间
    pub create_time: Option<String>,
    /// 更新时间
    pub update_time: Option<String>,
}

// ============================================================================
// 筛选视图相关模型
// ============================================================================

/// 筛选视图基础信息
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FilterViewInfo {
    /// 筛选视图ID
    pub filter_view_id: String,
    /// 筛选视图名称
    pub name: String,
    /// 筛选范围
    pub range: Range,
    /// 创建时间
    pub create_time: Option<String>,
    /// 更新时间
    pub update_time: Option<String>,
}

/// 创建筛选视图请求
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateFilterViewRequest {
    /// 筛选视图ID (可选,不填自动生成)
    pub filter_view_id: Option<String>,
    /// 筛选视图名称 (可选,不填自动生成)
    pub name: Option<String>,
    /// 筛选范围 (必填)
    pub range: Range,
}

/// 更新筛选视图请求
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpdateFilterViewRequest {
    /// 筛选视图名称
    pub name: Option<String>,
    /// 筛选范围
    pub range: Option<Range>,
}

/// 筛选视图条件
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FilterViewCondition {
    /// 筛选视图ID
    pub filter_view_id: String,
    /// 列标识符
    pub column_id: String,
    /// 筛选操作符
    pub operator: String,
    /// 筛选值
    pub value: Option<serde_json::Value>,
    /// 是否忽略大小写
    pub ignore_case: Option<bool>,
}

// ============================================================================
// 浮动图片相关模型
// ============================================================================

/// 创建浮动图片请求
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateFloatImageRequest {
    /// 浮动图片令牌 (必填)
    pub float_image_token: FloatImageToken,
    /// 图片范围 (必填,只支持单个单元格)
    pub range: Range,
    /// 浮动图片ID (可选,不填自动生成)
    pub float_image_id: Option<String>,
    /// 图片展示宽度 (可选)
    pub width: Option<i32>,
    /// 图片展示高度 (可选)
    pub height: Option<i32>,
    /// 水平偏移量 (可选,默认为0)
    pub offset_x: Option<i32>,
    /// 垂直偏移量 (可选,默认为0)
    pub offset_y: Option<i32>,
}

/// 更新浮动图片请求
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpdateFloatImageRequest {
    /// 图片范围
    pub range: Option<Range>,
    /// 图片展示宽度
    pub width: Option<i32>,
    /// 图片展示高度
    pub height: Option<i32>,
    /// 水平偏移量
    pub offset_x: Option<i32>,
    /// 垂直偏移量
    pub offset_y: Option<i32>,
}

/// 浮动图片信息
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FloatImageInfo {
    /// 浮动图片ID
    pub float_image_id: String,
    /// 浮动图片令牌
    pub float_image_token: FloatImageToken,
    /// 图片范围
    pub range: Range,
    /// 图片展示宽度
    pub width: i32,
    /// 图片展示高度
    pub height: i32,
    /// 水平偏移量
    pub offset_x: i32,
    /// 垂直偏移量
    pub offset_y: i32,
    /// 创建时间
    pub create_time: Option<String>,
    /// 更新时间
    pub update_time: Option<String>,
}

// ============================================================================
// 数据操作相关模型
// ============================================================================

/// 查找单元格请求
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FindCellsRequest {
    /// 查找范围
    pub range: Range,
    /// 查找内容
    pub find: String,
    /// 是否匹配大小写
    pub match_case: Option<bool>,
    /// 是否匹配整个单元格
    pub match_entire_cell: Option<bool>,
    /// 是否使用正则表达式
    pub use_regular_expressions: Option<bool>,
}

/// 查找结果
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FindResult {
    /// 匹配的单元格位置
    pub cell_position: Vec<CellPosition>,
    /// 匹配数量
    pub total_count: i32,
}

/// 单元格位置
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CellPosition {
    /// 工作表ID
    pub sheet_id: String,
    /// 行号
    pub row_index: i32,
    /// 列号
    pub column_index: i32,
    /// 单元格值
    pub value: Option<serde_json::Value>,
}

/// 替换单元格请求
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReplaceCellsRequest {
    /// 替换范围
    pub range: Range,
    /// 查找内容
    pub find: String,
    /// 替换内容
    pub replacement: String,
    /// 是否匹配大小写
    pub match_case: Option<bool>,
    /// 是否匹配整个单元格
    pub match_entire_cell: Option<bool>,
    /// 是否使用正则表达式
    pub use_regular_expressions: Option<bool>,
}

/// 替换结果
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReplaceResult {
    /// 成功替换的单元格位置
    pub replaced_cells: Vec<CellPosition>,
    /// 替换数量
    pub replaced_count: i32,
}

/// 移动行列请求
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MoveDimensionRequest {
    /// 移动源范围
    pub source_range: Range,
    /// 移动目标位置
    pub destination_index: i32,
    /// 移动维度 ("ROWS" 或 "COLUMNS")
    pub dimension: String,
}

// ============================================================================
// 响应模型
// ============================================================================

/// API响应基础结构
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SheetsResponse<T> {
    /// 响应数据
    pub data: Option<T>,
    /// 错误信息
    pub error: Option<serde_json::Value>,
    /// 请求ID
    pub request_id: Option<String>,
}

/// 分页响应
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PagedResponse<T> {
    /// 数据列表
    pub items: Option<Vec<T>>,
    /// 是否还有更多数据
    pub has_more: Option<bool>,
    /// 页面令牌
    pub page_token: Option<String>,
    /// 总数
    pub total: Option<i32>,
}

#[cfg(test)]
mod tests {

    use serde_json;

    #[test]
    fn test_serialization_roundtrip() {
        // 基础序列化测试
        let json = r#"{"test": "value"}"#;
        assert!(serde_json::from_str::<serde_json::Value>(json).is_ok());
    }

    #[test]
    fn test_deserialization_from_json() {
        // 基础反序列化测试
        let json = r#"{"field": "data"}"#;
        let value: serde_json::Value = serde_json::from_str(json).unwrap();
        assert_eq!(value["field"], "data");
    }
}