{
  "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"
      }
    },
    "responses": {
      "badRequest": {
        "description": "请求无效，或提供的数据格式错误。"
      },
      "unauthorized": {
        "description": "未授权"
      },
      "forbidden": {
        "description": "禁止访问"
      },
      "notFound": {
        "description": "未找到指定资源。"
      },
      "unsupportedMediaType": {
        "description": "不支持的媒体类型。"
      }
    }
  },
  "paths": {
    "/data-tables/{dataTableId}/rows/update": {
      "patch": {
        "operationId": "updateDataTableRows",
        "tags": [
          "DataTable"
        ],
        "summary": "更新数据表中的行",
        "description": "更新数据表中符合筛选条件的行。",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "format": "nanoid",
              "pattern": "^[A-Za-z0-9]{16}$"
            },
            "required": true,
            "description": "数据表的 ID",
            "name": "dataTableId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "filter": {
                    "type": "object",
                    "properties": {
                      "type": {
                        "anyOf": [
                          {
                            "type": "string",
                            "enum": [
                              "and"
                            ]
                          },
                          {
                            "type": "string",
                            "enum": [
                              "or"
                            ]
                          }
                        ],
                        "default": "and"
                      },
                      "filters": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "columnName": {
                              "type": "string",
                              "minLength": 1,
                              "maxLength": 63,
                              "pattern": "^[a-zA-Z][a-zA-Z0-9_]*$"
                            },
                            "condition": {
                              "anyOf": [
                                {
                                  "type": "string",
                                  "enum": [
                                    "eq"
                                  ]
                                },
                                {
                                  "type": "string",
                                  "enum": [
                                    "neq"
                                  ]
                                },
                                {
                                  "type": "string",
                                  "enum": [
                                    "like"
                                  ]
                                },
                                {
                                  "type": "string",
                                  "enum": [
                                    "ilike"
                                  ]
                                },
                                {
                                  "type": "string",
                                  "enum": [
                                    "gt"
                                  ]
                                },
                                {
                                  "type": "string",
                                  "enum": [
                                    "gte"
                                  ]
                                },
                                {
                                  "type": "string",
                                  "enum": [
                                    "lt"
                                  ]
                                },
                                {
                                  "type": "string",
                                  "enum": [
                                    "lte"
                                  ]
                                }
                              ]
                            },
                            "value": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "number"
                                },
                                {
                                  "type": "boolean"
                                },
                                {
                                  "type": "string"
                                },
                                {},
                                {}
                              ]
                            }
                          },
                          "required": [
                            "columnName",
                            "condition",
                            "value"
                          ]
                        },
                        "minItems": 1
                      }
                    },
                    "required": [
                      "filters"
                    ],
                    "description": "匹配待更新行的筛选条件。"
                  },
                  "data": {
                    "type": "object",
                    "additionalProperties": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "number"
                        },
                        {
                          "type": "boolean"
                        },
                        {},
                        {
                          "type": "string"
                        },
                        {}
                      ]
                    },
                    "description": "待更新的列值"
                  },
                  "returnData": {
                    "type": "boolean",
                    "default": false,
                    "description": "设为 true 时，返回更新后的行；设为 false 时，成功后返回 true。"
                  },
                  "dryRun": {
                    "type": "boolean",
                    "default": false,
                    "description": "设为 true 时，仅预览变更，不保存。"
                  }
                },
                "required": [
                  "filter",
                  "data"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "操作成功。",
            "content": {
              "application/json": {
                "schema": {
                  "anyOf": [
                    {
                      "type": "boolean",
                      "description": "returnData 为 false 且 dryRun 为 false 时返回"
                    },
                    {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "integer",
                            "nullable": true,
                            "description": "行 ID，自动生成"
                          },
                          "createdAt": {
                            "type": "string",
                            "nullable": true,
                            "format": "date-time",
                            "description": "行创建的日期和时间"
                          },
                          "updatedAt": {
                            "type": "string",
                            "nullable": true,
                            "format": "date-time",
                            "description": "行上次更新的日期和时间"
                          },
                          "dryRunState": {
                            "type": "string",
                            "enum": [
                              "before",
                              "after"
                            ],
                            "description": "此条目显示的是变更前还是变更后的行状态"
                          }
                        },
                        "required": [
                          "id",
                          "createdAt",
                          "updatedAt",
                          "dryRunState"
                        ]
                      },
                      "description": "dryRun 为 true 时返回，每行的变更前和变更后状态各有一个条目"
                    },
                    {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "integer",
                            "description": "行 ID，自动生成"
                          },
                          "createdAt": {
                            "type": "string",
                            "format": "date-time",
                            "description": "行创建的日期和时间"
                          },
                          "updatedAt": {
                            "type": "string",
                            "format": "date-time",
                            "description": "行上次更新的日期和时间"
                          }
                        },
                        "required": [
                          "id",
                          "createdAt",
                          "updatedAt"
                        ],
                        "description": "数据表中的一行，包含系统列（id、createdAt、updatedAt）和用户自定义列"
                      },
                      "description": "returnData 为 true 且 dryRun 为 false 时返回"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/badRequest"
          },
          "401": {
            "$ref": "#/components/responses/unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/forbidden"
          },
          "404": {
            "$ref": "#/components/responses/notFound"
          },
          "415": {
            "$ref": "#/components/responses/unsupportedMediaType"
          }
        }
      }
    }
  }
}
