{
  "swagger": "2.0",
  "info": {
    "title": "Vercel Swagger API",
    "description": "notably uses gRPC-Gateway with OpenAPI",
    "version": "1.0"
  },
  "schemes": ["http"],
  "consumes": ["application/json"],
  "produces": ["application/json"],
  "paths": {
    "/api/v1/serverless/orgs/{org_id}/projects/{project_id}/clusters/{cluster_id}/databases": {
      "get": {
        "operationId": "GetVercelDatabaseList",
        "description": "List databases of the cluster.",
        "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/vercel.ListDatabasesResponse"
            }
          },
          "400": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/vercel.BaseResp"
            }
          },
          "500": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/vercel.BaseResp"
            }
          }
        }
      },
      "post": {
        "operationId": "CreateVercelDatabase",
        "description": "Create database of cluster.",
        "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": "Serverless cluster info",
            "name": "database",
            "in": "body",
            "required": true,
            "schema": {
              "$ref": "#/definitions/vercel.CreateDatabaseRequest"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "schema": {
              "$ref": "#/definitions/vercel.MessageResp"
            }
          },
          "400": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/vercel.BaseResp"
            }
          },
          "500": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/vercel.BaseResp"
            }
          }
        }
      }
    },
    "/ecosystem/api/v1/orgs/{org_id}/projects/{project_id}/clusters/{cluster_id}/vercel/connections": {
      "get": {
        "operationId": "getVercelConnections",
        "description": "List connections between Vercel project and TiDB cluster By cluster id.",
        "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/vercel.ListConnectionResponse"
            }
          },
          "400": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/vercel.BaseResp"
            }
          },
          "500": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/vercel.BaseResp"
            }
          }
        }
      },
      "post": {
        "operationId": "createVercelConnection",
        "description": "Add connection between Vercel project and TiDB cluster",
        "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": "Vercel project information and integration configuration id",
            "name": "vercel_project",
            "in": "body",
            "required": true,
            "schema": {
              "$ref": "#/definitions/vercel.AddConnectionRequest"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "schema": {
              "$ref": "#/definitions/vercel.MessageResp"
            }
          },
          "400": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/vercel.BaseResp"
            }
          },
          "500": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/vercel.BaseResp"
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteVercelConnection",
        "description": "Delete connection between Vercel project and TiDB cluster",
        "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
          },
          {
            "type": "string",
            "name": "vercel_project_id",
            "in": "query",
            "required": true
          },
          {
            "type": "string",
            "name": "vercel_project_name",
            "in": "query",
            "required": true
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "schema": {
              "$ref": "#/definitions/vercel.MessageResp"
            }
          },
          "400": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/vercel.BaseResp"
            }
          },
          "500": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/vercel.BaseResp"
            }
          }
        }
      }
    },
    "/ecosystem/api/v1/orgs/{org_id}/projects/{project_id}/dataapps/{data_app_id}/vercel/connections": {
      "post": {
        "operationId": "CreateVercelDataAppLink",
        "description": "Add connection between Vercel project and TiDB Data app",
        "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 Data App ID",
            "name": "data_app_id",
            "in": "path",
            "required": true
          },
          {
            "description": "Vercel project information and integration configuration id",
            "name": "vercel_project",
            "in": "body",
            "required": true,
            "schema": {
              "$ref": "#/definitions/vercel.AddDataAppConnectionRequest"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "schema": {
              "$ref": "#/definitions/vercel.MessageResp"
            }
          },
          "400": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/vercel.BaseResp"
            }
          },
          "500": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/vercel.BaseResp"
            }
          }
        }
      },
      "delete": {
        "operationId": "DeleteVercelDataappLink",
        "description": "Delete connection between Vercel project and TiDB data app",
        "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 Data App ID",
            "name": "data_app_id",
            "in": "path",
            "required": true
          },
          {
            "type": "string",
            "name": "vercel_project_id",
            "in": "query",
            "required": true
          },
          {
            "type": "string",
            "name": "vercel_project_name",
            "in": "query",
            "required": true
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "schema": {
              "$ref": "#/definitions/vercel.MessageResp"
            }
          },
          "400": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/vercel.BaseResp"
            }
          },
          "500": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/vercel.BaseResp"
            }
          }
        }
      }
    },
    "/ecosystem/api/v1/orgs/{org_id}/projects/{project_id}/serverless/clusters": {
      "post": {
        "operationId": "CreateVercelCluster",
        "description": "Create serverless cluster, return success when the cluster is ready.",
        "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
          },
          {
            "description": "Serverless cluster info",
            "name": "vercel_project",
            "in": "body",
            "required": true,
            "schema": {
              "$ref": "#/definitions/vercel.CreateClusterRequest"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "schema": {
              "$ref": "#/definitions/vercel.MessageResp"
            }
          },
          "400": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/vercel.BaseResp"
            }
          },
          "500": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/vercel.BaseResp"
            }
          }
        }
      }
    },
    "/ecosystem/api/v1/orgs/{org_id}/vercel/connections": {
      "get": {
        "operationId": "getOrgVercelConnections",
        "description": "List connections between Vercel project and (cluster or data app) By TiDB Org.",
        "consumes": ["application/json"],
        "produces": ["application/json"],
        "parameters": [
          {
            "type": "string",
            "description": "TiDB org ID",
            "name": "org_id",
            "in": "path",
            "required": true
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "schema": {
              "$ref": "#/definitions/vercel.TiDBOrgVercelConnection"
            }
          },
          "400": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/vercel.BaseResp"
            }
          },
          "500": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/vercel.BaseResp"
            }
          }
        }
      }
    },
    "/ecosystem/api/v1/vercel/access_token": {
      "post": {
        "operationId": "getVercelAccessToken",
        "description": "Get Vercel access token. For the concern of security, we will store the long-lived access token in our database",
        "consumes": ["application/json"],
        "produces": ["application/json"],
        "parameters": [
          {
            "type": "string",
            "description": "The code received when adding integration.",
            "name": "code",
            "in": "query",
            "required": true
          },
          {
            "type": "string",
            "description": "The configuration ID of the integration(absent with External installation).",
            "name": "configurationId",
            "in": "query"
          },
          {
            "type": "string",
            "description": "The ID of the created project(only exist when installing via Deploy Button).",
            "name": "currentProjectId",
            "in": "query"
          },
          {
            "type": "string",
            "description": "An external ID or reference(only exist when installing via Deploy Button).",
            "name": "external-id",
            "in": "query"
          },
          {
            "type": "string",
            "description": "The URL to redirect to after the integration has been installed(absent with External installation).",
            "name": "next",
            "in": "query"
          },
          {
            "type": "string",
            "description": "The ID of the team (only if a team is selected).",
            "name": "teamId",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "schema": {
              "$ref": "#/definitions/vercel.AccessTokenResponse"
            }
          },
          "400": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/vercel.AccessTokenResponse"
            }
          },
          "500": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/vercel.AccessTokenResponse"
            }
          }
        }
      }
    },
    "/ecosystem/api/v1/vercel/integration/configurations/{configuration_id}/connections": {
      "get": {
        "operationId": "getAllVercelConnections",
        "description": "List connections between Vercel project and (cluster or data app) By integration configuration.",
        "consumes": ["application/json"],
        "produces": ["application/json"],
        "parameters": [
          {
            "type": "string",
            "description": "Vercel integration configuration id",
            "name": "configuration_id",
            "in": "path",
            "required": true
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "schema": {
              "$ref": "#/definitions/vercel.ListConnectionResponse"
            }
          },
          "400": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/vercel.BaseResp"
            }
          },
          "500": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/vercel.BaseResp"
            }
          }
        }
      }
    },
    "/ecosystem/api/v1/vercel/integration/configurations/{configuration_id}/projects": {
      "get": {
        "operationId": "getVercelProjects",
        "description": "List Vercel projects accessible to the integration configuration.",
        "consumes": ["application/json"],
        "produces": ["application/json"],
        "parameters": [
          {
            "type": "string",
            "description": "Vercel integration configuration information",
            "name": "configuration_id",
            "in": "path",
            "required": true
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "schema": {
              "$ref": "#/definitions/vercel.RetrieveProjectResponse"
            }
          },
          "400": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/vercel.BaseResp"
            }
          },
          "500": {
            "description": "error",
            "schema": {
              "$ref": "#/definitions/vercel.BaseResp"
            }
          }
        }
      }
    }
  },
  "definitions": {
    "vercel.AccessTokenResponse": {
      "type": "object",
      "properties": {
        "base_resp": {
          "$ref": "#/definitions/vercel.Resp"
        },
        "redirectUrl": {
          "type": "string"
        }
      }
    },
    "vercel.AddConnectionRequest": {
      "type": "object",
      "required": ["configuration_id", "framework_type", "vercel_project_id", "vercel_project_name"],
      "properties": {
        "branch_enabled": {
          "type": "boolean"
        },
        "configuration_id": {
          "type": "string"
        },
        "database": {
          "type": "string"
        },
        "framework_type": {
          "type": "string",
          "enum": ["General", "Prisma", "TiDB Cloud Serverless Driver"]
        },
        "vercel_project_id": {
          "type": "string"
        },
        "vercel_project_name": {
          "type": "string"
        }
      }
    },
    "vercel.AddDataAppConnectionRequest": {
      "type": "object",
      "required": ["configuration_id", "vercel_project_id", "vercel_project_name"],
      "properties": {
        "configuration_id": {
          "type": "string"
        },
        "vercel_project_id": {
          "type": "string"
        },
        "vercel_project_name": {
          "type": "string"
        }
      }
    },
    "vercel.BaseResp": {
      "type": "object",
      "properties": {
        "base_resp": {
          "$ref": "#/definitions/vercel.Resp"
        }
      }
    },
    "vercel.ConnectionTargetType": {
      "type": "string",
      "enum": ["cluster", "dataApp"],
      "x-enum-varnames": ["TargetTypeCluster", "TargetTypeDataApp"]
    },
    "vercel.CreateClusterRequest": {
      "type": "object",
      "required": ["cluster_name", "configuration_id", "selected_vercel_projects"],
      "properties": {
        "cluster_name": {
          "type": "string"
        },
        "configuration_id": {
          "type": "string"
        },
        "selected_vercel_projects": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "vercel.EventType": {
      "type": "string",
      "enum": [
        "project-removed",
        "project.removed",
        "integration-configuration-removed",
        "integration-configuration.removed",
        "deployment.created",
        "deployment.ready",
        "deployment.check-rerequested"
      ],
      "x-enum-varnames": [
        "ProjectRemoved",
        "IntegrationRemovedDeprecated",
        "IntegrationRemoved",
        "DeploymentCreated",
        "DeploymentReady",
        "DeploymentRerequested"
      ]
    },
    "vercel.ListConnectionResponse": {
      "type": "object",
      "properties": {
        "base_resp": {
          "$ref": "#/definitions/vercel.Resp"
        },
        "connections": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/vercel.TiDBVercelConnectionVO"
          }
        }
      }
    },
    "vercel.CreateDatabaseRequest": {
      "type": "object",
      "required": ["database_name"],
      "properties": {
        "database_name": {
          "type": "string"
        }
      }
    },
    "vercel.ListDatabasesResponse": {
      "type": "object",
      "properties": {
        "base_resp": {
          "$ref": "#/definitions/vercel.Resp"
        },
        "databases": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "vercel.MessageResp": {
      "type": "object",
      "properties": {
        "base_resp": {
          "$ref": "#/definitions/vercel.Resp"
        },
        "message": {
          "type": "string"
        }
      }
    },
    "vercel.ProjectVO": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        }
      }
    },
    "vercel.Resp": {
      "type": "object",
      "properties": {
        "err_code": {
          "type": "integer"
        },
        "err_msg": {
          "type": "string"
        }
      }
    },
    "vercel.RetrieveProjectResponse": {
      "type": "object",
      "properties": {
        "base_resp": {
          "$ref": "#/definitions/vercel.Resp"
        },
        "projects": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/vercel.ProjectVO"
          }
        }
      }
    },
    "vercel.TiDBOrgVercelConnection": {
      "type": "object",
      "properties": {
        "base_resp": {
          "$ref": "#/definitions/vercel.Resp"
        },
        "connections_array": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/vercel.TiDBTargetVercelConnectionVO"
          }
        }
      }
    },
    "vercel.TiDBTargetVercelConnectionVO": {
      "type": "object",
      "required": ["tidb_org_id", "tidb_project_id"],
      "properties": {
        "branch_enabled": {
          "type": "boolean"
        },
        "projects": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/vercel.VercelProject"
          }
        },
        "target_id": {
          "type": "string"
        },
        "target_name": {
          "type": "string"
        },
        "target_type": {
          "$ref": "#/definitions/vercel.ConnectionTargetType"
        },
        "tidb_org_id": {
          "type": "string"
        },
        "tidb_org_name": {
          "type": "string"
        },
        "tidb_project_id": {
          "type": "string"
        },
        "tidb_project_name": {
          "type": "string"
        }
      }
    },
    "vercel.TiDBVercelConnectionVO": {
      "type": "object",
      "required": ["tidb_org_id", "tidb_project_id", "vercel_project_id", "vercel_project_name"],
      "properties": {
        "branch_enabled": {
          "type": "boolean"
        },
        "target_id": {
          "type": "string"
        },
        "target_name": {
          "type": "string"
        },
        "target_type": {
          "$ref": "#/definitions/vercel.ConnectionTargetType"
        },
        "tidb_org_id": {
          "type": "string"
        },
        "tidb_org_name": {
          "type": "string"
        },
        "tidb_project_id": {
          "type": "string"
        },
        "tidb_project_name": {
          "type": "string"
        },
        "vercel_project_id": {
          "type": "string"
        },
        "vercel_project_name": {
          "type": "string"
        }
      }
    },
    "vercel.VercelEvent": {
      "type": "object",
      "properties": {
        "createdAt": {
          "type": "integer"
        },
        "id": {
          "type": "string"
        },
        "payload": {},
        "type": {
          "$ref": "#/definitions/vercel.EventType"
        }
      }
    },
    "vercel.VercelProject": {
      "type": "object",
      "required": ["vercel_project_id", "vercel_project_name"],
      "properties": {
        "vercel_project_id": {
          "type": "string"
        },
        "vercel_project_name": {
          "type": "string"
        }
      }
    }
  }
}
