{
  "openapi": "3.0.0",
  "info": {
    "title": "n8n 公共 API",
    "version": "1.1.1"
  },
  "tags": [
    {
      "name": "CommunityPackage",
      "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": {
      "idempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "description": "此 POST 请求的安全重试键。使用 1 到 128 个可见 ASCII 字符。相同的键配合相同的请求，会返回首次成功的响应。使用此键发送不同请求时返回 422。首次请求仍在处理时重试，会返回 409。",
        "required": false,
        "schema": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128,
          "pattern": "^[\\x21-\\x7E]+$"
        }
      }
    },
    "responses": {
      "badRequest": {
        "description": "请求无效，或提供的数据格式错误。"
      },
      "unauthorized": {
        "description": "未授权"
      },
      "forbidden": {
        "description": "禁止访问"
      },
      "conflict": {
        "description": "冲突"
      },
      "unsupportedMediaType": {
        "description": "不支持的媒体类型。"
      },
      "unprocessableEntity": {
        "description": "无法处理的实体"
      }
    }
  },
  "paths": {
    "/community-packages": {
      "post": {
        "operationId": "installPackage",
        "tags": [
          "CommunityPackage"
        ],
        "summary": "安装社区包",
        "description": "根据 npm 包名称及可选版本安装社区包。",
        "parameters": [
          {
            "$ref": "#/components/parameters/idempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "npm 包名称。不带作用域的名称以 n8n-nodes- 开头；带作用域的名称采用 @[author]/n8n-nodes- 格式。"
                  },
                  "version": {
                    "type": "string",
                    "description": "Semver 版本或 npm dist-tag，例如 latest 或 beta。禁用未验证的包时，只能安装经过 n8n 验证的版本。"
                  }
                },
                "required": [
                  "name"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "操作成功。",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "packageName": {
                      "type": "string",
                      "description": "npm 包名称"
                    },
                    "installedVersion": {
                      "type": "string",
                      "description": "当前安装的版本"
                    },
                    "authorName": {
                      "type": "string",
                      "description": "包作者姓名"
                    },
                    "authorEmail": {
                      "type": "string",
                      "description": "包作者邮箱"
                    },
                    "installedNodes": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "name": {
                            "type": "string"
                          },
                          "type": {
                            "type": "string"
                          },
                          "latestVersion": {
                            "type": "number"
                          }
                        }
                      },
                      "description": "此包包含的节点"
                    },
                    "createdAt": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "updatedAt": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "updateAvailable": {
                      "type": "string",
                      "description": "可更新到的版本（如有）"
                    },
                    "failedLoading": {
                      "type": "boolean",
                      "description": "此包是否加载失败"
                    },
                    "policyRestrictions": {
                      "type": "object",
                      "properties": {
                        "nodeTypes": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "完整节点类型名称，例如 n8n-nodes-example.exampleNode。"
                              },
                              "blockedOn": {
                                "type": "string",
                                "enum": [
                                  "instance",
                                  "projects"
                                ],
                                "description": "instance：默认在实例上阻止；projects：在实例上允许，但在一个或多个项目中阻止。"
                              },
                              "optInAvailable": {
                                "type": "boolean",
                                "description": "项目能否允许此节点类型。当实例策略阻止此节点类型、但允许项目将其设为允许时，此值为 True。"
                              }
                            },
                            "required": [
                              "type",
                              "blockedOn",
                              "optInAvailable"
                            ]
                          },
                          "description": "此包中被阻止的节点类型，仅列出被阻止的类型。"
                        }
                      },
                      "required": [
                        "nodeTypes"
                      ],
                      "description": "此包中被节点类型策略阻止的节点类型。策略不会导致安装失败。未评估任何策略时不返回此字段，例如未获得节点类型策略功能许可时。nodeTypes 列表为空，表示没有策略阻止此包中的节点类型。"
                    }
                  },
                  "required": [
                    "packageName",
                    "installedVersion",
                    "installedNodes",
                    "createdAt",
                    "updatedAt"
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/badRequest"
          },
          "401": {
            "$ref": "#/components/responses/unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/forbidden"
          },
          "409": {
            "$ref": "#/components/responses/conflict"
          },
          "415": {
            "$ref": "#/components/responses/unsupportedMediaType"
          },
          "422": {
            "$ref": "#/components/responses/unprocessableEntity"
          }
        }
      }
    }
  }
}
