{
  "openapi": "3.0.0",
  "info": {
    "title": "n8n 公共 API",
    "version": "1.1.1"
  },
  "tags": [
    {
      "name": "DataTable",
      "description": "数据表及其行相关操作"
    }
  ],
  "servers": [
    {
      "url": "/api/v1",
      "description": "当前 n8n 实例（自托管版本的内置测试台）"
    },
    {
      "url": "{url}/api/v1",
      "description": "自托管 n8n 实例",
      "variables": {
        "url": {
          "default": "https://example.com"
        }
      }
    }
  ],
  "security": [
    {
      "ApiKeyAuth": []
    },
    {
      "BearerAuth": []
    },
    {
      "CookieAuth": []
    }
  ],
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-N8N-API-KEY"
      },
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      },
      "CookieAuth": {
        "type": "apiKey",
        "in": "cookie",
        "name": "n8n-auth"
      }
    },
    "parameters": {
      "limit": {
        "name": "limit",
        "in": "query",
        "description": "最多返回的数据项数量。",
        "required": false,
        "schema": {
          "type": "number",
          "default": 100,
          "maximum": 250
        }
      },
      "cursor": {
        "name": "cursor",
        "in": "query",
        "description": "将 cursor 参数设为上次请求响应中的 nextCursor 属性，以进行分页。使用默认值时，获取集合的第一页。更多信息，请参阅分页说明。",
        "required": false,
        "style": "form",
        "schema": {
          "type": "string"
        }
      }
    },
    "responses": {
      "badRequest": {
        "description": "请求无效，或提供的数据格式错误。"
      },
      "unauthorized": {
        "description": "未授权"
      },
      "forbidden": {
        "description": "禁止访问"
      }
    }
  },
  "paths": {
    "/data-tables": {
      "get": {
        "operationId": "listDataTables",
        "tags": [
          "DataTable"
        ],
        "summary": "列出所有数据表",
        "description": "获取所有数据表的列表，可选择筛选、排序和分页。每个表都包含 `sizeBytes`，`size` 排序选项按此值排序。",
        "parameters": [
          {
            "$ref": "#/components/parameters/limit"
          },
          {
            "$ref": "#/components/parameters/cursor"
          },
          {
            "schema": {
              "type": "string",
              "format": "jsonString"
            },
            "required": false,
            "description": "筛选条件的 JSON 字符串",
            "name": "filter",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "name:asc",
                "name:desc",
                "createdAt:asc",
                "createdAt:desc",
                "updatedAt:asc",
                "updatedAt:desc",
                "size:asc",
                "size:desc"
              ]
            },
            "required": false,
            "description": "排序格式：field:asc 或 field:desc",
            "name": "sortBy",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "操作成功。",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "数据表的唯一标识符"
                          },
                          "name": {
                            "type": "string",
                            "description": "数据表名称"
                          },
                          "columns": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "id": {
                                  "type": "string",
                                  "description": "列 ID"
                                },
                                "name": {
                                  "type": "string",
                                  "description": "列名称"
                                },
                                "type": {
                                  "type": "string",
                                  "description": "列的数据类型",
                                  "enum": [
                                    "string",
                                    "number",
                                    "boolean",
                                    "date"
                                  ]
                                },
                                "index": {
                                  "type": "integer",
                                  "description": "列位置"
                                },
                                "createdAt": {
                                  "type": "string",
                                  "format": "date-time",
                                  "description": "列创建的时间戳"
                                },
                                "updatedAt": {
                                  "type": "string",
                                  "format": "date-time",
                                  "description": "列上次更新的时间戳"
                                }
                              },
                              "required": [
                                "id",
                                "name",
                                "type",
                                "index",
                                "createdAt",
                                "updatedAt"
                              ]
                            },
                            "description": "列定义"
                          },
                          "projectId": {
                            "type": "string",
                            "description": "此表所属项目的 ID"
                          },
                          "createdAt": {
                            "type": "string",
                            "format": "date-time",
                            "description": "表创建的时间戳"
                          },
                          "updatedAt": {
                            "type": "string",
                            "format": "date-time",
                            "description": "表上次更新的时间戳"
                          },
                          "sizeBytes": {
                            "type": "integer",
                            "description": "物理存储大小，单位为字节，包括索引和内部开销。删除行后不会立即减少，数值可能延迟几秒更新。"
                          }
                        },
                        "required": [
                          "id",
                          "name",
                          "columns",
                          "projectId",
                          "createdAt",
                          "updatedAt",
                          "sizeBytes"
                        ]
                      }
                    },
                    "nextCursor": {
                      "type": "string",
                      "nullable": true,
                      "description": "将 cursor 参数设为先前请求返回的 nextCursor 属性，以对数据表进行分页。使用默认值时，获取集合的第一页。"
                    }
                  },
                  "required": [
                    "data",
                    "nextCursor"
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/badRequest"
          },
          "401": {
            "$ref": "#/components/responses/unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/forbidden"
          }
        }
      }
    }
  }
}
