{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://answerkb.com/schema/market.schema.json",
  "title": "Market series answer twin",
  "description": "Schema for the answer.json twin of each /markets/<topic>/latest/ page.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "id",
    "kind",
    "topic",
    "question",
    "common_queries",
    "answer",
    "value",
    "unit",
    "as_of",
    "last_updated",
    "stale_after",
    "status",
    "source_name",
    "source_url",
    "disclaimer",
    "history",
    "canonical_url"
  ],
  "properties": {
    "id": { "type": "string", "minLength": 1, "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$" },
    "kind": { "type": "string", "const": "market_series" },
    "topic": { "type": "string", "minLength": 1 },
    "question": { "type": "string", "minLength": 1 },
    "common_queries": {
      "type": "array",
      "items": { "type": "string", "minLength": 1 }
    },
    "answer": { "type": "string", "minLength": 1 },
    "value": { "type": ["number", "null"] },
    "value_high": { "type": ["number", "null"] },
    "unit": { "type": "string", "minLength": 1 },
    "as_of": { "type": ["string", "null"], "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
    "last_updated": { "type": ["string", "null"] },
    "stale_after": { "type": ["string", "null"] },
    "status": { "type": "string", "enum": ["awaiting", "fresh", "stale"] },
    "source_name": { "type": ["string", "null"], "minLength": 1 },
    "source_url": { "type": ["string", "null"], "format": "uri" },
    "disclaimer": { "type": "string", "minLength": 1 },
    "history": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["as_of", "value"],
        "properties": {
          "as_of": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
          "value": { "type": "number" },
          "value_high": { "type": ["number", "null"] }
        }
      }
    },
    "canonical_url": { "type": "string", "format": "uri" },
    "updated": { "type": "string", "format": "date" },
    "path": { "type": "string", "pattern": "^/" },
    "reporter": { "type": ["string", "null"] },
    "note": { "type": ["string", "null"] }
  }
}
