{
  "openapi": "3.0.0",
  "info": {
    "title": "n8n 公共 API",
    "version": "1.1.1"
  },
  "tags": [
    {
      "name": "Audit",
      "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]+$"
        }
      }
    },
    "schemas": {
      "auditVersion.generated": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "nodes": {
            "type": "array",
            "items": {}
          },
          "createdAt": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "documentationUrl": {
            "type": "string"
          },
          "hasBreakingChange": {
            "type": "boolean"
          },
          "hasSecurityFix": {
            "type": "boolean",
            "nullable": true
          },
          "hasSecurityIssue": {
            "type": "boolean",
            "nullable": true
          },
          "securityIssueFixVersion": {
            "type": "string",
            "nullable": true
          }
        },
        "required": [
          "name",
          "nodes",
          "createdAt",
          "description",
          "documentationUrl",
          "hasBreakingChange",
          "hasSecurityFix",
          "hasSecurityIssue",
          "securityIssueFixVersion"
        ]
      }
    },
    "responses": {
      "badRequest": {
        "description": "请求无效，或提供的数据格式错误。"
      },
      "unauthorized": {
        "description": "未授权"
      },
      "forbidden": {
        "description": "禁止访问"
      },
      "conflict": {
        "description": "冲突"
      },
      "unsupportedMediaType": {
        "description": "不支持的媒体类型。"
      },
      "unprocessableEntity": {
        "description": "无法处理的实体"
      },
      "internalServerError": {
        "description": "服务器内部错误。"
      }
    }
  },
  "paths": {
    "/audit": {
      "post": {
        "operationId": "generateAudit",
        "tags": [
          "Audit"
        ],
        "summary": "生成审计报告",
        "description": "为 n8n 实例生成安全审计报告。",
        "parameters": [
          {
            "$ref": "#/components/parameters/idempotencyKey"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "additionalOptions": {
                    "type": "object",
                    "properties": {
                      "daysAbandonedWorkflow": {
                        "type": "integer",
                        "description": "工作流连续未执行多少天后视为废弃"
                      },
                      "categories": {
                        "type": "array",
                        "items": {
                          "type": "string",
                          "enum": [
                            "credentials",
                            "database",
                            "nodes",
                            "filesystem",
                            "instance"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "操作成功。",
            "content": {
              "application/json": {
                "schema": {
                  "anyOf": [
                    {
                      "type": "object",
                      "properties": {
                        "Credentials Risk Report": {
                          "type": "object",
                          "properties": {
                            "risk": {
                              "type": "string",
                              "enum": [
                                "credentials",
                                "database",
                                "nodes",
                                "filesystem",
                                "instance"
                              ]
                            },
                            "sections": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "title": {
                                    "type": "string"
                                  },
                                  "description": {
                                    "type": "string"
                                  },
                                  "recommendation": {
                                    "type": "string"
                                  },
                                  "location": {
                                    "type": "array",
                                    "items": {
                                      "oneOf": [
                                        {
                                          "type": "object",
                                          "properties": {
                                            "kind": {
                                              "type": "string",
                                              "enum": [
                                                "node"
                                              ]
                                            },
                                            "workflowId": {
                                              "type": "string"
                                            },
                                            "workflowName": {
                                              "type": "string"
                                            },
                                            "nodeId": {
                                              "type": "string"
                                            },
                                            "nodeName": {
                                              "type": "string"
                                            },
                                            "nodeType": {
                                              "type": "string"
                                            }
                                          },
                                          "required": [
                                            "kind",
                                            "workflowId",
                                            "workflowName",
                                            "nodeId",
                                            "nodeName",
                                            "nodeType"
                                          ]
                                        },
                                        {
                                          "type": "object",
                                          "properties": {
                                            "kind": {
                                              "type": "string",
                                              "enum": [
                                                "credential"
                                              ]
                                            },
                                            "id": {
                                              "type": "string"
                                            },
                                            "name": {
                                              "type": "string"
                                            }
                                          },
                                          "required": [
                                            "kind",
                                            "id",
                                            "name"
                                          ]
                                        },
                                        {
                                          "type": "object",
                                          "properties": {
                                            "kind": {
                                              "type": "string",
                                              "enum": [
                                                "community"
                                              ]
                                            },
                                            "nodeType": {
                                              "type": "string"
                                            },
                                            "packageUrl": {
                                              "type": "string"
                                            }
                                          },
                                          "required": [
                                            "kind",
                                            "nodeType",
                                            "packageUrl"
                                          ]
                                        },
                                        {
                                          "type": "object",
                                          "properties": {
                                            "kind": {
                                              "type": "string",
                                              "enum": [
                                                "custom"
                                              ]
                                            },
                                            "nodeType": {
                                              "type": "string"
                                            },
                                            "filePath": {
                                              "type": "string"
                                            }
                                          },
                                          "required": [
                                            "kind",
                                            "nodeType",
                                            "filePath"
                                          ]
                                        }
                                      ],
                                      "type": "object"
                                    }
                                  },
                                  "settings": {
                                    "type": "object",
                                    "additionalProperties": {}
                                  },
                                  "nextVersions": {
                                    "type": "array",
                                    "items": {
                                      "$ref": "#/components/schemas/auditVersion.generated"
                                    }
                                  }
                                },
                                "required": [
                                  "title",
                                  "description",
                                  "recommendation"
                                ]
                              }
                            }
                          },
                          "required": [
                            "risk",
                            "sections"
                          ]
                        },
                        "Database Risk Report": {
                          "type": "object",
                          "properties": {
                            "risk": {
                              "type": "string",
                              "enum": [
                                "credentials",
                                "database",
                                "nodes",
                                "filesystem",
                                "instance"
                              ]
                            },
                            "sections": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "title": {
                                    "type": "string"
                                  },
                                  "description": {
                                    "type": "string"
                                  },
                                  "recommendation": {
                                    "type": "string"
                                  },
                                  "location": {
                                    "type": "array",
                                    "items": {
                                      "oneOf": [
                                        {
                                          "type": "object",
                                          "properties": {
                                            "kind": {
                                              "type": "string",
                                              "enum": [
                                                "node"
                                              ]
                                            },
                                            "workflowId": {
                                              "type": "string"
                                            },
                                            "workflowName": {
                                              "type": "string"
                                            },
                                            "nodeId": {
                                              "type": "string"
                                            },
                                            "nodeName": {
                                              "type": "string"
                                            },
                                            "nodeType": {
                                              "type": "string"
                                            }
                                          },
                                          "required": [
                                            "kind",
                                            "workflowId",
                                            "workflowName",
                                            "nodeId",
                                            "nodeName",
                                            "nodeType"
                                          ]
                                        },
                                        {
                                          "type": "object",
                                          "properties": {
                                            "kind": {
                                              "type": "string",
                                              "enum": [
                                                "credential"
                                              ]
                                            },
                                            "id": {
                                              "type": "string"
                                            },
                                            "name": {
                                              "type": "string"
                                            }
                                          },
                                          "required": [
                                            "kind",
                                            "id",
                                            "name"
                                          ]
                                        },
                                        {
                                          "type": "object",
                                          "properties": {
                                            "kind": {
                                              "type": "string",
                                              "enum": [
                                                "community"
                                              ]
                                            },
                                            "nodeType": {
                                              "type": "string"
                                            },
                                            "packageUrl": {
                                              "type": "string"
                                            }
                                          },
                                          "required": [
                                            "kind",
                                            "nodeType",
                                            "packageUrl"
                                          ]
                                        },
                                        {
                                          "type": "object",
                                          "properties": {
                                            "kind": {
                                              "type": "string",
                                              "enum": [
                                                "custom"
                                              ]
                                            },
                                            "nodeType": {
                                              "type": "string"
                                            },
                                            "filePath": {
                                              "type": "string"
                                            }
                                          },
                                          "required": [
                                            "kind",
                                            "nodeType",
                                            "filePath"
                                          ]
                                        }
                                      ],
                                      "type": "object"
                                    }
                                  },
                                  "settings": {
                                    "type": "object",
                                    "additionalProperties": {}
                                  },
                                  "nextVersions": {
                                    "type": "array",
                                    "items": {
                                      "$ref": "#/components/schemas/auditVersion.generated"
                                    }
                                  }
                                },
                                "required": [
                                  "title",
                                  "description",
                                  "recommendation"
                                ]
                              }
                            }
                          },
                          "required": [
                            "risk",
                            "sections"
                          ]
                        },
                        "Filesystem Risk Report": {
                          "type": "object",
                          "properties": {
                            "risk": {
                              "type": "string",
                              "enum": [
                                "credentials",
                                "database",
                                "nodes",
                                "filesystem",
                                "instance"
                              ]
                            },
                            "sections": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "title": {
                                    "type": "string"
                                  },
                                  "description": {
                                    "type": "string"
                                  },
                                  "recommendation": {
                                    "type": "string"
                                  },
                                  "location": {
                                    "type": "array",
                                    "items": {
                                      "oneOf": [
                                        {
                                          "type": "object",
                                          "properties": {
                                            "kind": {
                                              "type": "string",
                                              "enum": [
                                                "node"
                                              ]
                                            },
                                            "workflowId": {
                                              "type": "string"
                                            },
                                            "workflowName": {
                                              "type": "string"
                                            },
                                            "nodeId": {
                                              "type": "string"
                                            },
                                            "nodeName": {
                                              "type": "string"
                                            },
                                            "nodeType": {
                                              "type": "string"
                                            }
                                          },
                                          "required": [
                                            "kind",
                                            "workflowId",
                                            "workflowName",
                                            "nodeId",
                                            "nodeName",
                                            "nodeType"
                                          ]
                                        },
                                        {
                                          "type": "object",
                                          "properties": {
                                            "kind": {
                                              "type": "string",
                                              "enum": [
                                                "credential"
                                              ]
                                            },
                                            "id": {
                                              "type": "string"
                                            },
                                            "name": {
                                              "type": "string"
                                            }
                                          },
                                          "required": [
                                            "kind",
                                            "id",
                                            "name"
                                          ]
                                        },
                                        {
                                          "type": "object",
                                          "properties": {
                                            "kind": {
                                              "type": "string",
                                              "enum": [
                                                "community"
                                              ]
                                            },
                                            "nodeType": {
                                              "type": "string"
                                            },
                                            "packageUrl": {
                                              "type": "string"
                                            }
                                          },
                                          "required": [
                                            "kind",
                                            "nodeType",
                                            "packageUrl"
                                          ]
                                        },
                                        {
                                          "type": "object",
                                          "properties": {
                                            "kind": {
                                              "type": "string",
                                              "enum": [
                                                "custom"
                                              ]
                                            },
                                            "nodeType": {
                                              "type": "string"
                                            },
                                            "filePath": {
                                              "type": "string"
                                            }
                                          },
                                          "required": [
                                            "kind",
                                            "nodeType",
                                            "filePath"
                                          ]
                                        }
                                      ],
                                      "type": "object"
                                    }
                                  },
                                  "settings": {
                                    "type": "object",
                                    "additionalProperties": {}
                                  },
                                  "nextVersions": {
                                    "type": "array",
                                    "items": {
                                      "$ref": "#/components/schemas/auditVersion.generated"
                                    }
                                  }
                                },
                                "required": [
                                  "title",
                                  "description",
                                  "recommendation"
                                ]
                              }
                            }
                          },
                          "required": [
                            "risk",
                            "sections"
                          ]
                        },
                        "Nodes Risk Report": {
                          "type": "object",
                          "properties": {
                            "risk": {
                              "type": "string",
                              "enum": [
                                "credentials",
                                "database",
                                "nodes",
                                "filesystem",
                                "instance"
                              ]
                            },
                            "sections": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "title": {
                                    "type": "string"
                                  },
                                  "description": {
                                    "type": "string"
                                  },
                                  "recommendation": {
                                    "type": "string"
                                  },
                                  "location": {
                                    "type": "array",
                                    "items": {
                                      "oneOf": [
                                        {
                                          "type": "object",
                                          "properties": {
                                            "kind": {
                                              "type": "string",
                                              "enum": [
                                                "node"
                                              ]
                                            },
                                            "workflowId": {
                                              "type": "string"
                                            },
                                            "workflowName": {
                                              "type": "string"
                                            },
                                            "nodeId": {
                                              "type": "string"
                                            },
                                            "nodeName": {
                                              "type": "string"
                                            },
                                            "nodeType": {
                                              "type": "string"
                                            }
                                          },
                                          "required": [
                                            "kind",
                                            "workflowId",
                                            "workflowName",
                                            "nodeId",
                                            "nodeName",
                                            "nodeType"
                                          ]
                                        },
                                        {
                                          "type": "object",
                                          "properties": {
                                            "kind": {
                                              "type": "string",
                                              "enum": [
                                                "credential"
                                              ]
                                            },
                                            "id": {
                                              "type": "string"
                                            },
                                            "name": {
                                              "type": "string"
                                            }
                                          },
                                          "required": [
                                            "kind",
                                            "id",
                                            "name"
                                          ]
                                        },
                                        {
                                          "type": "object",
                                          "properties": {
                                            "kind": {
                                              "type": "string",
                                              "enum": [
                                                "community"
                                              ]
                                            },
                                            "nodeType": {
                                              "type": "string"
                                            },
                                            "packageUrl": {
                                              "type": "string"
                                            }
                                          },
                                          "required": [
                                            "kind",
                                            "nodeType",
                                            "packageUrl"
                                          ]
                                        },
                                        {
                                          "type": "object",
                                          "properties": {
                                            "kind": {
                                              "type": "string",
                                              "enum": [
                                                "custom"
                                              ]
                                            },
                                            "nodeType": {
                                              "type": "string"
                                            },
                                            "filePath": {
                                              "type": "string"
                                            }
                                          },
                                          "required": [
                                            "kind",
                                            "nodeType",
                                            "filePath"
                                          ]
                                        }
                                      ],
                                      "type": "object"
                                    }
                                  },
                                  "settings": {
                                    "type": "object",
                                    "additionalProperties": {}
                                  },
                                  "nextVersions": {
                                    "type": "array",
                                    "items": {
                                      "$ref": "#/components/schemas/auditVersion.generated"
                                    }
                                  }
                                },
                                "required": [
                                  "title",
                                  "description",
                                  "recommendation"
                                ]
                              }
                            }
                          },
                          "required": [
                            "risk",
                            "sections"
                          ]
                        },
                        "Instance Risk Report": {
                          "type": "object",
                          "properties": {
                            "risk": {
                              "type": "string",
                              "enum": [
                                "credentials",
                                "database",
                                "nodes",
                                "filesystem",
                                "instance"
                              ]
                            },
                            "sections": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "title": {
                                    "type": "string"
                                  },
                                  "description": {
                                    "type": "string"
                                  },
                                  "recommendation": {
                                    "type": "string"
                                  },
                                  "location": {
                                    "type": "array",
                                    "items": {
                                      "oneOf": [
                                        {
                                          "type": "object",
                                          "properties": {
                                            "kind": {
                                              "type": "string",
                                              "enum": [
                                                "node"
                                              ]
                                            },
                                            "workflowId": {
                                              "type": "string"
                                            },
                                            "workflowName": {
                                              "type": "string"
                                            },
                                            "nodeId": {
                                              "type": "string"
                                            },
                                            "nodeName": {
                                              "type": "string"
                                            },
                                            "nodeType": {
                                              "type": "string"
                                            }
                                          },
                                          "required": [
                                            "kind",
                                            "workflowId",
                                            "workflowName",
                                            "nodeId",
                                            "nodeName",
                                            "nodeType"
                                          ]
                                        },
                                        {
                                          "type": "object",
                                          "properties": {
                                            "kind": {
                                              "type": "string",
                                              "enum": [
                                                "credential"
                                              ]
                                            },
                                            "id": {
                                              "type": "string"
                                            },
                                            "name": {
                                              "type": "string"
                                            }
                                          },
                                          "required": [
                                            "kind",
                                            "id",
                                            "name"
                                          ]
                                        },
                                        {
                                          "type": "object",
                                          "properties": {
                                            "kind": {
                                              "type": "string",
                                              "enum": [
                                                "community"
                                              ]
                                            },
                                            "nodeType": {
                                              "type": "string"
                                            },
                                            "packageUrl": {
                                              "type": "string"
                                            }
                                          },
                                          "required": [
                                            "kind",
                                            "nodeType",
                                            "packageUrl"
                                          ]
                                        },
                                        {
                                          "type": "object",
                                          "properties": {
                                            "kind": {
                                              "type": "string",
                                              "enum": [
                                                "custom"
                                              ]
                                            },
                                            "nodeType": {
                                              "type": "string"
                                            },
                                            "filePath": {
                                              "type": "string"
                                            }
                                          },
                                          "required": [
                                            "kind",
                                            "nodeType",
                                            "filePath"
                                          ]
                                        }
                                      ],
                                      "type": "object"
                                    }
                                  },
                                  "settings": {
                                    "type": "object",
                                    "additionalProperties": {}
                                  },
                                  "nextVersions": {
                                    "type": "array",
                                    "items": {
                                      "$ref": "#/components/schemas/auditVersion.generated"
                                    }
                                  }
                                },
                                "required": [
                                  "title",
                                  "description",
                                  "recommendation"
                                ]
                              }
                            }
                          },
                          "required": [
                            "risk",
                            "sections"
                          ]
                        }
                      }
                    },
                    {
                      "type": "array",
                      "items": {},
                      "maxItems": 0
                    }
                  ]
                }
              }
            }
          },
          "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"
          },
          "500": {
            "$ref": "#/components/responses/internalServerError"
          }
        }
      }
    }
  }
}
