#
# 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 Database
      operationId: createDatabase
      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}/register:
    post:
      tags:
        - table
      summary: Register table
      operationId: RegisterTable
      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/RegisterTableRequest'
      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}/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 (%) for table names. Currently, only prefix matching is supported.
          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 (%) for table names. Currently, only prefix matching is supported.
          in: query
          schema:
            type: string
        - name: tableType
          description: Filter tables by table type. All table types will be returned if not set or empty.
          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}/tables:
    get:
      tags:
        - table
      summary: List tables globally
      operationId: ListTablesGlobally
      description: list tables paged globally which matches the given database name pattern and table name pattern both.
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: databaseNamePattern
          description: A sql LIKE pattern (%) for database names. All databases will be returned if not set or empty. Currently, only prefix matching is supported.
          in: path
          schema:
            type: string
        - name: tableNamePattern
          description: A sql LIKE pattern (%) for table names. All tables will be returned if not set or empty. Currently, only prefix matching is supported.
          in: query
          schema:
            type: string
        - name: maxResults
          in: query
          schema:
            type: integer
            format: int32
        - name: pageToken
          in: query
          schema:
            type: string

      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ListTablesGloballyResponse'
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "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}/auth:
    post:
      tags:
        - table
      summary: Auth table query
      operationId: authTableQuery
      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/AuthTableQueryRequest'
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AuthTableQueryResponse'
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "403":
          $ref: '#/components/responses/ForbiddenErrorResponse'
        404:
          description:
            Not Found
            - TableNotExistException, table does not exist
          content:
            application/json:
              schema:
                $ref: '#/components/responses/ResourceNotExistErrorResponse'
              examples:
                TableNotExist:
                  $ref: '#/components/examples/TableNotExistError'
        "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}/snapshots/{version}:
    get:
      tags:
        - table
      summary: Get version snapshot
      operationId: getVersionSnapshot
      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: version
          in: path
          required: true
          schema:
            type: string
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GetVersionSnapshotResponse'
        "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}/snapshots:
    get:
      tags:
        - table
      summary: List snapshots
      operationId: listSnapshots
      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
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ListSnapshotsResponse'
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "404":
          $ref: '#/components/responses/TableNotExistErrorResponse'
        "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 (%) for partition names. Currently, only prefix matching is supported.
          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 (%) for view names. Currently, only prefix matching is supported.
          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 (%) for view names. Currently, only prefix matching is supported.
          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}/views:
    get:
      tags:
        - view
      summary: List views globally
      operationId: listViewsGlobally
      description: List views globally which matches the given database name pattern and view name pattern both.
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: databaseNamePattern
          description: A sql LIKE pattern (%) for database names. All databases will be returned if not set or empty. Currently, only prefix matching is supported.
          in: path
          schema:
            type: string
        - name: viewNamePattern
          description: A sql LIKE pattern (%) for view names. All views will be returned if not set or empty. Currently, only prefix matching is supported.
          in: query
          schema:
            type: string
        - name: maxResults
          in: query
          schema:
            type: integer
            format: int32
        - name: pageToken
          in: query
          schema:
            type: string

      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ListViewsGloballyResponse'
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "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'
  /v1/{prefix}/databases/{database}/functions:
    get:
      tags:
        - function
      summary: List functions
      operationId: listFunctions
      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: functionNamePattern
          description: A sql LIKE pattern (%) for function names. Currently, only prefix matching is supported.
          in: query
          schema:
            type: string
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ListFunctionsResponse'
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "404":
          $ref: '#/components/responses/DatabaseNotExistErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
    post:
      tags:
        - function
      summary: Create function
      operationId: createFunction
      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/CreateFunctionRequest'
      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/FunctionAlreadyExistErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'

  /v1/{prefix}/databases/{database}/function-details:
    get:
      tags:
        - function
      summary: List function details
      operationId: listFunctionDetails
      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: functionNamePattern
          description: A sql LIKE pattern (%) for function names. Currently, only prefix matching is supported.
          in: query
          schema:
            type: string
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ListFunctionDetailsResponse'
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "404":
          $ref: '#/components/responses/DatabaseNotExistErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'

  /v1/{prefix}/functions:
    get:
      tags:
        - function
      summary: List functions globally
      operationId: listFunctionsGlobally
      description: List functions globally which matches the given database name pattern and function name pattern both.
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: databaseNamePattern
          description: A sql LIKE pattern (%) for database names. All databases will be returned if not set or empty. Currently, only prefix matching is supported.
          in: path
          schema:
            type: string
        - name: functionNamePattern
          description: A sql LIKE pattern (%) for function names. All functions will be returned if not set or empty. Currently, only prefix matching is supported.
          in: query
          schema:
            type: string
        - name: maxResults
          in: query
          schema:
            type: integer
            format: int32
        - name: pageToken
          in: query
          schema:
            type: string

      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ListFunctionsGloballyResponse'
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'


  /v1/{prefix}/databases/{database}/functions/{function}:
    get:
      tags:
        - function
      summary: Get function
      operationId: getFunction
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: database
          in: path
          required: true
          schema:
            type: string
        - name: function
          in: path
          required: true
          schema:
            type: string
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GetFunctionResponse'
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "404":
          $ref: '#/components/responses/FunctionNotExistErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
    post:
      tags:
        - function
      summary: Alter function
      operationId: alterFunction
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: database
          in: path
          required: true
          schema:
            type: string
        - name: function
          in: path
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AlterFunctionRequest'
      responses:
        "200":
          description: Success, no content
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "404":
          $ref: '#/components/responses/FunctionNotExistErrorResponse'
        "500":
          $ref: '#/components/responses/ServerErrorResponse'
    delete:
      tags:
        - function
      summary: Drop function
      operationId: dropFunction
      parameters:
        - name: prefix
          in: path
          required: true
          schema:
            type: string
        - name: database
          in: path
          required: true
          schema:
            type: string
        - name: function
          in: path
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Success, no content
        "401":
          $ref: '#/components/responses/UnauthorizedErrorResponse'
        "404":
          $ref: '#/components/responses/FunctionNotExistErrorResponse'
        "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
          }
    ForbiddenErrorResponse:
      description:
        Used for 403 errors.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example: {
            "message": "Table has no permission",
            "code": 403
          }
    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
            }
    FunctionNotExistErrorResponse:
      description:
        Not Found - FunctionNotExistException, the function does not exist
      content:
        application/json:
          schema:
            $ref: '#/components/responses/ResourceNotExistErrorResponse'
          example:
            {
              "message": "The given function does not exist",
              "resourceType": "FUNCTION",
              "resourceName": "function",
              "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
            }
    FunctionAlreadyExistErrorResponse:
      description: Conflict - The view already exists
      content:
        application/json:
          schema:
            $ref: '#/components/responses/ResourceAlreadyExistErrorResponse'
          example:
            {
              "message": "The given function already exists",
              "resourceType": "FUNCTION",
              "resourceName": "function",
              "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
    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'
    RegisterTableRequest:
      type: object
      properties:
        identifier:
          $ref: '#/components/schemas/Identifier'
        path:
          type: string
    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'
    CreateFunctionRequest:
      type: object
      properties:
        name:
          type: string
        inputParams:
          type: array
          items:
            $ref: '#/components/schemas/DataField'
        returnParams:
          type: array
          items:
            $ref: '#/components/schemas/DataField'
        deterministic:
          type: boolean
        definitions:
          type: object
          additionalProperties:
            $ref: "#/components/schemas/FunctionDefinition"
        comment:
          type: string
        options:
          type: object
          additionalProperties:
            type: string
    AlterFunctionRequest:
      type: object
      properties:
        changes:
          type: array
          items:
            $ref: '#/components/schemas/FunctionChange'
    FunctionChange:
      anyOf:
        - $ref: '#/components/schemas/SetFunctionOption'
        - $ref: '#/components/schemas/RemoveFunctionOption'
        - $ref: '#/components/schemas/UpdateFunctionComment'
        - $ref: '#/components/schemas/AddDefinition'
        - $ref: '#/components/schemas/UpdateDefinition'
        - $ref: '#/components/schemas/DropDefinition'
    BaseFunctionChange:
      discriminator:
        propertyName: action
        mapping:
          setOption: '#/components/schemas/SetFunctionOption'
          removeOption: '#/components/schemas/RemoveFunctionOption'
          updateComment: '#/components/schemas/UpdateFunctionComment'
          addDefinition: '#/components/schemas/AddDefinition'
          updateDefinition: '#/components/schemas/UpdateDefinition'
          dropDefinition: '#/components/schemas/DropDefinition'
      type: object
      required:
        - action
      properties:
        action:
          type: string
    SetFunctionOption:
      allOf:
        - $ref: '#/components/schemas/BaseFunctionChange'
      properties:
        action:
          type: string
          const: "setOption"
        key:
          type: string
        value:
          type: string
    RemoveFunctionOption:
      allOf:
        - $ref: '#/components/schemas/BaseFunctionChange'
      properties:
        action:
          type: string
          const: "removeOption"
        key:
          type: string
    UpdateFunctionComment:
      allOf:
        - $ref: '#/components/schemas/BaseFunctionChange'
      properties:
        action:
          type: string
          const: "updateComment"
        comment:
          type: string
    AddDefinition:
      allOf:
        - $ref: '#/components/schemas/BaseFunctionChange'
      properties:
        action:
          type: string
          const: "addDefinition"
        name:
          type: string
        definition:
          $ref: "#/components/schemas/FunctionDefinition"
    UpdateDefinition:
      allOf:
        - $ref: '#/components/schemas/BaseFunctionChange'
      properties:
        action:
          type: string
          const: "updateDefinition"
        name:
          type: string
        definition:
          $ref: "#/components/schemas/FunctionDefinition"
    DropDefinition:
      allOf:
        - $ref: '#/components/schemas/BaseFunctionChange'
      properties:
        action:
          type: string
          const: "dropDefinition"
        name:
          type: string
    FunctionDefinition:
      anyOf:
        - $ref: '#/components/schemas/FileFunctionDefinition'
        - $ref: '#/components/schemas/SQLFunctionDefinition'
        - $ref: '#/components/schemas/LambdaFunctionDefinition'
    BaseFunctionDefinition:
      discriminator:
        propertyName: type
        mapping:
          file: '#/components/schemas/FileFunctionDefinition'
          sql: '#/components/schemas/SQLFunctionDefinition'
          lambda: '#/components/schemas/LambdaFunctionDefinition'
      type: object
      required:
        - type
      properties:
        type:
          type: string
    SQLFunctionDefinition:
      allOf:
        - $ref: '#/components/schemas/BaseFunctionDefinition'
      properties:
        type:
          type: string
          const: "sql"
        definition:
          type: string
    FileFunctionDefinition:
      allOf:
        - $ref: '#/components/schemas/BaseFunctionDefinition'
      properties:
        type:
          type: string
          const: "file"
        fileResources:
          type: array
          items:
            $ref: '#/components/schemas/FunctionFileResource'
        language:
          type: string
        className:
          type: string
        functionName:
          type: string
    LambdaFunctionDefinition:
      allOf:
        - $ref: '#/components/schemas/BaseFunctionDefinition'
      properties:
        type:
          type: string
          const: "lambda"
        definition:
          type: string
        language:
          type: string
    FunctionFileResource:
      type: object
      properties:
        resourceType:
          type: string
        uri:
          type: string
    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/UpdateColumnDefaultValue'
        - $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'
          updateColumnDefaultValue: '#/components/schemas/UpdateColumnDefaultValue'
          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
    UpdateColumnDefaultValue:
      allOf:
        - $ref: '#/components/schemas/BaseSchemaChange'
      properties:
        action:
          type: string
          const: "updateColumnDefaultValue"
        fieldNames:
          type: array
          items:
            type: string
        newDefaultValue:
          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:
        tableId:
          type: string
        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'
    GetVersionSnapshotResponse:
      type: object
      properties:
        snapshot:
          $ref: '#/components/schemas/Snapshot'
    ListSnapshotsResponse:
      type: object
      properties:
        snapshots:
          type: array
          items:
            $ref: '#/components/schemas/Snapshot'
        nextPageToken:
          type: string
    AuthTableQueryRequest:
      type: object
      properties:
        select:
          type: array
          items:
            type: string
    AuthTableQueryResponse:
      type: object
      properties:
        filter:
          type: array
          items:
            type: string
    AlterDatabaseRequest:
      type: object
      properties:
        removals:
          type: array
          items:
            type: string
        updates:
          type: object
          additionalProperties:
            type: string
    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
            description: table name of the table.
        nextPageToken:
          type: string
    ListTableDetailsResponse:
      type: object
      properties:
        tableDetails:
          type: array
          items:
            $ref: '#/components/schemas/GetTableResponse'
        nextPageToken:
          type: string
    ListTablesGloballyResponse:
      type: object
      properties:
        tables:
          type: array
          items:
            identifier:
              $ref: '#/components/schemas/Identifier'
        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
            description: view name of the view.
        nextPageToken:
          type: string
    ListViewDetailsResponse:
      type: object
      properties:
        viewDetails:
          type: array
          items:
            $ref: '#/components/schemas/GetViewResponse'
        nextPageToken:
          type: string
    ListFunctionsGloballyResponse:
      type: object
      properties:
        functions:
          type: array
          items:
            $ref: '#/components/schemas/Identifier'
    ListViewsGloballyResponse:
      type: object
      properties:
        tables:
          type: array
          items:
            identifier:
              $ref: '#/components/schemas/Identifier'
        nextPageToken:
          type: string
    ListFunctionsResponse:
      type: object
      properties:
        functions:
          type: array
          items:
            type: string
        nextPageToken:
          type: string
    ListFunctionDetailsResponse:
      type: object
      properties:
        functionDetails:
          type: array
          items:
            $ref: '#/components/schemas/GetFunctionResponse'
        nextPageToken:
          type: string
    GetFunctionResponse:
      type: object
      properties:
        name:
          type: string
        inputParams:
          type: array
          items:
            $ref: '#/components/schemas/DataField'
        returnParams:
          type: array
          items:
            $ref: '#/components/schemas/DataField'
        deterministic:
          type: boolean
        definitions:
          type: object
          additionalProperties:
            $ref: "#/components/schemas/FunctionDefinition"
        comment:
          type: string
        options:
          type: object
          additionalProperties:
            type: string
        owner:
          type: string
        createdAt:
          format: int64
        createdBy:
          type: string
        updatedAt:
          format: int64
        updatedBy:
          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