{
  "openapi": "3.0.0",
  "info": {
    "title": "n8n 公共 API",
    "version": "1.1.1"
  },
  "tags": [
    {
      "name": "Promotions",
      "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]+$"
        }
      }
    },
    "responses": {
      "badRequest": {
        "description": "请求无效，或提供的数据格式错误。"
      },
      "unauthorized": {
        "description": "未授权"
      },
      "forbidden": {
        "description": "禁止访问"
      },
      "conflict": {
        "description": "冲突"
      },
      "unsupportedMediaType": {
        "description": "不支持的媒体类型。"
      },
      "unprocessableEntity": {
        "description": "无法处理的实体"
      },
      "serviceUnavailable": {
        "description": "所请求的服务暂时不可用。"
      }
    }
  },
  "paths": {
    "/promotions/providers": {
      "post": {
        "operationId": "createPromotionProvider",
        "tags": [
          "Promotions"
        ],
        "summary": "创建晋升提供方",
        "description": "创建提供方及其认证材料。Git 主机提供方在保存前会校验经过认证的 API 访问。对于 GitLab，服务使用 n8n 作为 Git 传输用户名，auth.username 可选，任何提供的用户名都会被忽略。普通 Git 令牌认证要求提供 auth.username。SSH 提供方会返回生成的公钥，请将其作为部署密钥添加到远程仓库。",
        "parameters": [
          {
            "$ref": "#/components/parameters/idempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 128
                  },
                  "type": {
                    "type": "string",
                    "enum": [
                      "git",
                      "gitlab"
                    ]
                  },
                  "auth": {
                    "oneOf": [
                      {
                        "type": "object",
                        "properties": {
                          "authType": {
                            "type": "string",
                            "enum": [
                              "ssh-key"
                            ]
                          },
                          "keyType": {
                            "type": "string",
                            "enum": [
                              "ed25519",
                              "rsa"
                            ],
                            "default": "ed25519"
                          }
                        },
                        "required": [
                          "authType"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "authType": {
                            "type": "string",
                            "enum": [
                              "token"
                            ]
                          },
                          "username": {
                            "type": "string",
                            "minLength": 1,
                            "description": "普通 Git 令牌认证时必填。对于 GitLab，服务会忽略此字段，使用 n8n 进行 Git 传输。"
                          },
                          "password": {
                            "type": "string",
                            "minLength": 1
                          }
                        },
                        "required": [
                          "authType",
                          "password"
                        ],
                        "additionalProperties": false
                      }
                    ],
                    "type": "object"
                  },
                  "config": {
                    "type": "object",
                    "properties": {
                      "schemaVersion": {
                        "type": "number",
                        "enum": [
                          1
                        ]
                      },
                      "baseUrl": {
                        "type": "string"
                      }
                    },
                    "required": [
                      "schemaVersion",
                      "baseUrl"
                    ],
                    "additionalProperties": false
                  }
                },
                "required": [
                  "name",
                  "type",
                  "auth"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "操作成功。",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "provider": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 36
                        },
                        "name": {
                          "type": "string"
                        },
                        "type": {
                          "type": "string",
                          "enum": [
                            "git",
                            "gitlab"
                          ]
                        },
                        "authType": {
                          "type": "string",
                          "enum": [
                            "ssh-key",
                            "token"
                          ]
                        },
                        "config": {
                          "anyOf": [
                            {
                              "type": "object",
                              "properties": {
                                "schemaVersion": {
                                  "type": "number",
                                  "enum": [
                                    1
                                  ]
                                },
                                "publicKey": {
                                  "type": "string",
                                  "minLength": 1
                                },
                                "keyType": {
                                  "type": "string",
                                  "enum": [
                                    "ed25519",
                                    "rsa"
                                  ]
                                }
                              },
                              "required": [
                                "schemaVersion",
                                "publicKey",
                                "keyType"
                              ],
                              "additionalProperties": false
                            },
                            {
                              "type": "object",
                              "properties": {
                                "schemaVersion": {
                                  "type": "number",
                                  "enum": [
                                    1
                                  ]
                                }
                              },
                              "required": [
                                "schemaVersion"
                              ],
                              "additionalProperties": false
                            },
                            {
                              "type": "object",
                              "properties": {
                                "schemaVersion": {
                                  "type": "number",
                                  "enum": [
                                    1
                                  ]
                                },
                                "baseUrl": {
                                  "type": "string"
                                }
                              },
                              "required": [
                                "schemaVersion",
                                "baseUrl"
                              ],
                              "additionalProperties": false
                            }
                          ]
                        },
                        "createdAt": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "updatedAt": {
                          "type": "string",
                          "format": "date-time"
                        }
                      },
                      "required": [
                        "id",
                        "name",
                        "type",
                        "authType",
                        "config",
                        "createdAt",
                        "updatedAt"
                      ]
                    },
                    "publicKey": {
                      "type": "string",
                      "nullable": true
                    }
                  },
                  "required": [
                    "provider",
                    "publicKey"
                  ]
                }
              }
            }
          },
          "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"
          },
          "503": {
            "$ref": "#/components/responses/serviceUnavailable"
          }
        }
      }
    }
  }
}
