{
  "openapi": "3.0.0",
  "info": {
    "title": "n8n 公共 API",
    "version": "1.1.1"
  },
  "tags": [
    {
      "name": "Folders",
      "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": "未找到指定资源。"
      }
    }
  },
  "paths": {
    "/projects/{projectId}/folders": {
      "get": {
        "operationId": "listFolders",
        "tags": [
          "Folders"
        ],
        "summary": "获取文件夹",
        "description": "获取项目内的文件夹，支持筛选、排序、字段选择和分页。",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "description": "项目的 ID。",
            "name": "projectId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "description": "以 JSON 编码的筛选对象。支持的字段包括 parentFolderId、name、tags（标签名称数组）、excludeFolderIdAndDescendants。"
            },
            "required": false,
            "name": "filter",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "以 JSON 编码的待包含字段数组。有效字段包括 id、name、createdAt、updatedAt、project、tags、parentFolder、workflowCount、subFolderCount、path。"
            },
            "required": false,
            "name": "select",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "name:asc",
                "name:desc",
                "createdAt:asc",
                "createdAt:desc",
                "updatedAt:asc",
                "updatedAt:desc"
              ],
              "description": "结果排序顺序。"
            },
            "required": false,
            "name": "sortBy",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "分页时跳过的数据项数量，默认为 0。"
            },
            "required": false,
            "name": "skip",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "返回的数据项数量，默认为 10。"
            },
            "required": false,
            "name": "take",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "操作成功。",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "count": {
                      "type": "integer",
                      "description": "符合查询条件的文件夹总数。"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "readOnly": true
                          },
                          "name": {
                            "type": "string"
                          },
                          "parentFolderId": {
                            "type": "string",
                            "nullable": true
                          },
                          "createdAt": {
                            "type": "string",
                            "format": "date-time",
                            "readOnly": true
                          },
                          "updatedAt": {
                            "type": "string",
                            "format": "date-time",
                            "readOnly": true
                          },
                          "homeProject": {
                            "type": "object",
                            "properties": {
                              "id": {
                                "type": "string",
                                "readOnly": true
                              },
                              "name": {
                                "type": "string"
                              },
                              "type": {
                                "type": "string",
                                "readOnly": true,
                                "enum": [
                                  "personal",
                                  "team"
                                ]
                              },
                              "icon": {
                                "type": "object",
                                "description": "项目图标；项目没有图标时为 null",
                                "properties": {
                                  "type": {
                                    "type": "string",
                                    "enum": [
                                      "emoji",
                                      "icon"
                                    ]
                                  },
                                  "value": {
                                    "type": "string"
                                  },
                                  "color": {
                                    "type": "string"
                                  }
                                },
                                "required": [
                                  "type",
                                  "value"
                                ],
                                "nullable": true
                              }
                            },
                            "required": [
                              "id",
                              "name",
                              "type",
                              "icon"
                            ]
                          },
                          "parentFolder": {
                            "type": "object",
                            "nullable": true,
                            "properties": {
                              "id": {
                                "type": "string",
                                "readOnly": true
                              },
                              "name": {
                                "type": "string"
                              },
                              "parentFolderId": {
                                "type": "string",
                                "nullable": true
                              }
                            },
                            "required": [
                              "id",
                              "name",
                              "parentFolderId"
                            ]
                          },
                          "tags": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "id": {
                                  "type": "string"
                                },
                                "name": {
                                  "type": "string"
                                }
                              },
                              "required": [
                                "id",
                                "name"
                              ]
                            }
                          },
                          "workflowCount": {
                            "type": "number",
                            "description": "文件夹包含的工作流数量。",
                            "readOnly": true
                          },
                          "subFolderCount": {
                            "type": "number",
                            "description": "文件夹包含的文件夹数量。",
                            "readOnly": true
                          },
                          "path": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            },
                            "description": "从项目根目录到此文件夹路径上每个文件夹的名称。",
                            "readOnly": true
                          }
                        },
                        "required": [
                          "id"
                        ]
                      }
                    }
                  },
                  "required": [
                    "count",
                    "data"
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/badRequest"
          },
          "401": {
            "$ref": "#/components/responses/unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/forbidden"
          },
          "404": {
            "$ref": "#/components/responses/notFound"
          }
        }
      }
    }
  }
}
