#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

---
openapi: 3.1.1
info:
  title: REST Catalog API
  description: This API exposes endpoints to RESTCatalog.
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0.html
  version: "1.0"
servers:
  - url: http://localhost:8080
    description: Server URL in Development environment
paths:
  /v1/config:
    get:
      tags:
        - config
      summary: Get Config
      operationId: getConfig
      parameters:
        - name: warehouse
          in: query
          required: false
          schema:
            type: string
          description: Warehouse location or identifier to request from the service
      responses:
        "200":
          description: Config defined in the server
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ConfigResponse'
              example: {
                "overrides": {
                  "key": "value"
                },
                "defaults": {
                  "prefix": "prefix"
                }
              }
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
  /v1/{prefix}/databases:
    get:
      tags:
        - database
      summary: List Databases
      operationId: listDatabases
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: maxResults
          in: query
          schema:
            type: integer
            format: int32
        - name: pageToken
          in: query
          schema:
            type: string
      responses:
        "200":
          description: List of database name
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ListDatabasesResponse'
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
    post:
      tags:
        - database
      summary: Create Databases
      operationId: createDatabases
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateDatabaseRequest'
      responses:
        "200":
          description: Success, no content
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "409":
          $ref: '#/components/responses/DatabaseAlreadyExistErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
  /v1/{prefix}/databases/{database}:
    get:
      tags:
        - database
      summary: Get Database
      operationId: getDatabases
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: database
          in: path
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Get a database by database name.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GetDatabaseResponse'
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "404":
          $ref: '#/components/responses/DatabaseNotExistErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
    delete:
      tags:
        - database
      summary: Drop Database
      operationId: dropDatabase
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: database
          in: path
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Success, no content
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "404":
          $ref: '#/components/responses/DatabaseNotExistErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
    post:
      tags:
        - database
      summary: Alter Database
      operationId: alterDatabase
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: database
          in: path
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AlterDatabaseRequest'
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AlterDatabaseResponse'
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "404":
          $ref: '#/components/responses/DatabaseNotExistErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
  /v1/{prefix}/databases/{database}/tables:
    get:
      tags:
        - table
      summary: List tables
      operationId: listTables
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: database
          in: path
          required: true
          schema:
            type: string
        - name: maxResults
          in: query
          schema:
            type: integer
            format: int32
        - name: pageToken
          in: query
          schema:
            type: string
        - name: tableNamePattern
          description: A sql LIKE pattern (% and _) for table names.
          in: query
          schema:
            type: string
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ListTablesResponse'
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "404":
          $ref: '#/components/responses/DatabaseNotExistErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
    post:
      tags:
        - table
      summary: Create table
      operationId: createTable
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: database
          in: path
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateTableRequest'
      responses:
        "200":
          description: Success, no content
        "400":
          $ref: '#/components/responses/BadRequestErrorResponse'
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "404":
          $ref: '#/components/responses/DatabaseNotExistErrorResponse'
        "409":
          $ref: '#/components/responses/TableAlreadyExistErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
  /v1/{prefix}/databases/{database}/table-details:
    get:
      tags:
        - table
      summary: List table details
      operationId: listTableDetails
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: database
          in: path
          required: true
          schema:
            type: string
        - name: maxResults
          in: query
          schema:
            type: integer
            format: int32
        - name: pageToken
          in: query
          schema:
            type: string
        - name: tableNamePattern
          description: A sql LIKE pattern (% and _) for table names.
          in: query
          schema:
            type: string
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ListTableDetailsResponse'
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "404":
          $ref: '#/components/responses/DatabaseNotExistErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
  /v1/{prefix}/databases/{database}/tables/{table}:
    get:
      tags:
        - table
      summary: Get table
      operationId: getTable
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: database
          in: path
          required: true
          schema:
            type: string
        - name: table
          in: path
          required: true
          schema:
            type: string
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GetTableResponse'
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "404":
          $ref: '#/components/responses/TableNotExistErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
    post:
      tags:
        - table
      summary: Alter table
      operationId: alterTable
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: database
          in: path
          required: true
          schema:
            type: string
        - name: table
          in: path
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AlterTableRequest'
      responses:
        "200":
          description: Success, no content
        "400":
          $ref: '#/components/responses/BadRequestErrorResponse'
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "404":
          $ref: '#/components/responses/TableNotExistErrorResponse'
        "409":
          $ref: '#/components/responses/TableAlreadyExistErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
    delete:
      tags:
        - table
      summary: Drop table
      operationId: dropTable
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: database
          in: path
          required: true
          schema:
            type: string
        - name: table
          in: path
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Success, no content
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "404":
          $ref: '#/components/responses/TableNotExistErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
  /v1/{prefix}/tables/rename:
    post:
      tags:
        - table
      summary: Rename table
      operationId: renameTable
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RenameTableRequest'
      responses:
        "200":
          description: Success, no content
        "400":
          $ref: '#/components/responses/BadRequestErrorResponse'
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "404":
          $ref: '#/components/responses/TableNotExistErrorResponse'
        "409":
          $ref: '#/components/responses/TableAlreadyExistErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
  /v1/{prefix}/databases/{database}/tables/{table}/commit:
    post:
      tags:
        - table
      summary: Commit table
      operationId: commitTable
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: database
          in: path
          required: true
          schema:
            type: string
        - name: table
          in: path
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CommitTableRequest'
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CommitTableResponse'
        "400":
          $ref: '#/components/responses/BadRequestErrorResponse'
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "404":
          $ref: '#/components/responses/TableNotExistErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
  /v1/{prefix}/databases/{database}/tables/{table}/rollback:
    post:
      tags:
        - table
      summary: Rollback table
      operationId: rollbackTable
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: database
          in: path
          required: true
          schema:
            type: string
        - name: table
          in: path
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RollbackTableRequest'
      responses:
        "200":
          description: Success, no content
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        404:
          description:
            Not Found
            - TableNotExistException, table does not exist
            - SnapshotNotExistException, the rollback snapshot does not exist
            - TagNotExistException, the rollback tag does not exist
          content:
            application/json:
              schema:
                $ref: '#/components/responses/ResourceNotExistErrorResponse'
              examples:
                TableNotExist:
                  $ref: '#/components/examples/TableNotExistError'
                SnapshotNotExist:
                  $ref: '#/components/examples/SnapshotNotExistError'
                TagNotExist:
                  $ref: '#/components/examples/TagNotExistError'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
  /v1/{prefix}/databases/{database}/tables/{table}/token:
    get:
      tags:
        - table
      summary: Get table token
      operationId: getTableToken
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: database
          in: path
          required: true
          schema:
            type: string
        - name: table
          in: path
          required: true
          schema:
            type: string
      responses:
        "200":
          description: DataToken for visit data.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GetTableDataTokenResponse'
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "404":
          $ref: '#/components/responses/TableNotExistErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
  /v1/{prefix}/databases/{database}/tables/{table}/snapshot:
    get:
      tags:
        - table
      summary: Get table snapshot
      operationId: getTableSnapshot
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: database
          in: path
          required: true
          schema:
            type: string
        - name: table
          in: path
          required: true
          schema:
            type: string
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GetTableSnapshotResponse'
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        404:
          description:
            Not Found
            - TableNotExistException, table does not exist
            - SnapshotNotExistException, the requested snapshot does not exist
          content:
            application/json:
              schema:
                $ref: '#/components/responses/ResourceNotExistErrorResponse'
              examples:
                TableNotExist:
                  $ref: '#/components/examples/TableNotExistError'
                SnapshotNotExist:
                  $ref: '#/components/examples/SnapshotNotExistError'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
  /v1/{prefix}/databases/{database}/tables/{table}/partitions:
    get:
      tags:
        - partition
      summary: List partitions
      operationId: listPartitions
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: database
          in: path
          required: true
          schema:
            type: string
        - name: table
          in: path
          required: true
          schema:
            type: string
        - name: maxResults
          in: query
          schema:
            type: integer
            format: int32
        - name: pageToken
          in: query
          schema:
            type: string
        - name: partitionNamePattern
          description: A sql LIKE pattern (% and _) for partition names.
          in: query
          schema:
            type: string
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ListPartitionsResponse'
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "404":
          $ref: '#/components/responses/TableNotExistErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
  /v1/{prefix}/databases/{database}/tables/{table}/partitions/mark:
    post:
      tags:
        - partition
      summary: MarkDone partitions
      operationId: markDonePartitions
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: database
          in: path
          required: true
          schema:
            type: string
        - name: table
          in: path
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MarkDonePartitionsRequest'
      responses:
        "200":
          description: Success, no content
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "404":
          $ref: '#/components/responses/TableNotExistErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
  /v1/{prefix}/databases/{database}/tables/{table}/branches:
    get:
      tags:
        - branch
      summary: List branches
      operationId: listBranches
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: database
          in: path
          required: true
          schema:
            type: string
        - name: table
          in: path
          required: true
          schema:
            type: string
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ListBranchesResponse'
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "404":
          $ref: '#/components/responses/TableNotExistErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
    post:
      tags:
        - branch
      summary: Create branch
      operationId: createBranch
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: database
          in: path
          required: true
          schema:
            type: string
        - name: table
          in: path
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateBranchRequest'
      responses:
        "200":
          description: Success, no content
        "400":
          $ref: '#/components/responses/BadRequestErrorResponse'
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "404":
          description:
            Not Found
            - TableNotExistException, table does not exist
            - TagNotExistException, the requested tag does not exist
          content:
            application/json:
              schema:
                $ref: '#/components/responses/ResourceNotExistErrorResponse'
              examples:
                TableNotExist:
                  $ref: '#/components/examples/TableNotExistError'
                TagNotExist:
                  $ref: '#/components/examples/TagNotExistError'
        "409":
          $ref: '#/components/responses/BranchAlreadyExistErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
  /v1/{prefix}/databases/{database}/tables/{table}/branches/{branch}:
    delete:
      tags:
        - branch
      summary: Drop branch
      operationId: dropBranch
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: database
          in: path
          required: true
          schema:
            type: string
        - name: table
          in: path
          required: true
          schema:
            type: string
        - name: branch
          in: path
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Success, no content
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "404":
          $ref: '#/components/responses/BranchNotExistErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
  /v1/{prefix}/databases/{database}/tables/{table}/branches/{branch}/forward:
    post:
      tags:
        - branch
      summary: forward branch
      operationId: forwardBranch
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: database
          in: path
          required: true
          schema:
            type: string
        - name: table
          in: path
          required: true
          schema:
            type: string
        - name: branch
          in: path
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ForwardBranchRequest'
      responses:
        "200":
          description: Success, no content
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "404":
          $ref: '#/components/responses/BranchNotExistErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
  /v1/{prefix}/databases/{database}/views:
    get:
      tags:
        - view
      summary: List views
      operationId: listViews
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: database
          in: path
          required: true
          schema:
            type: string
        - name: maxResults
          in: query
          schema:
            type: integer
            format: int32
        - name: pageToken
          in: query
          schema:
            type: string
        - name: viewNamePattern
          description: A sql LIKE pattern (% and _) for view names.
          in: query
          schema:
            type: string
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ListViewsResponse'
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "404":
          $ref: '#/components/responses/DatabaseNotExistErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
    post:
      tags:
        - view
      summary: Create view
      operationId: createView
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: database
          in: path
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateViewRequest'
      responses:
        "200":
          description: Success, no content
        "400":
          $ref: '#/components/responses/BadRequestErrorResponse'
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "404":
          $ref: '#/components/responses/DatabaseNotExistErrorResponse'
        "409":
          $ref: '#/components/responses/ViewAlreadyExistErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
  /v1/{prefix}/databases/{database}/view-details:
    get:
      tags:
        - view
      summary: List view details
      operationId: listViewDetails
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: database
          in: path
          required: true
          schema:
            type: string
        - name: maxResults
          in: query
          schema:
            type: integer
            format: int32
        - name: pageToken
          in: query
          schema:
            type: string
        - name: viewNamePattern
          description: A sql LIKE pattern (% and _) for view names.
          in: query
          schema:
            type: string
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ListViewDetailsResponse'
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "404":
          $ref: '#/components/responses/DatabaseNotExistErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
  /v1/{prefix}/databases/{database}/views/{view}:
    get:
      tags:
        - view
      summary: Get view
      operationId: getView
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: database
          in: path
          required: true
          schema:
            type: string
        - name: view
          in: path
          required: true
          schema:
            type: string
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GetViewResponse'
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "404":
          $ref: '#/components/responses/ViewNotExistErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
    post:
      tags:
        - view
      summary: Alter view
      operationId: alterView
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: database
          in: path
          required: true
          schema:
            type: string
        - name: view
          in: path
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AlterViewRequest'
      responses:
        "200":
          description: Success, no content
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "404":
          $ref: '#/components/responses/ViewNotExistErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
    delete:
      tags:
        - view
      summary: Drop view
      operationId: dropView
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: database
          in: path
          required: true
          schema:
            type: string
        - name: view
          in: path
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Success, no content
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "404":
          $ref: '#/components/responses/ViewNotExistErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
  /v1/{prefix}/views/rename:
    post:
      tags:
        - view
      summary: Rename view
      operationId: renameView
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RenameTableRequest'
      responses:
        "200":
          description: Success, no content
        "400":
          $ref: '#/components/responses/BadRequestErrorResponse'
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "404":
          $ref: '#/components/responses/ViewNotExistErrorResponse'
        "409":
          $ref: '#/components/responses/ViewAlreadyExistErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
