{
  "schemes": ["http"],
  "swagger": "2.0",
  "info": {
    "title": "Git Swagger API",
    "termsOfService": "http://swagger.io/terms/",
    "contact": {},
    "version": "1.0"
  },
  "host": "localhost:8080",
  "paths": {
    "/ecosystem/api/v1/integration/github/accounts": {
      "get": {
        "operationId": "getGithubAccountsService",
        "description": "Get TiDB Cloud App installation information. We may refresh token if access_token is expired and refresh_token is passed.",
        "consumes": ["application/json"],
        "produces": ["application/json"],
        "parameters": [
          {
            "type": "string",
            "description": "GitHub app user access token",
            "name": "access_token",
            "in": "header",
            "required": true
          },
          {
            "type": "string",
            "description": "GitHub app refresh token. If access_token is expired, we will try to use refresh_token to get a new access_token.",
            "name": "refresh_token",
            "in": "header"
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "schema": {
              "$ref": "#/definitions/git.GetGitHubInstallAccountsResponse"
            }
          },
          "400": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/git.BaseResp"
            }
          },
          "500": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/git.BaseResp"
            }
          }
        }
      }
    },
    "/ecosystem/api/v1/integration/github/exchange-token": {
      "get": {
        "operationId": "exchangeTokenService",
        "description": "Exchange GitHub token with code. See https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-a-user-access-token-for-a-github-app#using-the-web-application-flow-to-generate-a-user-access-token",
        "consumes": ["application/json"],
        "produces": ["application/json"],
        "parameters": [
          {
            "type": "string",
            "description": "The code you received in the previous step.",
            "name": "code",
            "in": "query",
            "required": true
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "schema": {
              "$ref": "#/definitions/git.ExchangeGitHubTokenResponse"
            }
          },
          "400": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/git.BaseResp"
            }
          },
          "500": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/git.BaseResp"
            }
          }
        }
      }
    },
    "/ecosystem/api/v1/integration/github/search-repo-v2": {
      "get": {
        "operationId": "getGithubRepoListService",
        "description": "List repositories that the TiDB Cloud App installation can access with a safer way. installation_id is not reliable, we need to judge whether the installation_id belongs to the user who provided the access_token.",
        "consumes": ["application/json"],
        "produces": ["application/json"],
        "parameters": [
          {
            "type": "string",
            "description": "GitHub app user access token",
            "name": "github_access_token",
            "in": "header",
            "required": true
          },
          {
            "type": "string",
            "description": "GitHub app refresh token. If access_token is expired, we will try to use refresh_token to get a new access_token.",
            "name": "github_refresh_token",
            "in": "header"
          },
          {
            "type": "string",
            "description": "GitHub account installation_id",
            "name": "installation_id",
            "in": "query",
            "required": true
          },
          {
            "type": "string",
            "description": "GitHub repository name",
            "name": "repo_name",
            "in": "query"
          },
          {
            "type": "integer",
            "description": "page",
            "name": "page",
            "in": "query"
          },
          {
            "type": "integer",
            "description": "per_page",
            "name": "per_page",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "schema": {
              "$ref": "#/definitions/git.GetGitHubRepoResponse"
            }
          },
          "400": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/git.BaseResp"
            }
          },
          "500": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/git.BaseResp"
            }
          }
        }
      }
    },
    "/ecosystem/api/v1/orgs/{org_id}/projects/{project_id}/clusters/{cluster_id}/git/connections": {
      "get": {
        "operationId": "getConnectionService",
        "description": "List Connections between TIDB Cloud cluster and Git.",
        "consumes": ["application/json"],
        "produces": ["application/json"],
        "parameters": [
          {
            "type": "string",
            "description": "TiDB Org ID",
            "name": "org_id",
            "in": "path",
            "required": true
          },
          {
            "type": "string",
            "description": "TiDB Project ID",
            "name": "project_id",
            "in": "path",
            "required": true
          },
          {
            "type": "string",
            "description": "TiDB Cluster ID",
            "name": "cluster_id",
            "in": "path",
            "required": true
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "schema": {
              "$ref": "#/definitions/git.GetConnectionResponse"
            }
          },
          "400": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/git.BaseResp"
            }
          },
          "500": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/git.BaseResp"
            }
          }
        }
      },
      "post": {
        "operationId": "createConnectionService",
        "description": "Add Connections between TIDB Cloud cluster and Git.",
        "consumes": ["application/json"],
        "produces": ["application/json"],
        "parameters": [
          {
            "type": "string",
            "description": "TiDB Org ID",
            "name": "org_id",
            "in": "path",
            "required": true
          },
          {
            "type": "string",
            "description": "TiDB Project ID",
            "name": "project_id",
            "in": "path",
            "required": true
          },
          {
            "type": "string",
            "description": "TiDB Cluster ID",
            "name": "cluster_id",
            "in": "path",
            "required": true
          },
          {
            "description": "Git information",
            "name": "git",
            "in": "body",
            "required": true,
            "schema": {
              "$ref": "#/definitions/git.AddConnectionRequest"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "schema": {
              "$ref": "#/definitions/git.AddConnectionResponse"
            }
          },
          "400": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/git.BaseResp"
            }
          },
          "500": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/git.BaseResp"
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteConnectionService",
        "description": "Delete Connections between TIDB Cloud cluster and Git.",
        "consumes": ["application/json"],
        "produces": ["application/json"],
        "parameters": [
          {
            "type": "string",
            "description": "TiDB Org ID",
            "name": "org_id",
            "in": "path",
            "required": true
          },
          {
            "type": "string",
            "description": "TiDB Project ID",
            "name": "project_id",
            "in": "path",
            "required": true
          },
          {
            "type": "string",
            "description": "TiDB Cluster ID",
            "name": "cluster_id",
            "in": "path",
            "required": true
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "schema": {
              "$ref": "#/definitions/git.BaseResp"
            }
          },
          "400": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/git.BaseResp"
            }
          },
          "500": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/git.BaseResp"
            }
          }
        }
      }
    },
    "/ecosystem/api/v1/orgs/{org_id}/projects/{project_id}/git/connections": {
      "get": {
        "operationId": "getConnectionListService",
        "description": "List Connections between TIDB Cloud cluster and Git.",
        "consumes": ["application/json"],
        "produces": ["application/json"],
        "parameters": [
          {
            "type": "string",
            "description": "TiDB Org ID",
            "name": "org_id",
            "in": "path",
            "required": true
          },
          {
            "type": "string",
            "description": "TiDB Project ID",
            "name": "project_id",
            "in": "path",
            "required": true
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "schema": {
              "$ref": "#/definitions/git.ListConnectionResponse"
            }
          },
          "400": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/git.BaseResp"
            }
          },
          "500": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/git.BaseResp"
            }
          }
        }
      }
    }
  },
  "definitions": {
    "git.AccountsVO": {
      "type": "object",
      "properties": {
        "installation_id": {
          "type": "integer"
        },
        "name": {
          "type": "string"
        },
        "owner_type": {
          "type": "string"
        }
      }
    },
    "git.AddConnectionRequest": {
      "type": "object",
      "required": ["repo_name"],
      "properties": {
        "git_provider": {
          "type": "string",
          "enum": ["github"]
        },
        "repo_name": {
          "type": "string"
        }
      }
    },
    "git.AddConnectionResponse": {
      "type": "object",
      "properties": {
        "base_resp": {
          "$ref": "#/definitions/git.Resp"
        },
        "id": {
          "type": "integer"
        }
      }
    },
    "git.BaseResp": {
      "type": "object",
      "properties": {
        "base_resp": {
          "$ref": "#/definitions/git.Resp"
        }
      }
    },
    "git.ExchangeGitHubTokenResponse": {
      "type": "object",
      "properties": {
        "access_token": {
          "type": "string"
        },
        "base_resp": {
          "$ref": "#/definitions/git.Resp"
        },
        "refresh_token": {
          "type": "string"
        }
      }
    },
    "git.GetConnectionResponse": {
      "type": "object",
      "properties": {
        "base_resp": {
          "$ref": "#/definitions/git.Resp"
        },
        "connection": {
          "$ref": "#/definitions/git.TiDBGitConnectionVO"
        }
      }
    },
    "git.GetGitHubInstallAccountsResponse": {
      "type": "object",
      "properties": {
        "access_token": {
          "type": "string"
        },
        "accounts": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/git.AccountsVO"
          }
        },
        "base_resp": {
          "$ref": "#/definitions/git.Resp"
        },
        "refresh_token": {
          "type": "string"
        }
      }
    },
    "git.GetGitHubRepoResponse": {
      "type": "object",
      "properties": {
        "base_resp": {
          "$ref": "#/definitions/git.Resp"
        },
        "first_page": {
          "type": "integer"
        },
        "last_page": {
          "type": "integer"
        },
        "next_page": {
          "type": "integer"
        },
        "page": {
          "type": "integer"
        },
        "per_page": {
          "type": "integer"
        },
        "prev_page": {
          "type": "integer"
        },
        "repositories": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/git.RepositoriesVO"
          }
        },
        "total": {
          "type": "integer"
        }
      }
    },
    "git.ListConnectionResponse": {
      "type": "object",
      "properties": {
        "base_resp": {
          "$ref": "#/definitions/git.Resp"
        },
        "connections": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/git.TiDBGitConnectionVO"
          }
        }
      }
    },
    "git.RepositoriesVO": {
      "type": "object",
      "properties": {
        "full_name": {
          "type": "string"
        },
        "id": {
          "type": "integer"
        },
        "name": {
          "type": "string"
        }
      }
    },
    "git.Resp": {
      "type": "object",
      "properties": {
        "err_code": {
          "type": "integer"
        },
        "err_msg": {
          "type": "string"
        }
      }
    },
    "git.TiDBGitConnectionVO": {
      "type": "object",
      "properties": {
        "git_provider": {
          "type": "string"
        },
        "repo_name": {
          "type": "string"
        },
        "tidb_cluster_id": {
          "type": "string"
        },
        "tidb_cluster_name": {
          "type": "string"
        }
      }
    }
  }
}
