{
  "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": {
      "credentialTypePolicyEffectiveWriteResultPublicDto.generated": {
        "type": "object",
        "properties": {
          "scopeId": {
            "type": "string",
            "nullable": true
          },
          "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"
              ]
            }
          },
          "defaultAction": {
            "type": "string",
            "enum": [
              "allow",
              "deny",
              "delegate"
            ]
          },
          "version": {
            "type": "integer",
            "minimum": 0
          },
          "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": [
          "scopeId",
          "rules",
          "defaultAction",
          "version",
          "warnings"
        ]
      }
    },
    "responses": {
      "badRequest": {
        "description": "请求无效，或提供的数据格式错误。"
      },
      "unauthorized": {
        "description": "未授权"
      },
      "forbidden": {
        "description": "禁止访问"
      },
      "conflict": {
        "description": "冲突"
      },
      "unsupportedMediaType": {
        "description": "不支持的媒体类型。"
      },
      "serviceUnavailable": {
        "description": "所请求的服务暂时不可用。"
      }
    }
  },
  "paths": {
    "/credential-type-policies/projects/{projectId}": {
      "put": {
        "operationId": "putCredentialTypeProjectPolicy",
        "tags": [
          "CredentialTypePolicy"
        ],
        "summary": "预览：替换项目的凭据类型策略",
        "description": "**预览**——即使不提升主版本号，也可能出现破坏性变更。\n\n设置项目的默认动作，并替换其单个策略文档中的规则；首次写入时会创建二者。项目作用域不接受 `delegate` 动作。`version` 必须等于上次读取的版本；过期值会以 409 拒绝，与其他作用域共享的项目策略文档也会被拒绝。",
        "parameters": [
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "description": "项目的 ID。",
            "name": "projectId",
            "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"
                          ]
                        },
                        "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"
                      ]
                    }
                  },
                  "defaultAction": {
                    "type": "string",
                    "enum": [
                      "allow",
                      "deny"
                    ]
                  },
                  "version": {
                    "type": "integer",
                    "minimum": 0
                  }
                },
                "required": [
                  "rules",
                  "defaultAction",
                  "version"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "操作成功。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/credentialTypePolicyEffectiveWriteResultPublicDto.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"
          },
          "503": {
            "$ref": "#/components/responses/serviceUnavailable"
          }
        }
      }
    }
  }
}