components:
  #############################
  # Reusable Response Objects #
  #############################
  responses:
    BadRequestErrorResponse:
      description:
        Used for 400 errors, means illegal request.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example: {
            "message": "Malformed request",
            "code": 400
          }
    UnauthorizedErrorResponse:
      description:
        Used for 401 errors.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example: {
            "message": "No auth for this resource",
            "code": 401
          }
    ResourceNotExistErrorResponse:
      description:
        Used for 404 errors, which means the resource does not exist.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example: {
            "message": "Resource is not exist",
            "resourceType": "TABLE",
            "resourceName": "user",
            "code": 404
          }
    DatabaseNotExistErrorResponse:
      description:
        Not Found - DatabaseNotExistException, the database does not exist
      content:
        application/json:
          schema:
            $ref: '#/components/responses/ResourceNotExistErrorResponse'
          example:
            {
              "message": "The given database does not exist",
              "resourceType": "DATABASE",
              "resourceName": "db",
              "code": 404
            }
    TableNotExistErrorResponse:
      description:
        Not Found - TableNotExistException, the table does not exist
      content:
        application/json:
          schema:
            $ref: '#/components/responses/ResourceNotExistErrorResponse'
          example:
            {
              "message": "The given table does not exist",
              "resourceType": "TABLE",
              "resourceName": "table",
              "code": 404
            }
    SnapshotNotExistErrorResponse:
      description:
        Not Found - SnapshotNotExistException, the snapshot does not exist
      content:
        application/json:
          schema:
            $ref: '#/components/responses/ResourceNotExistErrorResponse'
          example:
            {
              "message": "The given snapshot does not exist",
              "resourceType": "SNAPSHOT",
              "resourceName": "1",
              "code": 404
            }
    BranchNotExistErrorResponse:
      description:
        Not Found - BranchNotExistException, the branch does not exist
      content:
        application/json:
          schema:
            $ref: '#/components/responses/ResourceNotExistErrorResponse'
          example:
            {
              "message": "The given branch does not exist",
              "resourceType": "BRANCH",
              "resourceName": "branch",
              "code": 404
            }
    ViewNotExistErrorResponse:
      description:
        Not Found - ViewNotExistException, the view does not exist
      content:
        application/json:
          schema:
            $ref: '#/components/responses/ResourceNotExistErrorResponse'
          example:
            {
              "message": "The given view does not exist",
              "resourceType": "VIEW",
              "resourceName": "view",
              "code": 404
            }
    ResourceAlreadyExistErrorResponse:
      description:
        Used for 409 errors.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example: {
            "message": "Resource has exist",
            "resourceType": "TABLE",
            "resourceName": "account",
            "code": 409
          }
    DatabaseAlreadyExistErrorResponse:
      description: Conflict - The database already exists
      content:
        application/json:
          schema:
            $ref: '#/components/responses/ResourceAlreadyExistErrorResponse'
          example:
            {
              "message": "The given database already exists",
              "resourceType": "DATABASE",
              "resourceName": "db",
              "code": 409
            }
    TableAlreadyExistErrorResponse:
      description: Conflict - The table already exists
      content:
        application/json:
          schema:
            $ref: '#/components/responses/ResourceAlreadyExistErrorResponse'
          example:
            {
              "message": "The given table already exists",
              "resourceType": "TABLE",
              "resourceName": "table",
              "code": 409
            }
    BranchAlreadyExistErrorResponse:
      description: Conflict - The branch already exists
      content:
        application/json:
          schema:
            $ref: '#/components/responses/ResourceAlreadyExistErrorResponse'
          example:
            {
              "message": "The given branch already exists",
              "resourceType": "BRANCH",
              "resourceName": "branch",
              "code": 409
            }
    ViewAlreadyExistErrorResponse:
      description: Conflict - The view already exists
      content:
        application/json:
          schema:
            $ref: '#/components/responses/ResourceAlreadyExistErrorResponse'
          example:
            {
              "message": "The given view already exists",
              "resourceType": "VIEW",
              "resourceName": "view",
              "code": 409
            }
    ServerErrorResponse:
      description:
        Used for server 5xx errors.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example: {
            "message": "Internal Server Error",
            "code": 500
          }
  schemas:
    CreateDatabaseRequest:
      type: object
      properties:
        name:
          type: string
        options:
          type: object
          additionalProperties:
            type: string
    CreatePartitionsRequest:
      type: object
      properties:
        specs:
          type: array
          items:
            type: object
    DropPartitionsRequest:
      type: object
      properties:
        specs:
          type: array
          items:
            type: object
    AlterTableRequest:
      type: object
      properties:
        changes:
          type: array
          items:
            $ref: '#/components/schemas/SchemaChange'
    MarkDonePartitionsRequest:
      type: object
      properties:
        specs:
          type: array
          items:
            type: object
    CreateDatabaseResponse:
      type: object
      properties:
        name:
          type: string
        options:
          type: object
          additionalProperties:
            type: string
    ErrorResponse:
      type: object
      properties:
        message:
          type: string
        resourceType:
          type: string
          nullable: true
          enum: [ "DATABASE", "TABLE", "COLUMN", "SNAPSHOT", "BRANCH", "TAG", "VIEW", "DIALECT", "UNKNOWN" ]
        resourceName:
          type: string
          nullable: true
        code:
          type: integer
          format: int32
    CreateTableRequest:
      type: object
      properties:
        identifier:
          $ref: '#/components/schemas/Identifier'
        schema:
          $ref: '#/components/schemas/Schema'
    CreateViewRequest:
      type: object
      properties:
        identifier:
          $ref: '#/components/schemas/Identifier'
        schema:
          $ref: '#/components/schemas/ViewSchema'
    AlterViewRequest:
      type: object
      properties:
        changes:
          type: array
          items:
            $ref: '#/components/schemas/ViewChange'
    ViewChange:
      anyOf:
        - $ref: '#/components/schemas/SetViewOption'
        - $ref: '#/components/schemas/RemoveViewOption'
        - $ref: '#/components/schemas/UpdateViewComment'
        - $ref: '#/components/schemas/AddDialect'
        - $ref: '#/components/schemas/UpdateDialect'
        - $ref: '#/components/schemas/DropDialect'
    BaseViewChange:
      discriminator:
        propertyName: action
        mapping:
          setOption: '#/components/schemas/SetViewOption'
          removeOption: '#/components/schemas/RemoveViewOption'
          updateComment: '#/components/schemas/UpdateViewComment'
          addDialect: '#/components/schemas/AddDialect'
          updateDialect: '#/components/schemas/UpdateDialect'
          dropDialect: '#/components/schemas/DropDialect'
      type: object
      required:
        - action
      properties:
        action:
          type: string
    SetViewOption:
      allOf:
        - $ref: '#/components/schemas/BaseViewChange'
      properties:
        action:
          type: string
          const: "setOption"
        key:
          type: string
        value:
          type: string
    RemoveViewOption:
      allOf:
        - $ref: '#/components/schemas/BaseViewChange'
      properties:
        action:
          type: string
          const: "removeOption"
        key:
          type: string
    UpdateViewComment:
      allOf:
        - $ref: '#/components/schemas/BaseViewChange'
      properties:
        action:
          type: string
          const: "updateComment"
        key:
          type: string
    AddDialect:
      allOf:
        - $ref: '#/components/schemas/BaseViewChange'
      properties:
        action:
          type: string
          const: "addDialect"
        dialect:
          type: string
        query:
          type: string
    UpdateDialect:
      allOf:
        - $ref: '#/components/schemas/BaseViewChange'
      properties:
        action:
          type: string
          const: "updateDialect"
        dialect:
          type: string
        query:
          type: string
    DropDialect:
      allOf:
        - $ref: '#/components/schemas/BaseViewChange'
      properties:
        action:
          type: string
          const: "dropDialect"
        dialect:
          type: string
    DataField:
      type: object
      properties:
        id:
          type: integer
          format: int32
        name:
          type: string
        type:
          $ref: '#/components/schemas/DataType'
        description:
          type: string
    DataType:
      oneOf:
        - $ref: '#/components/schemas/PrimitiveType'
        - $ref: '#/components/schemas/ArrayType'
        - $ref: '#/components/schemas/MultisetType'
        - $ref: '#/components/schemas/MapType'
        - $ref: '#/components/schemas/RowType'
    PrimitiveType:
      type: string
    ArrayType:
      type: object
      properties:
        type:
          type: string
          pattern: ^ARRAY.*
          example: ARRAY
        element:
          $ref: '#/components/schemas/DataType'
    MultisetType:
      type: object
      properties:
        type:
          type: string
          pattern: ^MULTISET.*
          example: MULTISET
        element:
          $ref: '#/components/schemas/DataType'
    MapType:
      type: object
      properties:
        type:
          type: string
          pattern: ^MAP.*
          example: MAP
        key:
          $ref: '#/components/schemas/DataType'
        value:
          $ref: '#/components/schemas/DataType'
    RowType:
      type: object
      properties:
        type:
          type: string
          pattern: ^ROW.*
          example: ROW
        fields:
          type: array
          items:
            $ref: '#/components/schemas/DataField'
    Identifier:
      type: object
      properties:
        database:
          type: string
        object:
          type: string
    Schema:
      type: object
      properties:
        fields:
          type: array
          items:
            $ref: '#/components/schemas/DataField'
        partitionKeys:
          type: array
          items:
            type: string
        primaryKeys:
          type: array
          items:
            type: string
        options:
          type: object
          additionalProperties:
            type: string
        comment:
          type: string
    GetTableResponse:
      type: object
      properties:
        id:
          type: string
        name:
          type: string
        path:
          type: string
        isExternal:
          type: boolean
        schemaId:
          type: integer
          format: int64
        schema:
          $ref: '#/components/schemas/Schema'
        owner:
          type: string
        createdAt:
          format: int64
        createdBy:
          type: string
        updatedAt:
          format: int64
        updatedBy:
          type: string
    SchemaChange:
      anyOf:
        - $ref: '#/components/schemas/SetOption'
        - $ref: '#/components/schemas/RemoveOption'
        - $ref: '#/components/schemas/UpdateComment'
        - $ref: '#/components/schemas/AddColumn'
        - $ref: '#/components/schemas/RenameColumn'
        - $ref: '#/components/schemas/DropColumn'
        - $ref: '#/components/schemas/UpdateColumnComment'
        - $ref: '#/components/schemas/UpdateColumnType'
        - $ref: '#/components/schemas/UpdateColumnPosition'
        - $ref: '#/components/schemas/UpdateColumnNullability'
    BaseSchemaChange:
      discriminator:
        propertyName: action
        mapping:
          setOption: '#/components/schemas/SetOption'
          removeOption: '#/components/schemas/RemoveOption'
          updateComment: '#/components/schemas/UpdateComment'
          addColumn: '#/components/schemas/AddColumn'
          renameColumn: '#/components/schemas/RenameColumn'
          dropColumn: '#/components/schemas/DropColumn'
          updateColumnComment: '#/components/schemas/UpdateColumnComment'
          updateColumnType: '#/components/schemas/UpdateColumnType'
          updateColumnPosition: '#/components/schemas/UpdateColumnPosition'
          updateColumnNullability: '#/components/schemas/UpdateColumnNullability'
      type: object
      required:
        - action
      properties:
        action:
          type: string
    SetOption:
      allOf:
        - $ref: '#/components/schemas/BaseSchemaChange'
      properties:
        action:
          type: string
          const: "setOption"
        key:
          type: string
        value:
          type: string
    RemoveOption:
      allOf:
        - $ref: '#/components/schemas/BaseSchemaChange'
      properties:
        action:
          type: string
          const: "removeOption"
        key:
          type: string
    UpdateComment:
      allOf:
        - $ref: '#/components/schemas/BaseSchemaChange'
      properties:
        action:
          type: string
          const: "updateComment"
        comment:
          type: string
    AddColumn:
      allOf:
        - $ref: '#/components/schemas/BaseSchemaChange'
      properties:
        action:
          type: string
          const: "addColumn"
        fieldNames:
          type: array
          items:
            type: string
        dataType:
          $ref: '#/components/schemas/DataType'
        comment:
          type: string
        move:
          $ref: '#/components/schemas/Move'
    RenameColumn:
      allOf:
        - $ref: '#/components/schemas/BaseSchemaChange'
      properties:
        action:
          type: string
          const: "renameColumn"
        fieldNames:
          type: array
          items:
            type: string
        newName:
          type: string
    DropColumn:
      allOf:
        - $ref: '#/components/schemas/BaseSchemaChange'
      properties:
        action:
          type: string
          const: "dropColumn"
        fieldNames:
          type: array
          items:
            type: string
    UpdateColumnComment:
      allOf:
        - $ref: '#/components/schemas/BaseSchemaChange'
      properties:
        action:
          type: string
          const: "updateColumnComment"
        fieldNames:
          type: array
          items:
            type: string
        newComment:
          type: string
    UpdateColumnType:
      allOf:
        - $ref: '#/components/schemas/BaseSchemaChange'
      properties:
        action:
          type: string
          const: "updateColumnType"
        fieldNames:
          type: array
          items:
            type: string
        newDataType:
          $ref: '#/components/schemas/DataType'
        keepNullability:
          type: boolean
    UpdateColumnPosition:
      allOf:
        - $ref: '#/components/schemas/BaseSchemaChange'
      properties:
        action:
          type: string
          const: "updateColumnPosition"
        move:
          $ref: '#/components/schemas/Move'
    UpdateColumnNullability:
      allOf:
        - $ref: '#/components/schemas/BaseSchemaChange'
      properties:
        action:
          type: string
          const: "updateColumnNullability"
        fieldNames:
          type: array
          items:
            type: string
        newNullability:
          type: boolean
    Move:
      type: object
      properties:
        fieldName:
          type: string
        referenceFieldName:
          type: string
        type:
          type: string
    RenameTableRequest:
      type: object
      properties:
        source:
          $ref: '#/components/schemas/Identifier'
        destination:
          $ref: '#/components/schemas/Identifier'
    CommitTableRequest:
      type: object
      properties:
        snapshot:
          $ref: '#/components/schemas/Snapshot'
        statistics:
          type: array
          items:
            $ref: '#/components/schemas/PartitionStatistics'
    RollbackTableRequest:
      type: object
      properties:
        instant:
          $ref: '#/components/schemas/Instant'
    Instant:
      anyOf:
        - $ref: '#/components/schemas/SnapshotInstant'
        - $ref: '#/components/schemas/TagInstant'

    BaseInstant:
      discriminator:
        propertyName: action
        mapping:
          snapshot: '#/components/schemas/SnapshotInstant'
          tag: '#/components/schemas/TagInstant'
      type: object
      required:
        - type
      properties:
        'type':
          type: string
    SnapshotInstant:
      allOf:
        - $ref: '#/components/schemas/BaseInstant'
      properties:
        'type':
          type: string
          const: "snapshot"
        snapshotId:
          type: integer
          format: int64
    TagInstant:
      allOf:
        - $ref: '#/components/schemas/BaseInstant'
      properties:
        'type':
          type: string
          const: "tag"
        tagName:
          type: string
    Snapshot:
      type: object
      properties:
        version:
          type: integer
          format: int32
          nullable: true
        id:
          type: integer
          format: int64
        schemaId:
          type: integer
          format: int64
        baseManifestList:
          type: string
        deltaManifestList:
          type: string
        changelogManifestList:
          type: string
          nullable: true
        indexManifest:
          type: string
        commitUser:
          type: string
        commitIdentifier:
          type: string
        commitKind:
          type: string
          enum: [ "APPEND", "COMPACT", "OVERWRITE", "ANALYZE" ]
        timeMillis:
          type: integer
          format: int64
        logOffsets:
          type: object
          additionalProperties:
            type: integer
            format: int64
        totalRecordCount:
          type: integer
          format: int64
        deltaRecordCount:
          type: integer
          format: int64
        changelogRecordCount:
          type: integer
          format: int64
        watermark:
          type: integer
          format: int64
        statistics:
          type: string
    TableSnapshot:
      type: object
      properties:
        snapshot:
          $ref: '#/components/schemas/Snapshot'
        recordCount:
          type: integer
          format: int64
        fileSizeInBytes:
          type: integer
          format: int64
        fileCount:
          type: integer
          format: int64
        lastFileCreationTime:
          type: integer
          format: int64
    CommitTableResponse:
      type: object
      properties:
        success:
          type: boolean
    GetTableDataTokenResponse:
      type: object
      properties:
        token:
          type: object
          additionalProperties:
            type: string
        expiresAt:
          type: integer
          format: int64
    GetTableSnapshotResponse:
      type: object
      properties:
        snapshot:
          $ref: '#/components/schemas/TableSnapshot'
    AlterDatabaseRequest:
      type: object
      properties:
        removals:
          type: array
          items:
            type: string
        updates:
          type: object
          additionalProperties:
            type: string
    AlterPartitionsRequest:
      type: object
      properties:
        partitions:
          type: array
          items:
            $ref: '#/components/schemas/Partition'
    AlterDatabaseResponse:
      type: object
      properties:
        removed:
          type: array
          items:
            type: string
        updated:
          type: array
          items:
            type: string
        missing:
          type: array
          items:
            type: string
    ListDatabasesResponse:
      type: object
      properties:
        databases:
          type: array
          items:
            type: string
        nextPageToken:
          type: string
    GetDatabaseResponse:
      type: object
      properties:
        id:
          type: string
        name:
          type: string
        location:
          type: string
        options:
          type: object
          additionalProperties:
            type: string
        owner:
          type: string
        createdAt:
          format: int64
        createdBy:
          type: string
        updatedAt:
          format: int64
        updatedBy:
          type: string
    ListTablesResponse:
      type: object
      properties:
        tables:
          type: array
          items:
            type: string
        nextPageToken:
          type: string
    ListTableDetailsResponse:
      type: object
      properties:
        tableDetails:
          type: array
          items:
            $ref: '#/components/schemas/GetTableResponse'
        nextPageToken:
          type: string
    ConfigResponse:
      type: object
      properties:
        defaults:
          type: object
          additionalProperties:
            type: string
        overrides:
          type: object
          additionalProperties:
            type: string
    ListPartitionsResponse:
      type: object
      properties:
        partitions:
          type: array
          items:
            $ref: '#/components/schemas/Partition'
        nextPageToken:
          type: string
    CreateBranchRequest:
      type: object
      properties:
        branch:
          type: string
        fromTag:
          nullable: true
          type: string
    ForwardBranchRequest:
      type: object
      properties:
        branch:
          type: string
    ListBranchesResponse:
      type: object
      properties:
        branches:
          type: array
          items:
            type: string
    GetViewResponse:
      type: object
      properties:
        id:
          type: string
        name:
          type: string
        schema:
          $ref: '#/components/schemas/ViewSchema'
        owner:
          type: string
        createdAt:
          format: int64
        createdBy:
          type: string
        updatedAt:
          format: int64
        updatedBy:
          type: string
    ListViewsResponse:
      type: object
      properties:
        views:
          type: array
          items:
            type: string
        nextPageToken:
          type: string
    ListViewDetailsResponse:
      type: object
      properties:
        viewDetails:
          type: array
          items:
            $ref: '#/components/schemas/GetViewResponse'
        nextPageToken:
          type: string
    ViewSchema:
      type: object
      properties:
        fields:
          type: array
          items:
            $ref: '#/components/schemas/DataField'
        query:
          type: string
        dialects:
          type: object
          additionalProperties:
            type: string
        comment:
          type: string
        options:
          type: object
          additionalProperties:
            type: string
    Partition:
      type: object
      properties:
        spec:
          type: object
        recordCount:
          type: integer
          format: int64
        fileSizeInBytes:
          type: integer
          format: int64
        fileCount:
          type: integer
          format: int64
        lastFileCreationTime:
          type: integer
          format: int64
        done:
          type: boolean
    PartitionStatistics:
      type: object
      properties:
        spec:
          type: object
        recordCount:
          type: integer
          format: int64
        fileSizeInBytes:
          type: integer
          format: int64
        fileCount:
          type: integer
          format: int64
        lastFileCreationTime:
          type: integer
          format: int64
  #######################################
  # Examples of different values #
  #######################################
  examples:
    TableNotExistError:
      summary: The requested table does not exist
      value: {
        "message": "The given table does not exist",
        "resourceType": "TABLE",
        "resourceName": "table",
        "code": 404
      }
    SnapshotNotExistError:
      summary: The requested snapshot does not exist
      value: {
        "message": "The given snapshot does not exist",
        "resourceType": "SNAPSHOT",
        "resourceName": "1",
        "code": 404
      }
    TagNotExistError:
      summary: The requested tag does not exist
      value: {
        "message": "The given tag does not exist",
        "resourceType": "TAG",
        "resourceName": "tag1",
        "code": 404
      }
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer