{
  "openapi": "3.1.0",
  "info": {
    "title": "Ridge AI Data API",
    "version": "0.1.0"
  },
  "servers": [
    {
      "url": "https://app.ridgedata.ai",
      "description": "Ridge AI"
    }
  ],
  "security": [
    {
      "ridgeApiKey": []
    }
  ],
  "tags": [
    {
      "name": "Dashboards",
      "description": "Manage and retrieve dashboards."
    },
    {
      "name": "Datasources",
      "description": "Manage and retrieve datasources."
    },
    {
      "name": "Embed",
      "description": "Embed Ridge dashboards in other applications."
    }
  ],
  "components": {
    "securitySchemes": {
      "ridgeApiKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "Ridge API key (rk_…)"
      }
    },
    "schemas": {
      "PartitionFilter": {
        "type": "object",
        "required": [
          "column",
          "value"
        ],
        "properties": {
          "column": {
            "type": "string"
          },
          "value": {
            "type": "string"
          }
        }
      },
      "DashboardSpec": {
        "type": "object",
        "required": [
          "dashboardSpecId",
          "spec",
          "createdAt",
          "updatedAt"
        ],
        "properties": {
          "dashboardSpecId": {
            "type": "string"
          },
          "spec": {
            "type": "object",
            "description": "Parsed dashboard spec JSON."
          },
          "semanticModel": {
            "type": "object",
            "description": "Optional semantic model attached to the spec."
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "DashboardDatasource": {
        "type": "object",
        "required": [
          "datasourceId",
          "tableName"
        ],
        "properties": {
          "datasourceId": {
            "type": "string"
          },
          "tableName": {
            "type": "string"
          },
          "dataUrl": {
            "type": "string",
            "nullable": true,
            "description": "Pre-signed URL to fetch the parquet bytes for this datasource."
          }
        }
      },
      "Dashboard": {
        "type": "object",
        "required": [
          "dashboardId",
          "purpose",
          "domainContext",
          "createdAt",
          "updatedAt",
          "specs",
          "datasources",
          "dataAgentUrl"
        ],
        "properties": {
          "dashboardId": {
            "type": "string"
          },
          "purpose": {
            "type": "string"
          },
          "domainContext": {
            "type": "string"
          },
          "welcomeMessage": {
            "type": "string"
          },
          "analysisQuestions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "partitionFilters": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PartitionFilter"
            }
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "specs": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DashboardSpec"
            }
          },
          "datasources": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DashboardDatasource"
            }
          },
          "dataAgentUrl": {
            "type": "string"
          }
        }
      },
      "EmbedTokenRequest": {
        "type": "object",
        "description": "Restrict the issued token to a subset of dashboards and/or partition values. Omit both fields to allow access to every dashboard in the organization.",
        "properties": {
          "dashboardIds": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Dashboards the token may load. Each id must exist and be accessible to the calling API key."
          },
          "partitionFilters": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PartitionFilter"
            },
            "description": "Partition filters applied to every dataset request made with the token."
          }
        }
      },
      "EmbedTokenResponse": {
        "type": "object",
        "required": [
          "token"
        ],
        "properties": {
          "token": {
            "type": "string",
            "description": "Signed JWT (scope: `embed`). Pass it as `Authorization: Bearer <token>` when loading the embed bundle and its data requests."
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "message": {
            "type": "string"
          }
        }
      }
    }
  },
  "paths": {
    "/api/dashboards/{dashboardId}": {
      "get": {
        "tags": [
          "Dashboards"
        ],
        "summary": "Get a dashboard",
        "description": "Returns the dashboard, its specs, and the URLs needed to fetch its datasources.",
        "operationId": "getDashboard",
        "x-required-scopes": [
          "dashboard:read"
        ],
        "parameters": [
          {
            "name": "dashboardId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Dashboard payload",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Dashboard"
                }
              }
            }
          },
          "404": {
            "description": "Dashboard not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/datasources/{dataSourceId}/data": {
      "get": {
        "tags": [
          "Datasources"
        ],
        "summary": "Download the active dataset for a datasource",
        "description": "Returns parquet bytes for the datasource's active dataset. Supports `If-None-Match` for conditional fetches. Partition filters may be appended as query parameters.",
        "operationId": "getDatasourceData",
        "x-required-scopes": [
          "datasource:read"
        ],
        "parameters": [
          {
            "name": "dataSourceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "partition",
            "in": "query",
            "required": false,
            "description": "Partition filters as `partition.<column>=<value>` query parameters. Each entry restricts the returned bytes to rows where the partition column equals the given value. Repeat for multiple columns (e.g. `?partition.region=US&partition.year=2024`).",
            "style": "form",
            "explode": true,
            "schema": {
              "type": "object",
              "additionalProperties": {
                "type": "string"
              }
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Parquet bytes",
            "content": {
              "application/octet-stream": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "304": {
            "description": "Not modified"
          },
          "404": {
            "description": "Datasource or active dataset not found"
          }
        }
      }
    },
    "/api/embed/token": {
      "post": {
        "tags": [
          "Embed"
        ],
        "summary": "Create an embed token",
        "description": "Mints a short-lived JWT scoped to the embed bundle. The token may optionally be restricted to a set of dashboards and partition filters.",
        "operationId": "createEmbedToken",
        "x-required-scopes": [
          "management:read"
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EmbedTokenRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Signed embed token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EmbedTokenResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request body or unknown dashboard id",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  }
}
