openapi: '3.0.3'
info:
  version: '0.0.0'
  title: delika API version 1
  description: |
    delika API version 1 exposes some of the functions to handle datasets, data, and queires.
  license:
    name: 3-clause BSD
    url: https://docs.delika.io/api/v1/openapi/LICENSE
  termsOfService: https://docs.delika.io/terms-of-service.html
  contact:
    url: https://docs.delika.io/contact.html
    name: Connecto Data Inc.
    email: delika-support@connecto-data.com
servers:
  - url: https://api.delika.io/v1
    description: API servers
paths:
  /auth:
    get:
      summary: Authentication
      tags:
        - auth
      responses:
        '302':
          description: Redirect to the authentication server.
  /auth/token:
  #   get:
  #     summary: Show JWT info
  #     tags:
  #       - auth
  #     parameters:
  #       - name: code
  #         description: JWT
  #         in: query
  #         required: true
  #         schema:
  #           type: string
  #           format: JWT
  #     responses:
  #       '200':
  #         description: JWT info is displayed in your browser. You will copy the JWT info to activate your API client.
  #         content:
  #           text/html: {}
    post:
      summary: Renew JWT by refresh token
      tags:
        - auth
      requestBody:
        description: Valid refresh token.
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RefreshTokenRequest'
      responses:
        '200':
          description: JWT is successfully renewed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JwtResponse'
        '401':
          description: 'The given refresh token is invalidated.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeneralApiResponse'
  /me/datasets:
    get:
      summary: Get the list of datasets which you own
      tags:
        - user
        - account
      security:
        - jwt: []
      responses:
        '200':
          description: List of account's dataset.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DatasetListResponse'
        '401':
          description: 'Unauthorized: JWT is invalidated, or you does not agree to the current version of terms of service.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeneralApiResponse'
  /account/{AccountName}/datasets:
    get:
      summary: Get the list of datasets which the specified account owns
      tags:
        - account
      security:
        - jwt: []
      responses:
        '200':
          description: List of account's dataset.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DatasetListResponse'
        '401':
          description: 'Unauthorized: JWT is invalidated, or you does not agree to the current version of terms of service.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeneralApiResponse'
    parameters:
      - name: AccountName
        in: path
        description: The account name
        required: true
        schema:
          type: string
  /dataset/{AccountName}/{DatasetName}/data:
    get:
      summary: Get the list of datasets which the specified account owns
      tags:
        - dataset
      security:
        - jwt: []
      responses:
        '200':
          description: List of account's dataset.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DataListResponse'
        '401':
          description: 'Unauthorized: JWT is invalidated, or you does not agree to the current version of terms of service.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeneralApiResponse'
    parameters:
      - name: AccountName
        in: path
        description: The account name.
        required: true
        schema:
          type: string
      - name: DatasetName
        in: path
        description: The dataset name.
        required: true
        schema:
          type: string
  /data/{AccountName}/{DatasetName}/{DataName}:
    post:
      summary: Upload data
      tags:
        - data
      security:
        - jwt: []
      requestBody:
        description: A CSV file and data schema.
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/DataUploadRequest'
      responses:
        '200':
          description: File is successfully registered.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeneralApiResponse'
        '400':
          description: Got multiple files.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeneralApiResponse'
        '404':
          description: Dataset does not exist, or you are not eligible to upload.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeneralApiResponse'
    parameters:
      - name: AccountName
        in: path
        description: The account name.
        required: true
        schema:
          type: string
      - name: DatasetName
        in: path
        description: The dataset name.
        required: true
        schema:
          type: string
      - name: DataName
        in: path
        description: The data name.
        required: true
        schema:
          type: string
  /data/{AccountName}/{DatasetName}/{DataName}/rawdata:
    get:
      summary: Get the raw data
      tags:
        - data
      security:
        - jwt: []
      responses:
        '302':
          description: Redirect to the download URL.
        '401':
          description: 'Unauthorized: JWT is invalidated, or you does not agree to the current version of terms of service.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeneralApiResponse'
        '404':
          description: Data does not exist, or you are not eligible to download.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeneralApiResponse'
    parameters:
      - name: AccountName
        in: path
        description: The account name.
        required: true
        schema:
          type: string
      - name: DatasetName
        in: path
        description: The dataset name.
        required: true
        schema:
          type: string
      - name: DataName
        in: path
        description: The data name.
        required: true
        schema:
          type: string
  /data/{AccountName}/{DatasetName}/{DataName}/metadata/schema:
    get:
      summary: Get the schema of the data
      tags:
        - data
      security:
        - jwt: []
      responses:
        '200':
          description: The data schema.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DataSchemaResponse'
        '401':
          description: 'Unauthorized: JWT is invalidated, or you does not agree to the current version of terms of service.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeneralApiResponse'
        '404':
          description: Data does not exist, or you are not eligible to download.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeneralApiResponse'
    parameters:
      - name: AccountName
        in: path
        description: The account name.
        required: true
        schema:
          type: string
      - name: DatasetName
        in: path
        description: The dataset name.
        required: true
        schema:
          type: string
      - name: DataName
        in: path
        description: The data name.
        required: true
        schema:
          type: string
  /query:
    post:
      summary: Start new query
      tags:
        - query
      security:
        - jwt: []
      requestBody:
        description: SQL.
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SqlRequest'
      responses:
        '200':
          description: Query is queued.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/QueryResponse'
        '401':
          description: 'Unauthorized: JWT is invalidated, or you does not agree to the current version of terms of service.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeneralApiResponse'
  /query/{QueryId}/status:
    get:
      summary: Get the query status
      tags:
        - query
      security:
        - jwt: []
      responses:
        '200':
          description: Query is queued.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/QueryStatusResponse'
        '401':
          description: 'Unauthorized: JWT is invalidated, or you does not agree to the current version of terms of service.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeneralApiResponse'
        '404':
          description: Query does not exist, or you are not eligible to access.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeneralApiResponse'
    parameters:
      - name: QueryId
        in: path
        description: The query ID.
        required: true
        schema:
          type: string
  /query/{QueryId}/results/rawdata:
    get:
      summary: Get the query results
      tags:
        - query
      security:
        - jwt: []
      responses:
        '302':
          description: Redirect to the download URL of the query results.
        '400':
          description: Query is running yet.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeneralApiResponse'
        '401':
          description: 'Unauthorized: JWT is invalidated, or you does not agree to the current version of terms of service.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeneralApiResponse'
        '404':
          description: Query does not exist, or you are not eligible to access.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeneralApiResponse'
    parameters:
      - name: QueryId
        in: path
        description: The query ID.
        required: true
        schema:
          type: string
  /query/{QueryId}/results/metadata/schema:
    get:
      summary: Get the schema of the data
      tags:
        - query
      security:
        - jwt: []
      responses:
        '200':
          description: The data schema.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DataSchemaResponse'
        '401':
          description: 'Unauthorized: JWT is invalidated, or you does not agree to the current version of terms of service.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeneralApiResponse'
        '404':
          description: Data does not exist, or you are not eligible to download.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeneralApiResponse'
    parameters:
      - name: QueryId
        in: path
        description: The query ID.
        required: true
        schema:
          type: string
