{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://raw.githubusercontent.com/api-evangelist/peaka/main/json-schema/peaka-query-request-schema.json",
  "title": "QueryRequest",
  "x-generated": "2026-10-21",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/_original/peaka-api-openapi.json#/components/schemas/QueryRequest",
  "type": "object",
  "properties": {
    "displayName": {
      "type": "string",
      "description": "The display name of the query."
    },
    "inputQuery": {
      "type": [
        "string",
        "null"
      ],
      "description": "The SQL query. Required unless inputQueryRefId is provided."
    },
    "queryType": {
      "type": "string",
      "description": "The type of the query. Defaults to PLAIN.",
      "default": "PLAIN",
      "enum": [
        "PLAIN",
        "MATERIALIZED"
      ]
    },
    "schedule": {
      "$ref": "#/$defs/MaterializedQuerySchedule"
    },
    "inputQueryRefId": {
      "type": [
        "string",
        "null"
      ],
      "description": "The id of an existing query to materialize. Valid only if the query type is MATERIALIZED. When set, the materialized query is built from the referenced query's SQL and inputQuery is not required. The reference is resolved when the request is processed: a snapshot of the referenced query's SQL is stored as this query's inputQuery. The reference id itself is not persisted and is not returned in responses; later changes to the referenced query do not propagate. Send the reference again on an update to re-resolve from the source."
    },
    "path": {
      "type": [
        "string",
        "null"
      ],
      "description": "The folder path to place this query in. Intermediate folders are created automatically. If omitted, the query is placed at the root level."
    }
  },
  "$defs": {
    "MaterializedQuerySchedule": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "type": {
          "type": "string",
          "description": "Type of schedule.",
          "enum": [
            "interval",
            "cron",
            "none"
          ]
        },
        "cronExpression": {
          "type": [
            "string",
            "null"
          ],
          "description": "UNIX cron expression (minute hour day-of-month month day-of-week), e.g. '0 0 * * *' for every day at midnight. Set only when the schedule type is 'cron'."
        },
        "repeatDuration": {
          "type": [
            "string",
            "null"
          ],
          "description": "ISO-8601 duration between refreshes, e.g. 'PT6H' (every 6 hours), 'PT12H' (twice daily), 'P1D' (daily). Set only when the schedule type is 'interval'."
        },
        "timezone": {
          "type": [
            "string",
            "null"
          ],
          "description": "IANA timezone used to evaluate the cron expression, e.g. 'UTC' or 'Europe/Istanbul'. Set only when the schedule type is 'cron'."
        }
      },
      "description": "Schedule configuration of a materialized query. Provide EITHER an interval schedule (`type=interval` with `repeatDuration`) OR a cron schedule (`type=cron` with `cronExpression` and optional `timezone`). Use `type=none` for no schedule. The fields that do not apply to the chosen type are omitted."
    }
  }
}