{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/statisticsoftheworld-com/json-schema/statisticsoftheworld-com-source-comparison-bundle-schema.json",
  "title": "SourceComparisonBundle",
  "x-generated": "2026-11-26",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/statisticsoftheworld-com-openapi.yml#/components/schemas/SourceComparisonBundle",
  "type": "object",
  "required": [
    "schema_version",
    "processing_version",
    "selection",
    "concept",
    "country",
    "comparisonYear",
    "readings",
    "difference",
    "history",
    "provenance",
    "revisions",
    "diagnostics"
  ],
  "properties": {
    "schema_version": {
      "const": 1
    },
    "processing_version": {
      "const": "source-comparison-v1"
    },
    "selection": {
      "type": "object",
      "required": [
        "concept",
        "country",
        "year",
        "as_of",
        "revision"
      ],
      "properties": {
        "concept": {
          "type": "string",
          "enum": [
            "gdp",
            "gdp-per-capita",
            "gdp-growth",
            "gdp-ppp",
            "gdp-per-capita-ppp",
            "inflation",
            "unemployment",
            "government-debt",
            "current-account",
            "investment"
          ]
        },
        "country": {
          "type": "string",
          "enum": [
            "ARG",
            "AUS",
            "BRA",
            "CAN",
            "CHN",
            "FRA",
            "DEU",
            "IND",
            "IDN",
            "ITA",
            "JPN",
            "KOR",
            "MEX",
            "NGA",
            "SAU",
            "ZAF",
            "ESP",
            "TUR",
            "GBR",
            "USA"
          ]
        },
        "year": {
          "oneOf": [
            {
              "type": "integer",
              "minimum": 1960,
              "maximum": 2100
            },
            {
              "const": "common"
            }
          ]
        },
        "as_of": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "revision": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^(0|[1-9]\\d{0,18})$"
        }
      }
    },
    "concept": {
      "$ref": "#/$defs/SourceComparisonConcept"
    },
    "country": {
      "$ref": "#/$defs/SourceComparisonCountry"
    },
    "comparisonYear": {
      "type": [
        "integer",
        "null"
      ]
    },
    "readings": {
      "type": "array",
      "minItems": 2,
      "maxItems": 2,
      "items": {
        "$ref": "#/$defs/SourceComparisonReading"
      }
    },
    "difference": {
      "type": "object",
      "required": [
        "absolute",
        "relativePercent",
        "unit",
        "label",
        "status",
        "reason"
      ],
      "properties": {
        "absolute": {
          "type": [
            "number",
            "null"
          ],
          "description": "IMF minus World Bank, withheld for incompatible scope/metadata or missing readings. Rate differences are percentage points."
        },
        "relativePercent": {
          "type": [
            "number",
            "null"
          ],
          "description": "For level series only, absolute divided by the positive World Bank reading times 100. Never a relative-percent comparison of rates."
        },
        "unit": {
          "type": "string"
        },
        "label": {
          "const": "IMF minus World Bank"
        },
        "status": {
          "type": "string",
          "enum": [
            "comparable",
            "methodology_sensitive",
            "not_comparable",
            "missing"
          ]
        },
        "reason": {
          "type": "string"
        }
      }
    },
    "history": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "year",
          "imf",
          "worldBank",
          "imfRaw",
          "worldBankRaw",
          "difference"
        ],
        "properties": {
          "year": {
            "type": "integer"
          },
          "imf": {
            "type": [
              "number",
              "null"
            ]
          },
          "worldBank": {
            "type": [
              "number",
              "null"
            ]
          },
          "imfRaw": {
            "type": [
              "number",
              "null"
            ]
          },
          "worldBankRaw": {
            "type": [
              "number",
              "null"
            ]
          },
          "difference": {
            "type": [
              "number",
              "null"
            ]
          }
        }
      }
    },
    "provenance": {
      "type": "object",
      "required": [
        "asOf",
        "coverageStart",
        "timeBasis",
        "sourceAvailability",
        "revision"
      ],
      "properties": {
        "asOf": {
          "type": "string",
          "format": "date-time",
          "description": "Exact SOTW transaction-final recording cutoff, including submillisecond precision. Preserve together with revision for replay."
        },
        "coverageStart": {
          "type": "string",
          "format": "date-time"
        },
        "timeBasis": {
          "const": "sotw_recorded_at"
        },
        "sourceAvailability": {
          "const": "not_established"
        },
        "revision": {
          "type": "string",
          "pattern": "^(0|[1-9]\\d{0,18})$",
          "description": "Decimal archive transaction watermark, at most 9223372036854775807. Zero identifies a genuinely empty baseline."
        }
      }
    },
    "revisions": {
      "type": "array",
      "maxItems": 2000,
      "description": "Selected-reference-year observation events and source metadata events; the latest 2,000 transaction-final events in the selected scope at most. Baseline is initial stored state, not publisher revision history.",
      "items": {
        "type": "object",
        "required": [
          "indicatorId",
          "referenceYear",
          "recordedAt",
          "operation",
          "value",
          "previousValue",
          "rawValue",
          "previousRawValue",
          "eventId",
          "kind"
        ],
        "properties": {
          "indicatorId": {
            "type": "string"
          },
          "referenceYear": {
            "type": [
              "integer",
              "null"
            ]
          },
          "recordedAt": {
            "type": "string",
            "format": "date-time"
          },
          "operation": {
            "type": "string",
            "enum": [
              "baseline",
              "insert",
              "update",
              "delete"
            ]
          },
          "value": {
            "type": "null",
            "description": "Historical event normalization is not established."
          },
          "previousValue": {
            "type": "null"
          },
          "rawValue": {
            "type": [
              "number",
              "null"
            ]
          },
          "previousRawValue": {
            "type": [
              "number",
              "null"
            ]
          },
          "eventId": {
            "type": "string",
            "pattern": "^[1-9]\\d{0,18}$"
          },
          "kind": {
            "type": "string",
            "enum": [
              "observation",
              "metadata"
            ]
          }
        }
      }
    },
    "diagnostics": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Coverage limits, review requirements and publisher-vintage limitations."
    }
  },
  "$defs": {
    "SourceComparisonConcept": {
      "type": "object",
      "required": [
        "id",
        "label",
        "unit",
        "format",
        "comparability",
        "notes",
        "imfId",
        "wbId"
      ],
      "properties": {
        "id": {
          "type": "string",
          "enum": [
            "gdp",
            "gdp-per-capita",
            "gdp-growth",
            "gdp-ppp",
            "gdp-per-capita-ppp",
            "inflation",
            "unemployment",
            "government-debt",
            "current-account",
            "investment"
          ]
        },
        "label": {
          "type": "string"
        },
        "unit": {
          "type": "string"
        },
        "format": {
          "type": "string",
          "enum": [
            "currency",
            "percent",
            "number"
          ]
        },
        "comparability": {
          "type": "string",
          "enum": [
            "aligned",
            "definition_mismatch",
            "methodology_sensitive"
          ]
        },
        "notes": {
          "type": "string"
        },
        "imfId": {
          "type": "string"
        },
        "wbId": {
          "type": "string"
        }
      }
    },
    "SourceComparisonCountry": {
      "type": "object",
      "required": [
        "id",
        "name"
      ],
      "properties": {
        "id": {
          "type": "string",
          "enum": [
            "ARG",
            "AUS",
            "BRA",
            "CAN",
            "CHN",
            "FRA",
            "DEU",
            "IND",
            "IDN",
            "ITA",
            "JPN",
            "KOR",
            "MEX",
            "NGA",
            "SAU",
            "ZAF",
            "ESP",
            "TUR",
            "GBR",
            "USA"
          ]
        },
        "name": {
          "type": "string"
        }
      }
    },
    "SourceComparisonReading": {
      "type": "object",
      "required": [
        "indicatorId",
        "source",
        "sourceUrl",
        "unit",
        "value",
        "rawValue",
        "normalizationFactor",
        "normalizationStatus",
        "referenceYear",
        "storedSource",
        "archivedSourceName",
        "archivedSourceUrl",
        "definitionOrigin",
        "unitOrigin",
        "catalogMetadataRetrievedAt",
        "availability",
        "observationStatus",
        "publisherVintage",
        "sourcePublishedAt",
        "sotwRowUpdatedAt",
        "definition",
        "methodology",
        "definitionUnit",
        "metadataUpdatedAt",
        "license",
        "attribution",
        "sourceCaptureSha256",
        "capturedAt",
        "processingVersion"
      ],
      "properties": {
        "indicatorId": {
          "type": "string"
        },
        "source": {
          "type": "string",
          "enum": [
            "IMF",
            "World Bank"
          ]
        },
        "sourceUrl": {
          "type": "string",
          "format": "uri"
        },
        "unit": {
          "type": "string"
        },
        "value": {
          "type": [
            "number",
            "null"
          ],
          "description": "Normalized value only for reviewed compatible units and stored source attribution. Null can mean a missing reading or normalization withheld; inspect rawValue and normalizationStatus."
        },
        "rawValue": {
          "type": [
            "number",
            "null"
          ],
          "description": "Native stored reading, before canonical scale normalization. It can remain numeric when value is null because review is required."
        },
        "normalizationFactor": {
          "type": [
            "number",
            "null"
          ]
        },
        "normalizationStatus": {
          "type": "string",
          "enum": [
            "reviewed",
            "requires_review"
          ]
        },
        "referenceYear": {
          "type": [
            "integer",
            "null"
          ]
        },
        "storedSource": {
          "type": [
            "string",
            "null"
          ]
        },
        "archivedSourceName": {
          "type": [
            "string",
            "null"
          ]
        },
        "archivedSourceUrl": {
          "type": [
            "string",
            "null"
          ]
        },
        "definitionOrigin": {
          "type": "string",
          "enum": [
            "archived",
            "reviewed_catalog"
          ]
        },
        "unitOrigin": {
          "type": "string",
          "enum": [
            "archived",
            "reviewed_catalog"
          ]
        },
        "catalogMetadataRetrievedAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "availability": {
          "type": "string",
          "enum": [
            "available",
            "missing"
          ],
          "description": "Availability of the raw stored reading, separate from normalization review."
        },
        "observationStatus": {
          "const": "unknown"
        },
        "publisherVintage": {
          "type": "null"
        },
        "sourcePublishedAt": {
          "type": "null"
        },
        "sotwRowUpdatedAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "definition": {
          "type": [
            "string",
            "null"
          ]
        },
        "methodology": {
          "type": [
            "string",
            "null"
          ]
        },
        "definitionUnit": {
          "type": [
            "string",
            "null"
          ]
        },
        "metadataUpdatedAt": {
          "type": [
            "string",
            "null"
          ]
        },
        "license": {
          "type": "string"
        },
        "attribution": {
          "type": "string"
        },
        "sourceCaptureSha256": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^[a-f0-9]{64}$"
        },
        "capturedAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "processingVersion": {
          "type": [
            "string",
            "null"
          ],
          "description": "Stored ingestion processing version, separate from the comparison processing_version."
        }
      }
    }
  }
}