{
  "openapi": "3.0.0",
  "info": {
    "title": "n8n 公共 API",
    "version": "1.1.1"
  },
  "tags": [
    {
      "name": "SettingsLdap",
      "description": "LDAP 设置相关操作"
    }
  ],
  "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"
      }
    },
    "schemas": {
      "ldapConfigurationPublicDto.generated": {
        "type": "object",
        "properties": {
          "loginEnabled": {
            "type": "boolean",
            "description": "是否启用 LDAP 登录。"
          },
          "loginLabel": {
            "type": "string",
            "description": "LDAP 登录按钮显示的标签。"
          },
          "connectionUrl": {
            "type": "string",
            "description": "LDAP 服务器 URL。"
          },
          "allowUnauthorizedCerts": {
            "type": "boolean",
            "description": "是否允许不受信任的证书（自签名证书）。"
          },
          "connectionSecurity": {
            "type": "string",
            "enum": [
              "none",
              "tls",
              "startTls"
            ],
            "description": "LDAP 连接的 TLS/SSL 安全模式。"
          },
          "connectionPort": {
            "type": "number",
            "description": "LDAP 服务器端口。"
          },
          "baseDn": {
            "type": "string",
            "description": "LDAP 搜索查询的基础 DN。"
          },
          "bindingAdminDn": {
            "type": "string",
            "description": "用于绑定的 LDAP 管理员用户 DN。"
          },
          "bindingAdminPassword": {
            "type": "string",
            "description": "LDAP 管理员用户密码。GET 读取时会遮蔽：已存储密码时返回遮蔽占位符，未设置时返回空字符串。提交先前 GET 返回的遮蔽占位符，可保持已存储密码不变。"
          },
          "firstNameAttribute": {
            "type": "string",
            "description": "映射到用户名字的 LDAP 属性。"
          },
          "lastNameAttribute": {
            "type": "string",
            "description": "映射到用户姓氏的 LDAP 属性。"
          },
          "emailAttribute": {
            "type": "string",
            "description": "映射到用户邮箱的 LDAP 属性。"
          },
          "loginIdAttribute": {
            "type": "string",
            "description": "用于登录的 LDAP 属性，通常与 emailAttribute 相同。"
          },
          "ldapIdAttribute": {
            "type": "string",
            "description": "用于唯一标识用户的 LDAP 属性。"
          },
          "userFilter": {
            "type": "string",
            "description": "搜索用户时使用的附加 LDAP 筛选条件；空字符串表示无附加筛选条件。"
          },
          "synchronizationEnabled": {
            "type": "boolean",
            "description": "是否启用 LDAP 自动同步。"
          },
          "synchronizationInterval": {
            "type": "number",
            "description": "自动同步的间隔，单位为分钟；synchronizationEnabled 为 false 时忽略。"
          },
          "searchPageSize": {
            "type": "number",
            "description": "每页搜索获取的 LDAP 条目数量。"
          },
          "searchTimeout": {
            "type": "number",
            "description": "LDAP 搜索超时时长，单位为秒。"
          },
          "enforceEmailUniqueness": {
            "type": "boolean",
            "description": "是否强制 LDAP 用户邮箱唯一。为 true 时，如果两个用户邮箱相同，只导入第一个用户。"
          },
          "linkExistingAccountsByEmail": {
            "type": "boolean",
            "description": "是否允许将 LDAP 用户关联到邮箱相同的现有 n8n 账户。为 false 时，登录和同步都会跳过此类用户。PUT 中此字段可选，省略时保留已存储的值。"
          }
        },
        "required": [
          "loginEnabled",
          "loginLabel",
          "connectionUrl",
          "allowUnauthorizedCerts",
          "connectionSecurity",
          "connectionPort",
          "baseDn",
          "bindingAdminDn",
          "bindingAdminPassword",
          "firstNameAttribute",
          "lastNameAttribute",
          "emailAttribute",
          "loginIdAttribute",
          "ldapIdAttribute",
          "userFilter",
          "synchronizationEnabled",
          "synchronizationInterval",
          "searchPageSize",
          "searchTimeout",
          "enforceEmailUniqueness",
          "linkExistingAccountsByEmail"
        ],
        "description": "完整 LDAP 配置。GET 返回所有字段；请将完整对象作为 PUT 请求体提交。",
        "additionalProperties": false
      }
    },
    "responses": {
      "unauthorized": {
        "description": "未授权"
      },
      "forbidden": {
        "description": "禁止访问"
      }
    }
  },
  "paths": {
    "/settings/ldap": {
      "get": {
        "operationId": "getLdapConfiguration",
        "tags": [
          "SettingsLdap"
        ],
        "summary": "获取 LDAP 配置",
        "description": "获取当前 LDAP 配置，包括界面中提供的所有字段。读取时会遮蔽绑定管理员密码。需要 `ldap:manage` 作用域，并获得 LDAP 功能许可。",
        "responses": {
          "200": {
            "description": "操作成功。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ldapConfigurationPublicDto.generated"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/forbidden"
          }
        }
      }
    }
  }
}
