openapi: 3.0.1
info:
  title: Flink SQL Gateway REST API
  contact:
    email: user@flink.apache.org
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0.html
  version: v1/1.16-SNAPSHOT
paths:
  /api_versions:
    get:
      description: Get the current available versions for the Rest Endpoint. The client
        can choose one of the return version as the protocol for later communicate.
      operationId: getApiVersion
      responses:
        "200":
          description: The request was successful.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GetApiVersionResponseBody'
  /info:
    get:
      description: Get meta data for this cluster.
      operationId: getInfo
      responses:
        "200":
          description: The request was successful.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GetInfoResponseBody'
  /sessions:
    post:
      description: Opens a new session with specific properties. Specific properties
        can be given for current session which will override the default properties
        of gateway.
      operationId: openSession
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OpenSessionRequestBody'
      responses:
        "200":
          description: The request was successful.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OpenSessionResponseBody'
  /sessions/{session_handle}:
    get:
      description: Get the session configuration.
      operationId: getSessionConfig
      parameters:
      - name: session_handle
        in: path
        description: The SessionHandle that identifies a session.
        required: true
        schema:
          $ref: '#/components/schemas/SessionHandle'
      responses:
        "200":
          description: The request was successful.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GetSessionConfigResponseBody'
    delete:
      description: Closes the specific session.
      operationId: closeSession
      parameters:
      - name: session_handle
        in: path
        description: The SessionHandle that identifies a session.
        required: true
        schema:
          $ref: '#/components/schemas/SessionHandle'
      responses:
        "200":
          description: The request was successful.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CloseSessionResponseBody'
  /sessions/{session_handle}/heartbeat:
    post:
      description: "Trigger heartbeat to tell the server that the client is active,\
        \ and to keep the session alive as long as configured timeout value."
      operationId: triggerSession
      parameters:
      - name: session_handle
        in: path
        description: The SessionHandle that identifies a session.
        required: true
        schema:
          $ref: '#/components/schemas/SessionHandle'
      responses:
        "200":
          description: The request was successful.
  /sessions/{session_handle}/operations/{operation_handle}/cancel:
    post:
      description: Cancel the operation.
      operationId: cancelOperation
      parameters:
      - name: session_handle
        in: path
        description: The SessionHandle that identifies a session.
        required: true
        schema:
          $ref: '#/components/schemas/SessionHandle'
      - name: operation_handle
        in: path
        description: The OperationHandle that identifies a operation.
        required: true
        schema:
          $ref: '#/components/schemas/OperationHandle'
      responses:
        "200":
          description: The request was successful.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OperationStatusResponseBody'
  /sessions/{session_handle}/operations/{operation_handle}/close:
    delete:
      description: Close the operation.
      operationId: closeOperation
      parameters:
      - name: session_handle
        in: path
        description: The SessionHandle that identifies a session.
        required: true
        schema:
          $ref: '#/components/schemas/SessionHandle'
      - name: operation_handle
        in: path
        description: The OperationHandle that identifies a operation.
        required: true
        schema:
          $ref: '#/components/schemas/OperationHandle'
      responses:
        "200":
          description: The request was successful.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OperationStatusResponseBody'
  /sessions/{session_handle}/operations/{operation_handle}/result/{token}:
    get:
      description: Fetch results of Operation.
      operationId: fetchResults
      parameters:
      - name: session_handle
        in: path
        description: The SessionHandle that identifies a session.
        required: true
        schema:
          $ref: '#/components/schemas/SessionHandle'
      - name: operation_handle
        in: path
        description: The OperationHandle that identifies a operation.
        required: true
        schema:
          $ref: '#/components/schemas/OperationHandle'
      - name: token
        in: path
        description: The OperationHandle that identifies a operation.
        required: true
        schema:
          type: integer
          format: int64
      responses:
        "200":
          description: The request was successful.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FetchResultsResponseBody'
  /sessions/{session_handle}/operations/{operation_handle}/status:
    get:
      description: Get the status of operation.
      operationId: getOperationStatus
      parameters:
      - name: session_handle
        in: path
        description: The SessionHandle that identifies a session.
        required: true
        schema:
          $ref: '#/components/schemas/SessionHandle'
      - name: operation_handle
        in: path
        description: The OperationHandle that identifies a operation.
        required: true
        schema:
          $ref: '#/components/schemas/OperationHandle'
      responses:
        "200":
          description: The request was successful.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OperationStatusResponseBody'
  /sessions/{session_handle}/statements:
    post:
      description: Execute a statement.
      operationId: executeStatement
      parameters:
      - name: session_handle
        in: path
        description: The SessionHandle that identifies a session.
        required: true
        schema:
          $ref: '#/components/schemas/SessionHandle'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ExecuteStatementRequestBody'
      responses:
        "200":
          description: The request was successful.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExecuteStatementResponseBody'
