{
  "openapi": "3.1.1",
  "info": {
    "title": "調布データマップ 公開データAPI",
    "version": "1.0.0",
    "description": "認証不要・読み取り専用の非公式API。住民基本台帳の人口・世帯数と2020年町丁境界を提供します。原表空欄・未掲載・未収録を区別し、0で埋めません。各GETはHEADにも対応し、OPTIONSでCORSを確認できます。大量取得には版付き静的JSON・CSVを利用してください。同じデータを/mcpのMCPツールからも取得できます。"
  },
  "servers": [
    {
      "url": "https://chofu-data.tokyo/api/v1"
    }
  ],
  "security": [],
  "paths": {
    "/datasets": {
      "get": {
        "operationId": "listDatasets",
        "summary": "公開データセットの一覧",
        "description": "data_revisionを指定すると過去の版に固定できます。ページ分割された結果はnext_urlをたどってください。",
        "parameters": [
          {
            "name": "data_revision",
            "in": "query",
            "required": false,
            "description": "データの版。省略時はカタログの現行版。次ページでも同じ版を使います。",
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$",
              "description": "データの版。省略時はカタログの現行版。次ページでも同じ版を使います。"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "定義・出典・版・必要な注意事項を含む取得結果",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DatasetsResponse"
                }
              }
            },
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string"
                }
              },
              "X-Data-Revision": {
                "schema": {
                  "type": "string",
                  "pattern": "^[0-9a-f]{64}$"
                }
              }
            }
          },
          "304": {
            "description": "If-None-Matchに一致。本文なし。"
          },
          "400": {
            "description": "理由付きJSONエラー。数値0や空配列への置き換えは行いません。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "理由付きJSONエラー。数値0や空配列への置き換えは行いません。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "理由付きJSONエラー。数値0や空配列への置き換えは行いません。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "414": {
            "description": "理由付きJSONエラー。数値0や空配列への置き換えは行いません。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "理由付きJSONエラー。数値0や空配列への置き換えは行いません。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "理由付きJSONエラー。数値0や空配列への置き換えは行いません。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/datasets/{dataset_id}": {
      "get": {
        "operationId": "describeDataset",
        "summary": "定義・単位・収録日・出典・制約",
        "description": "data_revisionを指定すると過去の版に固定できます。ページ分割された結果はnext_urlをたどってください。",
        "parameters": [
          {
            "name": "dataset_id",
            "in": "path",
            "required": true,
            "schema": {
              "enum": [
                "population",
                "town_boundaries"
              ],
              "type": "string"
            }
          },
          {
            "name": "data_revision",
            "in": "query",
            "required": false,
            "description": "データの版。省略時はカタログの現行版。次ページでも同じ版を使います。",
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$",
              "description": "データの版。省略時はカタログの現行版。次ページでも同じ版を使います。"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "定義・出典・版・必要な注意事項を含む取得結果",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DatasetResponse"
                }
              }
            },
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string"
                }
              },
              "X-Data-Revision": {
                "schema": {
                  "type": "string",
                  "pattern": "^[0-9a-f]{64}$"
                }
              }
            }
          },
          "304": {
            "description": "If-None-Matchに一致。本文なし。"
          },
          "400": {
            "description": "理由付きJSONエラー。数値0や空配列への置き換えは行いません。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "理由付きJSONエラー。数値0や空配列への置き換えは行いません。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "理由付きJSONエラー。数値0や空配列への置き換えは行いません。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "414": {
            "description": "理由付きJSONエラー。数値0や空配列への置き換えは行いません。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "理由付きJSONエラー。数値0や空配列への置き換えは行いません。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "理由付きJSONエラー。数値0や空配列への置き換えは行いません。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/areas": {
      "get": {
        "operationId": "searchAreas",
        "summary": "区域名・IDの検索",
        "description": "data_revisionを指定すると過去の版に固定できます。ページ分割された結果はnext_urlをたどってください。",
        "parameters": [
          {
            "name": "data_revision",
            "in": "query",
            "required": false,
            "description": "データの版。省略時はカタログの現行版。次ページでも同じ版を使います。",
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$",
              "description": "データの版。省略時はカタログの現行版。次ページでも同じ版を使います。"
            }
          },
          {
            "name": "q",
            "in": "query",
            "required": false,
            "description": "区域名・別名・IDの部分一致。候補を返し、自動で1区域に確定しません。",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 100,
              "description": "区域名・別名・IDの部分一致。候補を返し、自動で1区域に確定しません。"
            }
          },
          {
            "name": "geography_level",
            "in": "query",
            "required": false,
            "description": "市全体と町丁別を明示します。人口取得では必須。",
            "schema": {
              "type": "string",
              "enum": [
                "municipality",
                "town_area"
              ],
              "description": "市全体と町丁別を明示します。人口取得では必須。"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "1ページの最大行数。欠損行も件数に含みます。",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100,
              "description": "1ページの最大行数。欠損行も件数に含みます。"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "description": "次ページの不透明なトークン。ほかのクエリパラメーターと併用できません。",
            "schema": {
              "type": "string",
              "maxLength": 2048,
              "description": "次ページの不透明なトークン。ほかのクエリパラメーターと併用できません。"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "定義・出典・版・必要な注意事項を含む取得結果",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AreasResponse"
                }
              }
            },
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string"
                }
              },
              "X-Data-Revision": {
                "schema": {
                  "type": "string",
                  "pattern": "^[0-9a-f]{64}$"
                }
              }
            }
          },
          "304": {
            "description": "If-None-Matchに一致。本文なし。"
          },
          "400": {
            "description": "理由付きJSONエラー。数値0や空配列への置き換えは行いません。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "理由付きJSONエラー。数値0や空配列への置き換えは行いません。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "理由付きJSONエラー。数値0や空配列への置き換えは行いません。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "414": {
            "description": "理由付きJSONエラー。数値0や空配列への置き換えは行いません。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "理由付きJSONエラー。数値0や空配列への置き換えは行いません。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "理由付きJSONエラー。数値0や空配列への置き換えは行いません。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/population/observations": {
      "get": {
        "operationId": "queryPopulation",
        "summary": "人口・世帯数・人口密度の取得",
        "description": "初回はgeography_levelと、dateまたはfrom/toが必須。cursor指定時はcursorだけを渡します。基準日・区域IDの昇順。集計・補間・暗黙の日付置換は行いません。期間内の未収録月はmetaに含めます。",
        "parameters": [
          {
            "name": "data_revision",
            "in": "query",
            "required": false,
            "description": "データの版。省略時はカタログの現行版。次ページでも同じ版を使います。",
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$",
              "description": "データの版。省略時はカタログの現行版。次ページでも同じ版を使います。"
            }
          },
          {
            "name": "geography_level",
            "in": "query",
            "required": false,
            "description": "市全体と町丁別を明示します。人口取得では必須。",
            "schema": {
              "type": "string",
              "enum": [
                "municipality",
                "town_area"
              ],
              "description": "市全体と町丁別を明示します。人口取得では必須。"
            }
          },
          {
            "name": "area_ids",
            "in": "query",
            "required": false,
            "description": "区域IDをカンマ区切りで最大10件。省略時は指定した地理粒度の全区域。",
            "schema": {
              "type": "array",
              "minItems": 1,
              "maxItems": 10,
              "uniqueItems": true,
              "items": {
                "type": "string",
                "pattern": "^(chofu-city|13208[0-9]+)$"
              },
              "description": "区域IDをカンマ区切りで最大10件。省略時は指定した地理粒度の全区域。"
            },
            "style": "form",
            "explode": false
          },
          {
            "name": "date",
            "in": "query",
            "required": false,
            "description": "基準日またはlatest（最新収録日）。from/toとの併用不可。",
            "schema": {
              "type": "string",
              "pattern": "^(?:\\d{4}-\\d{2}-\\d{2}|latest)$",
              "description": "基準日またはlatest（最新収録日）。from/toとの併用不可。"
            }
          },
          {
            "name": "from",
            "in": "query",
            "required": false,
            "description": "期間の開始日（含む）。toも必須。未収録月は補間しません。",
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
              "description": "期間の開始日（含む）。toも必須。未収録月は補間しません。"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "description": "期間の終了日（含む）。fromも必須。",
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
              "description": "期間の終了日（含む）。fromも必須。"
            }
          },
          {
            "name": "metrics",
            "in": "query",
            "required": false,
            "description": "カンマ区切り。densityは町丁別のみ。時点間・区域間の集計は行いません。",
            "schema": {
              "type": "array",
              "minItems": 1,
              "uniqueItems": true,
              "items": {
                "type": "string",
                "enum": [
                  "population",
                  "male",
                  "female",
                  "households",
                  "density"
                ]
              },
              "default": [
                "population"
              ],
              "description": "カンマ区切り。densityは町丁別のみ。時点間・区域間の集計は行いません。"
            },
            "style": "form",
            "explode": false
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "1ページの最大行数。欠損行も件数に含みます。",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100,
              "description": "1ページの最大行数。欠損行も件数に含みます。"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "description": "次ページの不透明なトークン。ほかのクエリパラメーターと併用できません。",
            "schema": {
              "type": "string",
              "maxLength": 2048,
              "description": "次ページの不透明なトークン。ほかのクエリパラメーターと併用できません。"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "定義・出典・版・必要な注意事項を含む取得結果",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ObservationsResponse"
                }
              }
            },
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string"
                }
              },
              "X-Data-Revision": {
                "schema": {
                  "type": "string",
                  "pattern": "^[0-9a-f]{64}$"
                }
              }
            }
          },
          "304": {
            "description": "If-None-Matchに一致。本文なし。"
          },
          "400": {
            "description": "理由付きJSONエラー。数値0や空配列への置き換えは行いません。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "理由付きJSONエラー。数値0や空配列への置き換えは行いません。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "理由付きJSONエラー。数値0や空配列への置き換えは行いません。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "414": {
            "description": "理由付きJSONエラー。数値0や空配列への置き換えは行いません。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "理由付きJSONエラー。数値0や空配列への置き換えは行いません。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "理由付きJSONエラー。数値0や空配列への置き換えは行いません。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/boundaries/{area_id}": {
      "get": {
        "operationId": "getBoundary",
        "summary": "町丁境界の属性とGeoJSON取得先",
        "description": "data_revisionを指定すると過去の版に固定できます。ページ分割された結果はnext_urlをたどってください。",
        "parameters": [
          {
            "name": "area_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^13208[0-9]+$"
            }
          },
          {
            "name": "data_revision",
            "in": "query",
            "required": false,
            "description": "データの版。省略時はカタログの現行版。次ページでも同じ版を使います。",
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$",
              "description": "データの版。省略時はカタログの現行版。次ページでも同じ版を使います。"
            }
          },
          {
            "name": "boundary_version",
            "in": "query",
            "required": false,
            "description": "境界の版。人口密度は2020年境界を分母に使います。",
            "schema": {
              "type": "string",
              "enum": [
                "census-2020"
              ],
              "description": "境界の版。人口密度は2020年境界を分母に使います。"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "定義・出典・版・必要な注意事項を含む取得結果",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BoundaryResponse"
                }
              }
            },
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string"
                }
              },
              "X-Data-Revision": {
                "schema": {
                  "type": "string",
                  "pattern": "^[0-9a-f]{64}$"
                }
              }
            }
          },
          "304": {
            "description": "If-None-Matchに一致。本文なし。"
          },
          "400": {
            "description": "理由付きJSONエラー。数値0や空配列への置き換えは行いません。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "理由付きJSONエラー。数値0や空配列への置き換えは行いません。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "理由付きJSONエラー。数値0や空配列への置き換えは行いません。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "414": {
            "description": "理由付きJSONエラー。数値0や空配列への置き換えは行いません。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "理由付きJSONエラー。数値0や空配列への置き換えは行いません。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "理由付きJSONエラー。数値0や空配列への置き換えは行いません。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Coverage": {
        "type": "object",
        "properties": {
          "reference_dates": {
            "type": "array",
            "items": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          "latest_reference_date": {
            "type": "string",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
          },
          "expected_frequency": {
            "type": "string"
          },
          "temporal_granularity": {
            "type": "string"
          },
          "uncollected_reference_dates": {
            "type": "array",
            "items": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          "uncollected_reason": {
            "type": "string"
          },
          "freshness_status": {
            "type": "string"
          },
          "source_checked_at": {
            "type": [
              "string",
              "null"
            ]
          },
          "data_revision": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          }
        },
        "required": [
          "reference_dates",
          "latest_reference_date",
          "expected_frequency",
          "temporal_granularity",
          "uncollected_reference_dates",
          "uncollected_reason",
          "freshness_status",
          "source_checked_at",
          "data_revision"
        ],
        "additionalProperties": false
      },
      "Source": {
        "type": "object",
        "properties": {
          "source_id": {
            "type": "string"
          },
          "publisher": {
            "type": "string"
          },
          "source_url": {
            "type": "string"
          },
          "original_url": {
            "type": "string"
          },
          "license_id": {
            "type": "string"
          },
          "license_url": {
            "type": "string"
          },
          "attribution": {
            "type": "string"
          },
          "modifications": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "data_revision": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          }
        },
        "required": [
          "source_id",
          "publisher",
          "source_url",
          "original_url",
          "license_id",
          "license_url",
          "attribution",
          "modifications",
          "data_revision"
        ],
        "additionalProperties": true
      },
      "Pagination": {
        "type": "object",
        "properties": {
          "total_rows": {
            "type": "integer",
            "minimum": 0
          },
          "returned_rows": {
            "type": "integer",
            "minimum": 0
          },
          "limit": {
            "type": "integer",
            "minimum": 1,
            "maximum": 500,
            "default": 100,
            "description": "1ページの最大行数。欠損行も件数に含みます。"
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          },
          "next_url": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "total_rows",
          "returned_rows",
          "limit",
          "next_cursor",
          "next_url"
        ],
        "additionalProperties": false
      },
      "Metadata": {
        "type": "object",
        "properties": {
          "applied_filters": {
            "type": "object"
          },
          "units": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "coverage": {
            "$ref": "#/components/schemas/Coverage"
          },
          "definition_status": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "uncollected_reference_dates_in_range": {
            "type": "array",
            "items": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Source"
            }
          },
          "links": {
            "type": "object",
            "properties": {
              "release": {
                "type": "string"
              },
              "dataset": {
                "type": "string"
              },
              "coverage": {
                "type": "string"
              },
              "provenance": {
                "type": "string"
              },
              "quality": {
                "type": "string"
              },
              "sources": {
                "type": "string"
              },
              "bulk": {
                "type": "object",
                "additionalProperties": {
                  "type": "string"
                }
              }
            },
            "required": [
              "release",
              "dataset",
              "coverage",
              "provenance",
              "quality",
              "sources",
              "bulk"
            ],
            "additionalProperties": false
          },
          "pagination": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/Pagination"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "applied_filters",
          "units",
          "coverage",
          "definition_status",
          "warnings",
          "uncollected_reference_dates_in_range",
          "sources",
          "links",
          "pagination"
        ],
        "additionalProperties": false
      },
      "Observation": {
        "type": "object",
        "properties": {
          "dataset_id": {
            "const": "population"
          },
          "municipality_code": {
            "const": "13208"
          },
          "area_id": {
            "type": "string"
          },
          "area_name": {
            "type": "string"
          },
          "geography_level": {
            "enum": [
              "municipality",
              "town_area"
            ]
          },
          "reference_date": {
            "type": "string",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
          },
          "population": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0
          },
          "male": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0
          },
          "female": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0
          },
          "households": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0
          },
          "density": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 0
          },
          "observation_status": {
            "enum": [
              "reported",
              "missing"
            ]
          },
          "missing_reason": {
            "enum": [
              null,
              "source_blank",
              "not_in_source"
            ]
          },
          "provenance_id": {
            "type": "string"
          },
          "data_revision": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          },
          "area_km2": {
            "type": "number",
            "exclusiveMinimum": 0
          },
          "boundary_version": {
            "type": "string"
          },
          "boundary_provenance_id": {
            "type": "string"
          },
          "calculation_method": {
            "type": "string"
          }
        },
        "required": [
          "dataset_id",
          "municipality_code",
          "area_id",
          "area_name",
          "geography_level",
          "reference_date",
          "observation_status",
          "missing_reason",
          "provenance_id",
          "data_revision"
        ],
        "additionalProperties": false,
        "anyOf": [
          {
            "required": [
              "population"
            ]
          },
          {
            "required": [
              "male"
            ]
          },
          {
            "required": [
              "female"
            ]
          },
          {
            "required": [
              "households"
            ]
          },
          {
            "required": [
              "density"
            ]
          }
        ],
        "allOf": [
          {
            "if": {
              "properties": {
                "observation_status": {
                  "const": "missing"
                }
              }
            },
            "then": {
              "properties": {
                "population": {
                  "type": "null"
                },
                "male": {
                  "type": "null"
                },
                "female": {
                  "type": "null"
                },
                "households": {
                  "type": "null"
                },
                "density": {
                  "type": "null"
                },
                "missing_reason": {
                  "enum": [
                    "source_blank",
                    "not_in_source"
                  ]
                }
              }
            },
            "else": {
              "properties": {
                "population": {
                  "type": "integer",
                  "minimum": 0
                },
                "male": {
                  "type": "integer",
                  "minimum": 0
                },
                "female": {
                  "type": "integer",
                  "minimum": 0
                },
                "households": {
                  "type": "integer",
                  "minimum": 0
                },
                "density": {
                  "type": "number",
                  "minimum": 0
                },
                "missing_reason": {
                  "type": "null"
                }
              }
            }
          },
          {
            "if": {
              "required": [
                "density"
              ]
            },
            "then": {
              "required": [
                "area_km2",
                "boundary_version",
                "boundary_provenance_id",
                "calculation_method"
              ],
              "properties": {
                "geography_level": {
                  "const": "town_area"
                }
              }
            }
          }
        ]
      },
      "DatasetSummary": {
        "type": "object",
        "properties": {
          "dataset_id": {
            "enum": [
              "population",
              "town_boundaries"
            ]
          },
          "title": {
            "type": "string"
          },
          "api_url": {
            "type": "string"
          }
        },
        "required": [
          "dataset_id",
          "title",
          "api_url"
        ],
        "additionalProperties": false
      },
      "Dataset": {
        "type": "object",
        "properties": {
          "dataset_id": {
            "enum": [
              "population",
              "town_boundaries"
            ]
          },
          "title": {
            "type": "string"
          },
          "data_revision": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          }
        },
        "required": [
          "dataset_id",
          "title",
          "data_revision"
        ],
        "additionalProperties": true
      },
      "Area": {
        "type": "object",
        "properties": {
          "area_id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "geography_level": {
            "enum": [
              "municipality",
              "town_area"
            ]
          },
          "municipality_code": {
            "const": "13208"
          },
          "aliases": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "parent_area_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "source_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "source_code_system": {
            "type": [
              "string",
              "null"
            ]
          },
          "valid_from": {
            "type": [
              "string",
              "null"
            ]
          },
          "valid_to": {
            "type": [
              "string",
              "null"
            ]
          },
          "validity_status": {
            "type": "string"
          },
          "data_revision": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          }
        },
        "required": [
          "area_id",
          "name",
          "geography_level",
          "municipality_code",
          "aliases",
          "parent_area_id",
          "source_code",
          "source_code_system",
          "valid_from",
          "valid_to",
          "validity_status",
          "data_revision"
        ],
        "additionalProperties": false
      },
      "Boundary": {
        "type": "object",
        "properties": {
          "area_id": {
            "type": "string"
          },
          "area_name": {
            "type": "string"
          },
          "boundary_version": {
            "type": "string"
          },
          "area_km2": {
            "type": "number",
            "exclusiveMinimum": 0
          },
          "representative_point": {
            "type": "array",
            "minItems": 2,
            "maxItems": 2,
            "items": {
              "type": "number"
            }
          },
          "bbox": {
            "type": "array",
            "minItems": 4,
            "maxItems": 4,
            "items": {
              "type": "number"
            }
          },
          "source_code": {
            "type": "string"
          },
          "provenance_id": {
            "type": "string"
          },
          "data_revision": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          }
        },
        "required": [
          "area_id",
          "area_name",
          "boundary_version",
          "area_km2",
          "representative_point",
          "bbox",
          "source_code",
          "provenance_id",
          "data_revision"
        ],
        "additionalProperties": false
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "details": {
                "type": "object"
              }
            },
            "required": [
              "code",
              "message",
              "details"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "error"
        ],
        "additionalProperties": false
      },
      "DatasetsResponse": {
        "type": "object",
        "properties": {
          "api_version": {
            "const": "1.0.0"
          },
          "contract_version": {
            "type": "string"
          },
          "data_revision": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          },
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DatasetSummary"
            }
          },
          "meta": {
            "$ref": "#/components/schemas/Metadata"
          }
        },
        "required": [
          "api_version",
          "contract_version",
          "data_revision",
          "data",
          "meta"
        ],
        "additionalProperties": false
      },
      "DatasetResponse": {
        "type": "object",
        "properties": {
          "api_version": {
            "const": "1.0.0"
          },
          "contract_version": {
            "type": "string"
          },
          "data_revision": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          },
          "data": {
            "$ref": "#/components/schemas/Dataset"
          },
          "meta": {
            "$ref": "#/components/schemas/Metadata"
          }
        },
        "required": [
          "api_version",
          "contract_version",
          "data_revision",
          "data",
          "meta"
        ],
        "additionalProperties": false
      },
      "AreasResponse": {
        "type": "object",
        "properties": {
          "api_version": {
            "const": "1.0.0"
          },
          "contract_version": {
            "type": "string"
          },
          "data_revision": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          },
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Area"
            }
          },
          "meta": {
            "$ref": "#/components/schemas/Metadata"
          }
        },
        "required": [
          "api_version",
          "contract_version",
          "data_revision",
          "data",
          "meta"
        ],
        "additionalProperties": false
      },
      "ObservationsResponse": {
        "type": "object",
        "properties": {
          "api_version": {
            "const": "1.0.0"
          },
          "contract_version": {
            "type": "string"
          },
          "data_revision": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          },
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Observation"
            }
          },
          "meta": {
            "$ref": "#/components/schemas/Metadata"
          }
        },
        "required": [
          "api_version",
          "contract_version",
          "data_revision",
          "data",
          "meta"
        ],
        "additionalProperties": false
      },
      "BoundaryResponse": {
        "type": "object",
        "properties": {
          "api_version": {
            "const": "1.0.0"
          },
          "contract_version": {
            "type": "string"
          },
          "data_revision": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          },
          "data": {
            "$ref": "#/components/schemas/Boundary"
          },
          "meta": {
            "$ref": "#/components/schemas/Metadata"
          }
        },
        "required": [
          "api_version",
          "contract_version",
          "data_revision",
          "data",
          "meta"
        ],
        "additionalProperties": false
      }
    }
  }
}
