swagger: '2.0'
info:
  title: TiDB Enterprise Platform
  description: TiDB Enterprise Platform OpenAPI
  version: 1.0.0
basePath: /pingcap.com/v1
schemes:
  - http
  - https
consumes:
  - application/json
produces:
  - application/json
security:
  - BasicAuth: []
  - ApiKeyAuth: []
  - OAuth2:
      - read
      - write
parameters:
  instanceIdParameter:
    name: instanceId
    in: path
    type: string
    required: true
  timestampParameter:
    name: timestamp
    in: path
    type: string
    required: true
  machineIdParameter:
    name: machineId
    in: path
    type: string
    required: true
paths:
  '/dummy':
    get:
      summary: Dummy API path
      responses:
        '200':
          $ref: '#/definitions/TypeMeta'
  '/logoff':
    post:
      summary: logoff current user
      tags:
        - user
      responses:
        '200':
          $ref: '#/definitions/TypeMeta'
  '/login':
    post:
      summary: login  user
      tags:
        - user
      parameters:
        - name: body
          in: body
          schema:
            $ref: '#/definitions/Login'
      responses:
        '200':
          $ref: '#/definitions/LoginResponse'
  '/machines':
    post:
      summary: Import machines
      tags:
        - machine
      consumes:
        - multipart/form-data
      parameters:
        - name: machines_file
          in: formData
          type: file
      responses:
        '200':
          $ref: '#/definitions/ImportMachinesResponse'
  '/machines/nodelabel-distribution':
    get:
      summary: Get machines count via purpose
      tags:
        - machine
      responses:
        '200':
          description: Get machines count via purpose
          schema:
            $ref: '#/definitions/GetLabelMachinesResponse'
  '/machines-template':
    get:
      summary: Download template of machine list
      tags:
        - machine
      produces:
        - text/csv
      responses:
        '200':
          description: The CSV template of machine list
          schema:
            type: file
  '/namespaces/{namespace}/tidbcluster-schedule-backup':
    get:
      summary: Get current scheduled backup
      tags:
        - cluster
        - backup
      parameters:
        - name: namespace
          in: path
          type: string
          required: true
      responses:
        '200':
          description: Get current scheduled backup
          schema:
            $ref: '#/definitions/TiDBClusterScheduledBackup'
    post:
      summary: Create a scheduled backup
      tags:
        - cluster
        - backup
      parameters:
        - name: namespace
          in: path
          type: string
          required: true
        - name: body
          in: body
          schema:
            $ref: '#/definitions/TiDBClusterScheduledBackupRequest'
      responses:
        '201':
          description: Created new scheduled backup
          schema:
            $ref: '#/definitions/TiDBClusterScheduledBackup'
  '/namespaces/{namespace}/tidbcluster-schedule-backup/tidb-scheduled-backup-manager':
    put:
      summary: Create a scheduled backup
      tags:
        - cluster
        - backup
      parameters:
        - name: namespace
          in: path
          type: string
          required: true
        - name: body
          in: body
          schema:
            $ref: '#/definitions/TiDBClusterScheduledBackupRequest'
      responses:
        '200':
          description: Updated scheduled backup
          schema:
            $ref: '#/definitions/TiDBClusterScheduledBackup'
  '/tidbclusters':
    post:
      summary: Create a TiDB cluster
      tags:
        - cluster
      parameters:
        - name: body
          in: body
          schema:
            $ref: '#/definitions/TiDBCluster'
      responses:
        '201':
          description: Created new TiDB cluster
          schema:
            $ref: '#/definitions/TiDBCluster'
  '/version':
    get:
      summary: Get versions of the server
      responses:
        '200':
          description: versions of the server
          schema:
            $ref: '#/definitions/GetVersionResponse'
definitions:
  TypeMeta:
    type: object
    x-go-type:
      import:
        package: "k8s.io/apimachinery/pkg/apis/meta/v1"
        alias: "metav1"
      type: "TypeMeta"
  ListMeta:
    type: object
    x-go-type:
      import:
        package: "k8s.io/apimachinery/pkg/apis/meta/v1"
        alias: "metav1"
      type: "ListMeta"
  ObjectMeta:
    type: object
    x-go-type:
      import:
        package: "k8s.io/apimachinery/pkg/apis/meta/v1"
        alias: "metav1"
      type: "ObjectMeta"
  TiDBCluster:
    type: object
    x-go-type:
      import:
        package: "github.com/pingcap/tep/pkg/apis/apiserver"
      type: "TiDBCluster"
  TiDBClusterBackupTemplate:
    type: object
    x-go-type:
      import:
        package: "github.com/pingcap/tep/pkg/apis/apiserver"
      type: "TiDBClusterBackupTemplate"
  TiDBClusterScheduledBackup:
    type: object
    x-go-type:
      import:
        package: "github.com/pingcap/tep/pkg/apis/apiserver"
      type: "TiDBClusterSchedulerBackup"
  GetLabelMachinesResponse:
    type: object
    properties:
      compute:
        type: integer
        x-omitempty: false
      storage:
        type: integer
        x-omitempty: false
  TiDBClusterScheduledBackupRequest:
    type: object
    properties:
      maxBackups:
        type: integer
      schedule:
        type: string
      backupTemplate:
        $ref: '#/definitions/TiDBClusterBackupTemplate'
  GetVersionResponse:
    type: object
    properties:
      apiVersion:
        type: string
      kind:
        type: string
      metadata:
        $ref: '#/definitions/TypeMeta'
      releaseVersion:
        type: string
      gitHash:
        type: string
      gitBranch:
        type: string
      utcBuildTime:
        type: string
      kubernetesVersion:
        type: string
      metaDBVersion:
        type: string
      tidbOperatorVersion:
        type: string
  Login:
    type: object
    properties:
      username:
        type: string
      password:
        type: string
  LoginResponse:
    type: object
    properties:
      apiVersion:
        type: string
      kind:
        type: string
      metadata:
        $ref: '#/definitions/TypeMeta'
      authToken:
        type: string
  ImportMachinesResponse:
    type: object
    properties:
      metadata:
        $ref: '#/definitions/TypeMeta'
      data:
        type: object
        properties:
          errmsg:
            type: array
            items:
              type: string
          total:
            type: integer
          status:
            type: string
            enum:
              - failed
              - successful

responses:
  Unauthorized:
    description: Unauthorized
    headers:
      WWW_Authenticate:
        type: string
  NotFound:
    description: Not found
  InternalServerError:
    description: internal server error
securityDefinitions:
  BasicAuth:
    type: basic
  ApiKeyAuth:
    type: apiKey
    in: header
    name: X-API-Key
  OAuth2:
    type: oauth2
    flow: accessCode
    authorizationUrl: 'https://example.com/oauth/authorize'
    tokenUrl: 'https://example.com/oauth/token'
    scopes:
      read: Grants read access
      write: Grants write access
      admin: Grants read and write access to administrative information
