{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://example.com/model-ranking/schema.json",
  "title": "ModelRankingData",
  "description": "大規模言語モデルランキングのデータセット用 JSON Schema。data/models.json と data/benchmarks.json はこの schema による検証を通過しなければならない。",
  "type": "object",
  "required": ["schema_version", "benchmarks", "models"],
  "additionalProperties": false,
  "properties": {
    "schema_version": {
      "type": "string",
      "const": "1.0.0"
    },
    "benchmarks": {
      "type": "array",
      "description": "ベンチマーク定義の一覧。ページ描画とモデルレコード内の benchmarks キーのホワイトリストとして機能する。",
      "minItems": 1,
      "items": { "$ref": "#/$defs/benchmark" }
    },
    "models": {
      "type": "array",
      "description": "モデルレコードの一覧。サイトの唯一のデータソース。",
      "minItems": 1,
      "items": { "$ref": "#/$defs/model" }
    }
  },
  "$defs": {
    "benchmark": {
      "type": "object",
      "description": "個々のベンチマークの定義：単位、方向、出典。",
      "required": ["key", "name", "unit", "direction", "higher_is_better", "description", "source_name", "source_url"],
      "additionalProperties": false,
      "properties": {
        "key": { "type": "string", "pattern": "^[a-z0-9][a-z0-9_-]*$", "description": "ベンチマークキー。モデルの benchmarks オブジェクトのキーと一致する。" },
        "name": { "type": "string", "minLength": 1, "description": "表示名。" },
        "unit": { "type": "string", "enum": ["index", "elo", "percent", "score"] },
        "direction": { "type": "string", "enum": ["higher", "lower"] },
        "higher_is_better": { "type": "boolean" },
        "description": { "type": "string", "minLength": 1 },
        "source_name": { "type": "string", "minLength": 1 },
        "source_url": { "type": "string", "format": "uri" }
      }
    },
    "license": {
      "type": "string",
      "enum": [
        "proprietary",
        "open-weights",
        "open-weights-commercial-restricted",
        "open-weights-non-commercial",
        "apache-2.0",
        "mit"
      ]
    },
    "pricing": {
      "type": "object",
      "required": ["input_per_million", "output_per_million", "currency", "cached_input_per_million", "notes"],
      "additionalProperties": false,
      "properties": {
        "input_per_million": { "type": ["number", "null"], "minimum": 0, "description": "100 万トークンあたりの入力価格。不明の場合は null。推定は禁止。" },
        "output_per_million": { "type": ["number", "null"], "minimum": 0, "description": "100 万トークンあたりの出力価格。不明の場合は null。" },
        "currency": { "type": ["string", "null"], "pattern": "^[A-Z]{3}$", "description": "ISO 4217 の通貨コード（例：USD）。不明の場合は null。" },
        "cached_input_per_million": { "type": ["number", "null"], "minimum": 0, "description": "キャッシュ命中時の 100 万トークンあたり入力価格。不明の場合は null。" },
        "notes": { "type": "string", "description": "価格の適用条件に関する説明。プロモーション価格か否か、時間帯で変動するかなど。" }
      }
    },
    "source": {
      "type": "object",
      "required": ["name", "url", "retrieved_at"],
      "additionalProperties": false,
      "properties": {
        "name": { "type": "string", "minLength": 1 },
        "url": { "type": "string", "format": "uri" },
        "retrieved_at": { "type": "string", "format": "date" }
      }
    },
    "arena_score": {
      "type": "object",
      "required": ["board_name", "score", "collected_at", "notes"],
      "additionalProperties": false,
      "properties": {
        "board_name": { "type": "string", "minLength": 1 },
        "score": { "type": ["number", "null"] },
        "collected_at": { "type": "string", "format": "date" },
        "notes": { "type": "string" }
      }
    },
    "model": {
      "type": "object",
      "required": [
        "id",
        "name",
        "vendor",
        "release_date",
        "license",
        "context_window",
        "pricing",
        "benchmarks",
        "arena_score",
        "sources",
        "notes",
        "last_updated"
      ],
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$",
          "description": "グローバルに一意な小文字ハイフン形式の ID。"
        },
        "name": { "type": "string", "minLength": 1 },
        "vendor": { "type": "string", "minLength": 1 },
        "release_date": { "type": "string", "format": "date" },
        "license": { "$ref": "#/$defs/license" },
        "license_label": { "type": "string", "minLength": 1, "description": "ライセンスの可読名（例：Apache 2.0）。" },
        "context_window": { "type": ["integer", "null"], "minimum": 1, "description": "コンテキスト長（トークン単位）。不明の場合は null。" },
        "pricing": { "$ref": "#/$defs/pricing" },
        "benchmarks": {
          "type": "object",
          "description": "キーは benchmarks ホワイトリスト内になければならない。値は不明の場合 null。",
          "propertyNames": { "type": "string", "pattern": "^[a-z0-9][a-z0-9_-]*$" },
          "additionalProperties": { "type": ["number", "null"] }
        },
        "arena_score": {
          "oneOf": [
            { "type": "null" },
            { "$ref": "#/$defs/arena_score" }
          ]
        },
        "sources": {
          "type": "array",
          "minItems": 1,
          "items": { "$ref": "#/$defs/source" }
        },
        "notes": { "type": "string", "description": "項目の欠落や不確実性に関する説明。" },
        "last_updated": { "type": "string", "format": "date" }
      }
    }
  }
}
