{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/storelift-net/json-schema/storelift-net-hive-meta-schema.json",
  "title": "HiveMeta",
  "description": "Added to every /hive response (additive — existing fields are unchanged). `?envelope=data` returns `{ data, meta }` instead. Header `x-storelift-schema: hive.<endpoint>; v=<n>`.",
  "x-generated": "2026-11-26",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/storelift-net-openapi.yml#/components/schemas/HiveMeta",
  "type": "object",
  "required": [
    "schema",
    "schemaVersion",
    "apiVersion",
    "generatedAt",
    "coverage",
    "pagination",
    "units",
    "source"
  ],
  "properties": {
    "schema": {
      "type": "string",
      "description": "`hive.<endpoint>`"
    },
    "schemaVersion": {
      "type": "integer",
      "description": "Bumped only on a breaking change of this endpoint's body."
    },
    "envelopeVersion": {
      "type": "integer"
    },
    "measurementContract": {
      "$ref": "#/$defs/MeasurementContract"
    },
    "apiVersion": {
      "type": "string",
      "const": "v1"
    },
    "country": {
      "type": [
        "string",
        "null"
      ]
    },
    "platform": {
      "type": [
        "string",
        "null"
      ]
    },
    "asOf": {
      "type": [
        "string",
        "null"
      ],
      "format": "date",
      "description": "Newest measurement day in the body (UTC)."
    },
    "measuredAt": {
      "anyOf": [
        {
          "type": "string",
          "format": "date-time"
        },
        {
          "type": "string",
          "format": "date"
        },
        {
          "type": "null"
        }
      ]
    },
    "measuredAtPrecision": {
      "type": [
        "string",
        "null"
      ],
      "enum": [
        "instant",
        "day",
        null
      ]
    },
    "metricEvidence": {
      "type": "object",
      "properties": {
        "version": {
          "const": 1
        },
        "rows": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "term": {
                "type": "string"
              },
              "metrics": {
                "$ref": "#/$defs/HiveMetricPair"
              }
            }
          }
        }
      }
    },
    "generatedAt": {
      "type": "string",
      "format": "date-time"
    },
    "coverage": {
      "type": "object",
      "description": "What was asked vs. what was measured. A missing day is listed in `missing`, never filled with zeros.",
      "properties": {
        "requested": {
          "type": "integer"
        },
        "returned": {
          "type": "integer"
        },
        "unit": {
          "type": "string"
        },
        "missing": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "complete": {
          "type": [
            "boolean",
            "null"
          ]
        }
      },
      "additionalProperties": true
    },
    "pagination": {
      "type": "object",
      "properties": {
        "hasMore": {
          "type": "boolean"
        },
        "nextCursor": {
          "type": [
            "string",
            "null"
          ],
          "description": "Pass as `?cursor=` for the next page."
        },
        "page": {
          "type": "integer"
        },
        "pageSize": {
          "type": "integer"
        },
        "total": {
          "type": "integer"
        }
      }
    },
    "units": {
      "type": "object",
      "additionalProperties": {
        "type": "string"
      },
      "description": "Unit of each measured field present in the body."
    },
    "source": {
      "type": "string"
    }
  },
  "$defs": {
    "HiveMetricObservation": {
      "type": "object",
      "required": [
        "status",
        "kind",
        "value",
        "current",
        "source",
        "sourceObservedAt",
        "observedAtPrecision",
        "checkedAt",
        "period",
        "modelVersion",
        "evidence",
        "lastAttempt"
      ],
      "properties": {
        "status": {
          "type": "string",
          "enum": [
            "fresh",
            "stale",
            "pending",
            "absent",
            "error",
            "unmeasured",
            "restricted"
          ]
        },
        "kind": {
          "type": "string",
          "enum": [
            "observed",
            "estimated"
          ]
        },
        "value": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0,
          "maximum": 100
        },
        "current": {
          "type": "boolean"
        },
        "source": {
          "type": [
            "string",
            "null"
          ]
        },
        "sourceObservedAt": {
          "anyOf": [
            {
              "type": "string",
              "format": "date-time"
            },
            {
              "type": "string",
              "format": "date"
            },
            {
              "type": "null"
            }
          ],
          "description": "Original source observation time; a read or model calculation does not update it."
        },
        "observedAtPrecision": {
          "enum": [
            "instant",
            "day",
            null
          ]
        },
        "checkedAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "period": {
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "kind": {
              "enum": [
                "week",
                "day"
              ]
            },
            "start": {
              "type": "string",
              "format": "date"
            }
          }
        },
        "modelVersion": {
          "type": [
            "string",
            "null"
          ]
        },
        "evidence": {
          "type": [
            "object",
            "null"
          ],
          "additionalProperties": true,
          "description": "Source-bound evidence and available hashes. `observationId` is an opaque identifier scoped to your workspace: stable across your requests, never comparable with another workspace's identifiers. parsed_json_v1 describes a hash of parsed JSON, not raw response bytes."
        },
        "lastAttempt": {
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "status": {
              "enum": [
                "pending",
                "error"
              ]
            },
            "checkedAt": {
              "type": [
                "string",
                "null"
              ],
              "format": "date-time"
            },
            "attemptId": {
              "type": "string"
            }
          },
          "description": "Independent from a retained observation: a retry error does not erase an earlier valid value."
        }
      }
    },
    "HiveMetricPair": {
      "type": "object",
      "required": [
        "popularity",
        "difficulty"
      ],
      "properties": {
        "popularity": {
          "allOf": [
            {
              "$ref": "#/$defs/HiveMetricObservation"
            },
            {
              "properties": {
                "kind": {
                  "const": "observed"
                },
                "value": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "minimum": 1,
                  "maximum": 100
                }
              }
            }
          ]
        },
        "difficulty": {
          "allOf": [
            {
              "$ref": "#/$defs/HiveMetricObservation"
            },
            {
              "properties": {
                "kind": {
                  "const": "estimated"
                }
              }
            }
          ]
        }
      }
    },
    "MeasurementContract": {
      "type": "object",
      "description": "`engine` is an opaque, permanent contract code: it is not a measurement source, a model name or proof that observations are comparable. Rank revision identities are opaque stable integers (string identities remain strings in existing source fields and depth-cap keys). Compare revisions only within the same country, platform and term. Zero means unknown; distinct revisions retain distinct depth caps. Initial 0000-01-01 periods encode schedule defaults, never observation dates. Existing observed/estimated metric kinds, p1/p2 evidence, real source clocks and CSV columns are unchanged.",
      "required": [
        "version",
        "engine",
        "rankRevisionNamespace"
      ],
      "properties": {
        "version": {
          "const": 3
        },
        "engine": {
          "const": "e1"
        },
        "rankRevisionNamespace": {
          "const": "rank-v2"
        }
      }
    }
  }
}