components:
  securitySchemes:
    jwt:
      description: JSON Web Token (JWT) for authorization.
      type: http
      scheme: bearer
      bearerFormat: JWT
  schemas:
    ApiResponseStatus:
      description: API response status.
      type: object
      properties:
        Code:
          description: Status code (same as the HTTP status code).
          type: integer
          format: int32
        Message:
          description: Error message.
          type: string
    GeneralApiResponse:
      description: General error response.
      type: object
      properties:
        Status:
          $ref: '#/components/schemas/ApiResponseStatus'
    RefreshTokenRequest:
      description: Refresh token.
      type: object
      properties:
        RefreshToken:
          description: Refresh token.
          type: string
    JwtResponse:
      allOf:
        - $ref: '#/components/schemas/GeneralApiResponse'
        - type: object
          properties:
            Data:
              description: Response data.
              type: object
              properties:
                TokenType:
                  description: Bearer.
                  type: string
                AccessToken:
                  description: Access token.
                  type: string
                AccessTokenExpiresOn:
                  description: Access token expiration time (UTC).
                  type: string
                  format: date-time
                RefreshToken:
                  description: Refresh token.
                  type: string
                RefreshTokenExpiresOn:
                  description: Refresh token expiration time (UTC).
                  type: string
                  format: date-time
    DataUploadRequest:
      description: Data upload.
      type: object
      properties:
        Schema:
          description: Data schema.
          type: string
        ForceGenerateTableDefinition:
          description: Determines whether TableDefinition is generated automatically.
          type: boolean
        Data:
          description: CSV file, possibly gzipped.
          type: string
          format: binary
    DatasetInfo:
      description: Information of dataset.
      type: object
      properties:
        AccountName:
          description: Account name.
          type: string
        DatasetName:
          description: Dataset name.
          type: string
    DataInfo:
      description: Information of dataset.
      type: object
      properties:
        AccountName:
          description: Account name.
          type: string
        DatasetName:
          description: Dataset name.
          type: string
        DataName:
          description: Data name.
          type: string
    DataSchema:
      description: Data schema.
      type: object
      properties:
        SchemaVersion:
          description: The version of the schema.
          type: string
        TableDefinition:
          description: The definition of the table.
          type: object
          properties:
            Columns:
              description: The list of the table columns.
              type: array
              items:
                description: Table column.
                type: object
                properties:
                  Name:
                    description: Name of the column.
                    type: string
                  DataType:
                    description: Data type of the column
                    type: object
                    properties:
                      DataType:
                        description: The type of data.
                        type: string
                      DataTypeOptions:
                        description: Optional information of the data type.
                        type: object
        DataSpecification:
          description: The data format description.
          type: object
          properties:
            FormatType:
              description: The format of the data.
              type: string
            DeliveryType:
              description: The type that indicates how the data is stored.
              type: string
            DataOptions:
              description: Optional information of the data.
              type: object
    DatasetListResponse:
      description: Dataset list.
      allOf:
        - $ref: '#/components/schemas/GeneralApiResponse'
        - type: object
          properties:
            Data:
              type: object
              properties:
                DatasetCount:
                  description: The number of datasets in the list.
                  type: integer
                DatasetList:
                  description: Result dataset list.
                  type: array
                  items:
                    $ref: '#/components/schemas/DatasetInfo'
    DataListResponse:
      description: Dataset list.
      allOf:
        - $ref: '#/components/schemas/GeneralApiResponse'
        - type: object
          properties:
            Data:
              description: Response data.
              type: object
              properties:
                DataCount:
                  description: The number of data in the result list.
                  type: integer
                DataList:
                  description: Result data list.
                  type: array
                  items:
                    $ref: '#/components/schemas/DataInfo'
    DataSchemaResponse:
      description: Dataset list.
      allOf:
        - $ref: '#/components/schemas/GeneralApiResponse'
        - type: object
          properties:
            Data:
              description: Response data.
              type: object
              properties:
                Schema:
                  # $ref: '#/components/schemas/DataSchema'
                  description: Data schema.
                  type: string
    SqlRequest:
      description: Select query.
      type: object
      properties:
        Sql:
          description: Select query.
          type: string
    QueryResponse:
      description: Query.
      allOf:
        - $ref: '#/components/schemas/GeneralApiResponse'
        - type: object
          properties:
            Data:
              description: Response data.
              type: object
              properties:
                QueryId:
                  description: Query ID.
                  type: string
    QueryStatusResponse:
      description: Query status.
      allOf:
        - $ref: '#/components/schemas/GeneralApiResponse'
        - type: object
          properties:
            Data:
              description: Response data.
              type: object
              properties:
                Status:
                  description: Query Status.
                  type: string
                Sql:
                  description: Requested query.
                  type: string
                CreatedAt:
                  description: Created time.
                  type: string
                  format: date-time
                UpdatedAt:
                  description: Created time.
                  type: string
                  format: date-time
                Message:
                  description: Message.
                  type: string
                Size:
                  description: Result size.
                  type: integer
                  format: int64
tags:
  - name: auth
    description: Endpoints related to authentication.
  - name: user
    description: Endpoints related to logged-in user's actions.
  - name: dataset
    description: Endpoints related to datasets manupilation.
  - name: data
    description: Endpoints related to data manupilation.
  - name: query
    description: Endpoints related to SQL queries.
  - name: experimental
    description: Endpoints tagged 'experimental' will experience big changes or might be deleted in the future. General users should not use these endpoints.
