openapi: 3.0.1
security:
  - MitzuApiKey: []
info:
  title: Mitzu API
  description: |
    ## Mitzu API

    Mitzu API helps you to keep the catalog stored in Mitzu up-to-date when the data table schema
    in you data warehouse changes.

  version: "1.0"
tags:
  - name: Mitzu
    description: Mitzu operations
servers:
  - url: https://app.mitzu.io/api/v1
    description: Mitzu Cloud API endpoint
paths:
  /projects:
    get:
      summary: List projects
      operationId: list-projects
      tags:
        - project
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ListProjectsResponse"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "405":
          $ref: "#/components/responses/MethodNotAllowed"
        "429":
          $ref: "#/components/responses/TooManyRequests"

  /projects/{project_id}:
    get:
      summary: Project details
      description: Returns the project details including the configured tables
      operationId: project-details
      tags:
        - project
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ProjectDetailsResponse"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "405":
          $ref: "#/components/responses/MethodNotAllowed"
        "429":
          $ref: "#/components/responses/TooManyRequests"

  /projects/{project_id}/dimension-tables/{dimension_table_id}/index:
    post:
      summary: Index dimension table
      description:  Triggers indexing of the selected dimension table
      operationId: index-dimension-table
      tags:
        - project
        - indexing
      parameters:
        - name: project_id
          in: path
          description: The ID of the project
          required: true
          schema:
            type: string
        - name: dimension_table_id
          in: path
          description: The ID of the dimension table
          required: true
          schema:
            type: string
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TaskInfo"
        "404":
          description: Not Found
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    example: Project not found
        "401":
          $ref: "#/components/responses/Unauthorized"
        "405":
          $ref: "#/components/responses/MethodNotAllowed"
        "429":
          $ref: "#/components/responses/TooManyRequests"

  /projects/{project_id}/index-all-event-tables:
    post:
      summary: Index all event tables
      description:  Triggers indexing of all event tables in the project
      operationId: index-all-event-tables
      tags:
        - project
        - indexing
      parameters:
        - name: project_id
          in: path
          description: The ID of the project
          required: true
          schema:
            type: string
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/BulkIndexResponse"
        "404":
          description: Not Found
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    example: Project not found
        "401":
          $ref: "#/components/responses/Unauthorized"
        "405":
          $ref: "#/components/responses/MethodNotAllowed"
        "429":
          $ref: "#/components/responses/TooManyRequests"

components:
  responses:
    MethodNotAllowed:
      description: The requested HTTP method is not allowed.
    Unauthorized:
      description: The API key header is either missing or an invalid API key is given
    TooManyRequests:
      description: Too many requests sent with the same API key. Up to 10 requests can be sent within 1 second.
  schemas:
    TaskInfo:
      x-tags:
        - TaskInfo
      title: Task info
      description: Contains basic information about a task.
      type: object
      properties:
        id:
          type: string
          description: Unique ID of the task
        state:
          type: string
          enum:
            - queued
            - running
            - finished
            - cancelled
      additionalProperties: false

    BulkIndexResponse:
      x-tags:
        - BulkIndexResponse
      title: Index all tables response
      type: object
      properties:
        tasks:
          type: array
          items:
            $ref: '#/components/schemas/TaskInfo'
      additionalProperties: false

    ProjectInfo:
      x-tags:
        - ProjectInfo
      title: Project Info
      description: Contains basic information about a project.
      type: object
      properties:
        id:
          type: string
          description: Unique ID of the project
        name:
          type: string
          description: Name of the project
      additionalProperties: false

    ListProjectsResponse:
      x-tags:
        - ListProjectsResponse
      title: List project response
      type: object
      properties:
        projects:
          type: array
          items:
            $ref: '#/components/schemas/ProjectInfo'
      additionalProperties: false

    DimensionTableDetails:
      x-tags:
        - DimensionTableDetails
      title: Dimension table details
      description: Contains details about a dimension table
      properties:
        id:
          type: string
          description: Unique ID of the dimension table
        table_schema:
          type: string
          description: Schema of the dimension table in the data warehouse
        table_name:
          type: string
          description: Name of the dimension table in the data warehouse
      additionalProperties: false

    ProjectDetailsResponse:
      x-tags:
        - ProjectDetailsResponse
      title: Project details
      description: Contains project details including the configured tables
      properties:
        id:
          type: string
          description: Unique ID of the project
        name:
          type: string
          description: Name of the project
        dimension_tables:
          type: array
          items:
            $ref: '#/components/schemas/DimensionTableDetails'
      additionalProperties: false

  securitySchemes:
    MitzuApiKey:
      description: |
        ## API Key

        You can generate a new API key on the Account Settings -> API keys page.
      type: apiKey
      name: x-mitzu-api-key
      in: header
