{"openapi":"3.1.0","info":{"title":"云乐坊待办同步 API（YunLeFun Todo Sync）","version":"1.0.0","description":"离线优先跨端待办增量同步、幂等变更、批量迁移导入与全量备份导出协议。所有客户端通过 OAuth2 S256 PKCE 换取短效 `at+jwt` 资源令牌（官方生产 300 秒、自建模式 900 秒，以响应 `expires_in` 为准）并按 `Yunle-Todo-Subject` 隔离本地数据分区。\n\n相关入口：[Web 客户端 (todo.yunle.fun)](https://todo.yunle.fun) · [云乐坊开发者文档](https://docs.yunle.fun/app/todo) · [GitHub 仓库 (YunLeFun/todo)](https://github.com/YunLeFun/todo) · [自建部署指南](https://github.com/YunLeFun/todo/blob/main/docs/self-hosting.md)\n\n交互调试提示：在 Scalar 页面调试受保护接口时，请直接粘贴已签发的 `at+jwt` Bearer 访问令牌（`bearerAuth`）；OAuth2 授权码流程须使用已登记的回调地址、S256 PKCE 与对应 `resource` 参数。"},"externalDocs":{"description":"云乐坊开发者文档 · 云待办同步 API 接入指南","url":"https://docs.yunle.fun/app/todo"},"servers":[{"url":"/","description":"Current Todo Sync API Origin (same-origin)"}],"tags":[{"name":"System","description":"健康检查与规范发现"},{"name":"Sync","description":"增量同步与备份导出"},{"name":"Mutations","description":"版本乐观锁与幂等写入"},{"name":"Import","description":"批量迁移导入（预览与原子写入）"}],"paths":{"/health":{"get":{"tags":["System"],"summary":"服务健康检查","operationId":"getHealth","responses":{"200":{"description":"服务正常","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HealthResponse"}}}}}}},"/healthz":{"get":{"tags":["System"],"summary":"Kubernetes / Docker 健康检查探针","operationId":"getHealthz","responses":{"200":{"description":"服务正常","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HealthResponse"}}}}}}},"/openapi.json":{"get":{"tags":["System"],"summary":"获取实时 OpenAPI 3.1.0 规范文档","operationId":"getOpenApiSpec","responses":{"200":{"description":"OpenAPI 3.1.0 JSON 规范","content":{"application/json":{"schema":{"type":"object"}}}}}}},"/docs":{"get":{"tags":["System"],"summary":"交互式 API 文档（Scalar API Reference）","operationId":"getInteractiveDocs","responses":{"200":{"description":"基于 /openapi.json 渲染的交互式 HTML 文档页","content":{"text/html":{"schema":{"type":"string"}}}}}}},"/v1/todos/sync":{"get":{"tags":["Sync"],"summary":"按游标增量拉取清单、待办与墓碑删除记录","operationId":"syncTodos","security":[{"bearerAuth":[]},{"oauth2":["todos:read"]}],"parameters":[{"name":"cursor","in":"query","required":false,"description":"64 位有符号非负整数游标字符串（`0`–`9223372036854775807`，首次拉取传 `\"0\"`；纯数字串的前导零会被规范化，不得含空白或重复传参）","schema":{"type":"string","pattern":"^\\d{1,19}$","default":"0"}},{"name":"limit","in":"query","required":false,"description":"单页返回条数（`1`–`100`，默认 `50`；禁止前导零、空白或重复传参）","schema":{"type":"integer","minimum":1,"maximum":100,"default":50}}],"responses":{"200":{"description":"增量分页结果（客户端应在同一本地事务中持久化 records 与新 cursor）","headers":{"Yunle-Todo-Subject":{"$ref":"#/components/headers/YunleTodoSubject"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SyncPage"}}}},"400":{"description":"非法 cursor 或 limit 参数","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"缺少或无效的 Bearer 访问令牌（或未授权客户端）","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"Scope 不足或账号未准入/已停用","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"503":{"description":"上游 JWKS / 账号状态 / 数据库暂不可用（可退避重试）","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/v1/todos/mutations":{"post":{"tags":["Mutations"],"summary":"幂等写入单条清单或待办变更（新建 / 更新 / 墓碑删除）","operationId":"applyTodoMutation","security":[{"bearerAuth":[]},{"oauth2":["todos:write"]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/MutationRequest"}}}},"responses":{"200":{"description":"写入成功或幂等重放命中原回执","headers":{"Yunle-Todo-Subject":{"$ref":"#/components/headers/YunleTodoSubject"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/MutationSuccessResponse"}}}},"400":{"description":"请求格式或字段校验失败","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"缺少或无效的 Bearer 访问令牌（或未授权客户端）","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"Scope 不足或账号未准入/已停用","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"409":{"description":"业务或并发冲突（`version_conflict` / `mutation_reused` / `list_not_found` / `list_not_empty`）","headers":{"Yunle-Todo-Subject":{"$ref":"#/components/headers/YunleTodoSubject"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/MutationConflictResponse"}}}},"413":{"description":"请求体超出 128 KiB 或单条 JSON 负载超出 64 KiB 上限","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"503":{"description":"上游 JWKS / 账号状态 / 数据库暂不可用（可退避重试）","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/v1/todos/import/preview":{"post":{"tags":["Import"],"summary":"预检批量迁移记录（只读，不写入数据库）","operationId":"previewTodoImport","security":[{"bearerAuth":[]},{"oauth2":["todos:write"]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ImportRequest"}}}},"responses":{"200":{"description":"逐条返回可导入状态预测（列表优先检查）","headers":{"Yunle-Todo-Subject":{"$ref":"#/components/headers/YunleTodoSubject"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ImportResponse"}}}},"400":{"description":"导入批次不合法或包含重复 id / mutationId","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"缺少或无效的 Bearer 访问令牌（或未授权客户端）","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"Scope 不足或账号未准入/已停用","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"413":{"description":"单条或整批导入负载超出大小限制（单条 60,000 B，整批 90,000 B）","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"503":{"description":"上游 JWKS / 账号状态 / 数据库暂不可用（可退避重试）","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/v1/todos/import/apply":{"post":{"tags":["Import"],"summary":"事务化写入批量迁移记录（lists-first，最多 50 条）","operationId":"applyTodoImport","security":[{"bearerAuth":[]},{"oauth2":["todos:write"]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ImportRequest"}}}},"responses":{"200":{"description":"逐条返回实际导入结果（`created` / `existing` / `conflict` / `deleted` / `missing_list`）","headers":{"Yunle-Todo-Subject":{"$ref":"#/components/headers/YunleTodoSubject"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ImportResponse"}}}},"400":{"description":"导入批次不合法或包含重复 id / mutationId","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"缺少或无效的 Bearer 访问令牌（或未授权客户端）","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"Scope 不足或账号未准入/已停用","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"413":{"description":"单条或整批导入负载超出大小限制","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"503":{"description":"上游 JWKS / 账号状态 / 数据库暂不可用（可退避重试）","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/v1/todos/export":{"get":{"tags":["Sync"],"summary":"导出当前账号全部存活清单与待办的 JSON 快照","operationId":"exportTodos","security":[{"bearerAuth":[]},{"oauth2":["todos:read"]}],"responses":{"200":{"description":"全量 JSON 备份快照","headers":{"Yunle-Todo-Subject":{"$ref":"#/components/headers/YunleTodoSubject"},"Content-Disposition":{"$ref":"#/components/headers/ContentDisposition"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ExportSnapshot"}}}},"401":{"description":"缺少或无效的 Bearer 访问令牌（或未授权客户端）","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"Scope 不足或账号未准入/已停用","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"503":{"description":"快照并发冲突（`export_conflict`，附带 `Retry-After`）或上游 JWKS / 账号状态 / 数据库暂不可用","headers":{"Retry-After":{"$ref":"#/components/headers/RetryAfter"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}},"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"at+jwt","description":"在 Scalar 交互文档调试时可直接粘贴由认证服务签发的 `at+jwt` 访问令牌（官方 300 秒、自建 900 秒，以 `expires_in` 为准）"},"oauth2":{"type":"oauth2","description":"OAuth 2.0 授权码 + S256 PKCE（授权与换票均须携带已登记 `redirect_uri` 与 `resource` 参数）","flows":{"authorizationCode":{"authorizationUrl":"https://auth.yunle.fun/api/auth/oauth2/authorize","tokenUrl":"https://auth.yunle.fun/api/auth/oauth2/token","scopes":{"openid":"OpenID Connect 主体标识","profile":"读取显示昵称与头像（/oauth2/userinfo；自建模式返回昵称与用户名，不含头像）","offline_access":"签发轮换 Refresh Token","todos:read":"读取增量同步与导出全量快照","todos:write":"提交变更与执行批量导入"}}}}},"headers":{"YunleTodoSubject":{"description":"经服务端验签确认的权威账号主体 UID，客户端用于隔离本地存储分区与校验账号一致","schema":{"type":"string"}},"ContentDisposition":{"description":"导出 JSON 备份时的附件下载头（例如 `attachment; filename=\"yunle-todo-backup.json\"`）","schema":{"type":"string"}},"RetryAfter":{"description":"触发 `export_conflict` 等瞬态限流/冲突响应时建议退避重试的秒数","schema":{"type":"string","example":"1"}}},"schemas":{"HealthResponse":{"type":"object","required":["ok","mode"],"properties":{"ok":{"type":"boolean","const":true},"mode":{"type":"string","enum":["external","self-hosted"]}}},"TodoListGroupRef":{"type":"object","additionalProperties":false,"required":["id","name"],"properties":{"id":{"type":"string","minLength":1,"maxLength":128},"name":{"type":"string","minLength":1,"maxLength":512}}},"TodoListValue":{"type":"object","additionalProperties":false,"required":["title"],"properties":{"title":{"type":"string","minLength":1,"maxLength":512},"group":{"$ref":"#/components/schemas/TodoListGroupRef"}}},"TodoTaskValue":{"type":"object","additionalProperties":true,"required":["title","status"],"properties":{"title":{"type":"string","minLength":1,"maxLength":512},"status":{"type":"string","enum":["notStarted","inProgress","completed","waitingOnOthers","deferred"]},"listId":{"oneOf":[{"type":"string"},{"type":"null"}],"description":"所属清单 UUID；省略或为 null 表示放在默认收件箱"}}},"TodoImportTaskValue":{"type":"object","additionalProperties":true,"required":["title","status"],"properties":{"title":{"type":"string","minLength":1,"maxLength":512},"status":{"type":"string","enum":["notStarted","inProgress","completed","waitingOnOthers","deferred"]},"listId":{"oneOf":[{"type":"string","format":"uuid"},{"type":"null"}],"description":"批量导入时所属清单必须为有效 UUID 或 null（省略表示默认收件箱）"}}},"TodoListRecord":{"type":"object","required":["id","kind","version","value","updatedAt","deletedAt"],"properties":{"id":{"type":"string","format":"uuid"},"kind":{"type":"string","const":"list"},"version":{"type":"integer","minimum":1},"value":{"oneOf":[{"$ref":"#/components/schemas/TodoListValue"},{"type":"null"}]},"updatedAt":{"type":"string","format":"date-time"},"deletedAt":{"oneOf":[{"type":"string","format":"date-time"},{"type":"null"}]}}},"TodoTaskRecord":{"type":"object","required":["id","kind","version","value","updatedAt","deletedAt"],"properties":{"id":{"type":"string","format":"uuid"},"kind":{"type":"string","const":"task"},"version":{"type":"integer","minimum":1},"value":{"oneOf":[{"$ref":"#/components/schemas/TodoTaskValue"},{"type":"null"}]},"updatedAt":{"type":"string","format":"date-time"},"deletedAt":{"oneOf":[{"type":"string","format":"date-time"},{"type":"null"}]}}},"TodoRecord":{"oneOf":[{"$ref":"#/components/schemas/TodoListRecord"},{"$ref":"#/components/schemas/TodoTaskRecord"}]},"SyncPage":{"type":"object","required":["records","cursor","hasMore"],"properties":{"records":{"type":"array","items":{"$ref":"#/components/schemas/TodoRecord"}},"cursor":{"type":"string","pattern":"^\\d+$"},"hasMore":{"type":"boolean"}}},"ListMutationRequest":{"type":"object","required":["mutationId","id","kind","version","value"],"properties":{"mutationId":{"type":"string","format":"uuid"},"id":{"type":"string","format":"uuid"},"kind":{"type":"string","const":"list"},"version":{"type":"integer","minimum":0,"maximum":2147483647},"removeGroup":{"type":"boolean","description":"Web 端明确将清单移出分组时传 true；旧版 Web 未传 group 时服务端保留原分组"},"value":{"oneOf":[{"$ref":"#/components/schemas/TodoListValue"},{"type":"null"}]}}},"TaskMutationRequest":{"type":"object","required":["mutationId","id","kind","version","value"],"properties":{"mutationId":{"type":"string","format":"uuid"},"id":{"type":"string","format":"uuid"},"kind":{"type":"string","const":"task"},"version":{"type":"integer","minimum":0,"maximum":2147483647},"value":{"oneOf":[{"$ref":"#/components/schemas/TodoTaskValue"},{"type":"null"}]}}},"MutationRequest":{"oneOf":[{"$ref":"#/components/schemas/ListMutationRequest"},{"$ref":"#/components/schemas/TaskMutationRequest"}]},"MutationSuccessResponse":{"type":"object","required":["record"],"properties":{"record":{"$ref":"#/components/schemas/TodoRecord"}}},"MutationConflictResponse":{"type":"object","required":["error"],"properties":{"error":{"type":"string","enum":["version_conflict","mutation_reused","list_not_found","list_not_empty"]},"record":{"oneOf":[{"$ref":"#/components/schemas/TodoRecord"},{"type":"null"}]}}},"ImportListMutationItem":{"type":"object","required":["mutationId","id","kind","version","value"],"properties":{"mutationId":{"type":"string","format":"uuid"},"id":{"type":"string","format":"uuid"},"kind":{"type":"string","const":"list"},"version":{"type":"integer","const":0},"value":{"$ref":"#/components/schemas/TodoListValue"}}},"ImportTaskMutationItem":{"type":"object","required":["mutationId","id","kind","version","value"],"properties":{"mutationId":{"type":"string","format":"uuid"},"id":{"type":"string","format":"uuid"},"kind":{"type":"string","const":"task"},"version":{"type":"integer","const":0},"value":{"$ref":"#/components/schemas/TodoImportTaskValue"}}},"ImportMutationItem":{"oneOf":[{"$ref":"#/components/schemas/ImportListMutationItem"},{"$ref":"#/components/schemas/ImportTaskMutationItem"}]},"ImportRequest":{"type":"object","required":["mutations"],"properties":{"mutations":{"type":"array","minItems":1,"maxItems":50,"items":{"$ref":"#/components/schemas/ImportMutationItem"}}}},"ImportItemResult":{"type":"object","required":["id","status"],"properties":{"id":{"type":"string","format":"uuid"},"status":{"type":"string","enum":["ready","created","existing","conflict","deleted","missing_list"]}}},"ImportResponse":{"type":"object","required":["items"],"properties":{"items":{"type":"array","items":{"$ref":"#/components/schemas/ImportItemResult"}}}},"ExportSnapshot":{"type":"object","required":["format","version","exportedAt","records"],"properties":{"format":{"type":"string","const":"yunlefun/todo-backup"},"version":{"type":"integer","const":1},"exportedAt":{"type":"string","format":"date-time"},"records":{"type":"array","items":{"$ref":"#/components/schemas/TodoRecord"}}}},"ErrorResponse":{"type":"object","required":["error"],"properties":{"statusCode":{"type":"integer"},"error":{"type":"string"},"message":{"type":"string"}}}}}}