components:
  schemas:
    CloseSessionResponseBody:
      type: object
      properties:
        status:
          type: string
    WatermarkSpec:
      type: object
      properties:
        rowtimeAttribute:
          type: string
        watermarkExpression:
          $ref: '#/components/schemas/ResolvedExpression'
    GetInfoResponseBody:
      type: object
      properties:
        productName:
          type: string
        version:
          type: string
    JobVertexID:
      pattern: "[0-9a-f]{32}"
      type: string
    ResolvedExpression:
      type: object
      properties:
        outputDataType:
          $ref: '#/components/schemas/DataType'
        resolvedChildren:
          type: array
          items:
            $ref: '#/components/schemas/ResolvedExpression'
        children:
          type: array
          items:
            $ref: '#/components/schemas/Expression'
    LogicalType:
      type: object
      properties:
        typeRoot:
          $ref: '#/components/schemas/LogicalTypeRoot'
        children:
          type: array
          items:
            $ref: '#/components/schemas/LogicalType'
        nullable:
          type: boolean
    UniqueConstraint:
      type: object
      properties:
        name:
          type: string
        enforced:
          type: boolean
        columns:
          type: array
          items:
            type: string
        type:
          $ref: '#/components/schemas/ConstraintType'
    ExecuteStatementRequestBody:
      type: object
      properties:
        statement:
          type: string
        executionTimeout:
          type: integer
          format: int64
        executionConfig:
          type: object
          additionalProperties:
            type: string
    LogicalTypeRoot:
      type: string
      enum:
      - CHAR
      - VARCHAR
      - BOOLEAN
      - BINARY
      - VARBINARY
      - DECIMAL
      - TINYINT
      - SMALLINT
      - INTEGER
      - BIGINT
      - FLOAT
      - DOUBLE
      - DATE
      - TIME_WITHOUT_TIME_ZONE
      - TIMESTAMP_WITHOUT_TIME_ZONE
      - TIMESTAMP_WITH_TIME_ZONE
      - TIMESTAMP_WITH_LOCAL_TIME_ZONE
      - INTERVAL_YEAR_MONTH
      - INTERVAL_DAY_TIME
      - ARRAY
      - MULTISET
      - MAP
      - ROW
      - DISTINCT_TYPE
      - STRUCTURED_TYPE
      - "NULL"
      - RAW
      - SYMBOL
      - UNRESOLVED
    OperationHandle:
      type: object
      properties:
        identifier:
          type: string
          format: uuid
    ExecuteStatementResponseBody:
      type: object
      properties:
        operationHandle:
          type: string
    FetchResultsResponseBody:
      type: object
      properties:
        results:
          $ref: '#/components/schemas/ResultSet'
        resultType:
          type: string
        nextResultUri:
          type: string
    RowData:
      type: object
      properties:
        arity:
          type: integer
          format: int32
        rowKind:
          $ref: '#/components/schemas/RowKind'
    Column:
      type: object
      properties:
        name:
          type: string
        dataType:
          $ref: '#/components/schemas/DataType'
        comment:
          type: string
        physical:
          type: boolean
        persisted:
          type: boolean
    TriggerId:
      pattern: "[0-9a-f]{32}"
      type: string
    ResourceID:
      pattern: "[0-9a-f]{32}"
      type: string
    OpenSessionRequestBody:
      type: object
      properties:
        sessionName:
          type: string
        properties:
          type: object
          additionalProperties:
            type: string
    ResultSet:
      type: object
      properties:
        resultType:
          $ref: '#/components/schemas/ResultType'
        nextToken:
          type: integer
          format: int64
        resultSchema:
          $ref: '#/components/schemas/ResolvedSchema'
        data:
          type: array
          items:
            $ref: '#/components/schemas/RowData'
    DataType:
      type: object
      properties:
        logicalType:
          $ref: '#/components/schemas/LogicalType'
        children:
          type: array
          items:
            $ref: '#/components/schemas/DataType'
    ResolvedSchema:
      type: object
      properties:
        columns:
          type: array
          items:
            $ref: '#/components/schemas/Column'
        watermarkSpecs:
          type: array
          items:
            $ref: '#/components/schemas/WatermarkSpec'
        primaryKey:
          $ref: '#/components/schemas/UniqueConstraint'
        primaryKeyIndexes:
          type: array
          items:
            type: integer
            format: int32
        columnCount:
          type: integer
          format: int32
        columnDataTypes:
          type: array
          items:
            $ref: '#/components/schemas/DataType'
        columnNames:
          type: array
          items:
            type: string
    GetSessionConfigResponseBody:
      type: object
      properties:
        properties:
          type: object
          additionalProperties:
            type: string
    SerializedThrowable:
      type: object
      properties:
        serialized-throwable:
          type: string
          format: binary
    GetApiVersionResponseBody:
      type: object
      properties:
        versions:
          type: array
          items:
            type: string
    OperationStatusResponseBody:
      type: object
      properties:
        status:
          type: string
    SessionHandle:
      type: object
      properties:
        identifier:
          type: string
          format: uuid
    ResultType:
      type: string
      enum:
      - NOT_READY
      - PAYLOAD
      - EOS
    Expression:
      type: object
    RowKind:
      type: string
      enum:
      - INSERT
      - UPDATE_BEFORE
      - UPDATE_AFTER
      - DELETE
    OpenSessionResponseBody:
      type: object
      properties:
        sessionHandle:
          type: string
    ConstraintType:
      type: string
      enum:
      - PRIMARY_KEY
      - UNIQUE_KEY
    IntermediateDataSetID:
      pattern: "[0-9a-f]{32}"
      type: string
    JobID:
      pattern: "[0-9a-f]{32}"
      type: string
