{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/stackdata-io/json-schema/stackdata-io-series-response-schema.json",
  "title": "SeriesResponse",
  "x-generated": "2026-11-26",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/stackdata-io-openapi.json#/components/schemas/SeriesResponse",
  "type": "object",
  "required": [
    "status",
    "request",
    "observations"
  ],
  "properties": {
    "status": {
      "type": "string",
      "enum": [
        "ok",
        "empty",
        "refused"
      ]
    },
    "request": {
      "type": "object",
      "additionalProperties": true,
      "description": "The request as received."
    },
    "reason": {
      "type": "string",
      "description": "On `empty`, why there is nothing. On `refused`, one of `licence_unverified`,\n`no_data_path`, `not_in_serve_set`, `reader_refused`, `ambiguous_selection`.\n"
    },
    "detail": {
      "type": "string",
      "description": "With `reader_refused` and `ambiguous_selection`; also an `empty` caused by a reader's own message."
    },
    "dataset": {
      "type": "string",
      "description": "Present on refusals."
    },
    "resolved": {
      "type": "object",
      "description": "How the request was bound.",
      "properties": {
        "geo": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          },
          "description": "Caller code to the source's own geography code."
        },
        "select": {
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "label": {
                "type": "string"
              },
              "lang": {
                "type": "string"
              }
            }
          }
        },
        "freq": {
          "type": "string"
        },
        "window": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "minItems": 2,
          "maxItems": 2
        }
      }
    },
    "observations": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/SeriesObservation"
      }
    },
    "missing": {
      "type": "array",
      "description": "Requested country-periods with no observation (`{country, period}`), or `{country}` when the window is too long to enumerate. Withheld points are in `notes`, not here.",
      "items": {
        "type": "object",
        "properties": {
          "country": {
            "type": "string"
          },
          "period": {
            "type": "string"
          }
        }
      }
    },
    "notes": {
      "type": "array",
      "description": "What a plain gap would hide: from the reader (`withheld`, `window_capped`,\n`eliminated`, `opened`, `truncated`, `skipped_periods`, `refused_coordinates`),\nand from our own filtering — `other_frequency` (`count`, `frequencies`: points the\nsource returned at another frequency, left out) and `unrequested_geography`\n(`count`: points for geography codes the request did not name, left out). An answer\nempty only because of that filtering says so in `reason`.\n",
      "items": {
        "type": "object",
        "additionalProperties": true,
        "properties": {
          "kind": {
            "type": "string"
          },
          "reason": {
            "type": "string"
          }
        }
      }
    },
    "unparsed_periods": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Present only when the source returned period strings that could not be normalised; those points are not in `observations`."
    },
    "provenance": {
      "type": "object",
      "properties": {
        "dataset": {
          "type": "string"
        },
        "source_url": {
          "type": [
            "string",
            "null"
          ]
        },
        "licence": {
          "type": "object",
          "additionalProperties": true
        },
        "attribution": {
          "type": [
            "string",
            "null"
          ]
        },
        "cache_hit": {
          "type": "boolean"
        }
      }
    },
    "billing": {
      "type": "object",
      "additionalProperties": true,
      "description": "Metering outcome. Only an uncached upstream fetch is charged.",
      "properties": {
        "upstream_fetches": {
          "type": "integer"
        },
        "charged": {
          "type": "boolean"
        },
        "tier": {
          "type": "string"
        }
      }
    }
  },
  "$defs": {
    "SeriesObservation": {
      "type": "object",
      "required": [
        "country",
        "period",
        "value",
        "provenance"
      ],
      "properties": {
        "country": {
          "type": "string",
          "description": "The code the caller sent."
        },
        "period": {
          "type": "string",
          "description": "ISO period (YYYY",
          "YYYY-Qn": null,
          "YYYY-MM).": null
        },
        "value": {
          "type": [
            "number",
            "null"
          ]
        },
        "provenance": {
          "type": "object",
          "additionalProperties": true,
          "description": "The nested provenance envelope for this value: the raw string it came from, the\nrule that produced it, and `period_raw`, the period exactly as the source wrote it.\n",
          "properties": {
            "period_raw": {
              "type": "string"
            }
          }
        }
      }
    }
  }
}