{
  "openapi": "3.0.0",
  "info": {
    "title": "n8n 公共 API",
    "version": "1.1.1"
  },
  "tags": [
    {
      "name": "SecurityPolicy",
      "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"
      }
    },
    "schemas": {
      "securityPolicyPublicDto.generated": {
        "type": "object",
        "properties": {
          "personalSpacePublishing": {
            "type": "boolean",
            "description": "成员是否可以从个人空间发布工作流和智能体。"
          },
          "personalSpaceSharing": {
            "type": "boolean",
            "description": "成员是否可以从个人空间共享工作流和凭据。"
          },
          "publishedPersonalWorkflowsCount": {
            "type": "integer",
            "description": "当前已发布的个人工作流数量，用于收紧策略前了解影响。",
            "readOnly": true
          },
          "sharedPersonalWorkflowsCount": {
            "type": "integer",
            "description": "当前与其他用户共享的个人工作流数量。",
            "readOnly": true
          },
          "sharedPersonalCredentialsCount": {
            "type": "integer",
            "description": "当前与其他用户共享的个人凭据数量。",
            "readOnly": true
          },
          "redactionEnforcement": {
            "type": "object",
            "properties": {
              "floor": {
                "type": "string",
                "enum": [
                  "off",
                  "production",
                  "all"
                ],
                "description": "在整个实例上强制执行的最低执行数据遮蔽级别。"
              }
            },
            "required": [
              "floor"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "personalSpacePublishing",
          "personalSpaceSharing",
          "publishedPersonalWorkflowsCount",
          "sharedPersonalWorkflowsCount",
          "sharedPersonalCredentialsCount",
          "redactionEnforcement"
        ],
        "additionalProperties": false
      }
    },
    "responses": {
      "badRequest": {
        "description": "请求无效，或提供的数据格式错误。"
      },
      "unauthorized": {
        "description": "未授权"
      },
      "forbidden": {
        "description": "禁止访问"
      },
      "conflict": {
        "description": "冲突"
      },
      "unsupportedMediaType": {
        "description": "不支持的媒体类型。"
      }
    }
  },
  "paths": {
    "/settings/security-policy": {
      "put": {
        "operationId": "updateSecurityPolicy",
        "tags": [
          "SecurityPolicy"
        ],
        "summary": "设置安全策略",
        "description": "使用提供的完整对象替换实例安全策略，必须发送所有可写字段。若包含 GET 返回的只读使用数量，写入时会忽略，因此可以将 GET 响应作为 PUT 请求体提交。更新使用与界面相同的校验，并以相同方式生效。需要 `securitySettings:manage` 作用域，并获得个人空间策略功能许可。此配置组通过环境变量管理时，写入会以 409 拒绝，且不作任何更改；读取仍返回当前值。",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "personalSpacePublishing": {
                    "type": "boolean",
                    "description": "成员是否可以从个人空间发布工作流和智能体。"
                  },
                  "personalSpaceSharing": {
                    "type": "boolean",
                    "description": "成员是否可以从个人空间共享工作流和凭据。"
                  },
                  "redactionEnforcement": {
                    "type": "object",
                    "properties": {
                      "floor": {
                        "type": "string",
                        "enum": [
                          "off",
                          "production",
                          "all"
                        ],
                        "description": "在整个实例上强制执行的最低执行数据遮蔽级别。"
                      }
                    },
                    "required": [
                      "floor"
                    ],
                    "additionalProperties": false
                  },
                  "publishedPersonalWorkflowsCount": {
                    "type": "integer",
                    "description": "GET 返回的只读使用数量。写入时忽略，因此可以将 GET 响应作为 PUT 请求体提交。"
                  },
                  "sharedPersonalWorkflowsCount": {
                    "type": "integer",
                    "description": "GET 返回的只读使用数量。写入时忽略，因此可以将 GET 响应作为 PUT 请求体提交。"
                  },
                  "sharedPersonalCredentialsCount": {
                    "type": "integer",
                    "description": "GET 返回的只读使用数量。写入时忽略，因此可以将 GET 响应作为 PUT 请求体提交。"
                  }
                },
                "required": [
                  "personalSpacePublishing",
                  "personalSpaceSharing",
                  "redactionEnforcement"
                ],
                "additionalProperties": false,
                "description": "完整安全策略。必须提供所有可写字段，不支持部分更新。"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "操作成功。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/securityPolicyPublicDto.generated"
                }
              }
            }
          },
          "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"
          }
        }
      }
    }
  }
}
