{
  "openapi": "3.0.0",
  "info": {
    "title": "n8n 公共 API",
    "version": "1.1.1"
  },
  "tags": [
    {
      "name": "CredentialTypePolicy",
      "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": {
      "credentialTypePolicyDocumentWriteResultPublicDto.generated": {
        "type": "object",
        "properties": {
          "policy": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "kind": {
                "type": "string"
              },
              "rules": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "minLength": 1
                    },
                    "action": {
                      "type": "string",
                      "enum": [
                        "allow",
                        "deny",
                        "delegate"
                      ]
                    },
                    "selector": {
                      "oneOf": [
                        {
                          "type": "object",
                          "properties": {
                            "kind": {
                              "type": "string",
                              "enum": [
                                "name"
                              ]
                            },
                            "value": {
                              "type": "string",
                              "minLength": 1
                            }
                          },
                          "required": [
                            "kind",
                            "value"
                          ]
                        },
                        {
                          "type": "object",
                          "properties": {
                            "kind": {
                              "type": "string",
                              "enum": [
                                "package"
                              ]
                            },
                            "value": {
                              "type": "string",
                              "minLength": 1
                            }
                          },
                          "required": [
                            "kind",
                            "value"
                          ]
                        },
                        {
                          "type": "object",
                          "properties": {
                            "kind": {
                              "type": "string",
                              "enum": [
                                "extends"
                              ]
                            },
                            "value": {
                              "type": "string",
                              "minLength": 1
                            }
                          },
                          "required": [
                            "kind",
                            "value"
                          ],
                          "description": "匹配指定的凭据类型及继承它的所有类型"
                        }
                      ],
                      "type": "object"
                    }
                  },
                  "required": [
                    "id",
                    "action",
                    "selector"
                  ]
                }
              },
              "version": {
                "type": "integer",
                "minimum": 0,
                "exclusiveMinimum": true
              },
              "updatedBy": {
                "type": "string"
              },
              "createdAt": {
                "type": "string",
                "format": "date-time"
              },
              "updatedAt": {
                "type": "string",
                "format": "date-time"
              }
            },
            "required": [
              "id",
              "kind",
              "rules",
              "version",
              "updatedBy",
              "createdAt",
              "updatedAt"
            ]
          },
          "warnings": {
            "type": "array",
            "items": {
              "oneOf": [
                {
                  "type": "object",
                  "properties": {
                    "kind": {
                      "type": "string",
                      "enum": [
                        "shadowed"
                      ]
                    },
                    "ruleId": {
                      "type": "string"
                    },
                    "shadowedByRuleId": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "kind",
                    "ruleId",
                    "shadowedByRuleId"
                  ]
                },
                {
                  "type": "object",
                  "properties": {
                    "kind": {
                      "type": "string",
                      "enum": [
                        "notLoaded"
                      ]
                    },
                    "ruleId": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "kind",
                    "ruleId"
                  ]
                }
              ],
              "type": "object"
            }
          }
        },
        "required": [
          "policy",
          "warnings"
        ]
      }
    },
    "responses": {
      "badRequest": {
        "description": "请求无效，或提供的数据格式错误。"
      },
      "unauthorized": {
        "description": "未授权"
      },
      "forbidden": {
        "description": "禁止访问"
      },
      "notFound": {
        "description": "未找到指定资源。"
      },
      "conflict": {
        "description": "冲突"
      },
      "unsupportedMediaType": {
        "description": "不支持的媒体类型。"
      },
      "serviceUnavailable": {
        "description": "所请求的服务暂时不可用。"
      }
    }
  },
  "paths": {
    "/credential-type-policies/policies/{policyId}": {
      "put": {
        "operationId": "updateCredentialTypePolicyDocument",
        "tags": [
          "CredentialTypePolicy"
        ],
        "summary": "预览：替换凭据类型策略文档的规则",
        "description": "**预览**——即使不提升主版本号，也可能出现破坏性变更。\n\n替换文档的完整规则列表。`version` 必须等于上次读取的版本，过期值会以 409 拒绝。此文档所附加到的每个作用域，其版本都会递增。文档附加到项目作用域时，`delegate` 规则会被拒绝。",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "description": "凭据类型策略文档的 ID。",
            "name": "policyId",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "rules": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "minLength": 1
                        },
                        "action": {
                          "type": "string",
                          "enum": [
                            "allow",
                            "deny",
                            "delegate"
                          ]
                        },
                        "selector": {
                          "oneOf": [
                            {
                              "type": "object",
                              "properties": {
                                "kind": {
                                  "type": "string",
                                  "enum": [
                                    "name"
                                  ]
                                },
                                "value": {
                                  "type": "string",
                                  "minLength": 1
                                }
                              },
                              "required": [
                                "kind",
                                "value"
                              ]
                            },
                            {
                              "type": "object",
                              "properties": {
                                "kind": {
                                  "type": "string",
                                  "enum": [
                                    "package"
                                  ]
                                },
                                "value": {
                                  "type": "string",
                                  "minLength": 1
                                }
                              },
                              "required": [
                                "kind",
                                "value"
                              ]
                            },
                            {
                              "type": "object",
                              "properties": {
                                "kind": {
                                  "type": "string",
                                  "enum": [
                                    "extends"
                                  ]
                                },
                                "value": {
                                  "type": "string",
                                  "minLength": 1
                                }
                              },
                              "required": [
                                "kind",
                                "value"
                              ],
                              "description": "匹配指定的凭据类型及继承它的所有类型"
                            }
                          ],
                          "type": "object"
                        }
                      },
                      "required": [
                        "id",
                        "action",
                        "selector"
                      ]
                    }
                  },
                  "version": {
                    "type": "integer",
                    "minimum": 0
                  }
                },
                "required": [
                  "rules",
                  "version"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "操作成功。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/credentialTypePolicyDocumentWriteResultPublicDto.generated"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/badRequest"
          },
          "401": {
            "$ref": "#/components/responses/unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/forbidden"
          },
          "404": {
            "$ref": "#/components/responses/notFound"
          },
          "409": {
            "$ref": "#/components/responses/conflict"
          },
          "415": {
            "$ref": "#/components/responses/unsupportedMediaType"
          },
          "503": {
            "$ref": "#/components/responses/serviceUnavailable"
          }
        }
      }
    }
  }
}
