{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "网站 Data 记录项目规范",
  "description": "普通 JSON 记录的项目约定，用于生成页面与 Schema.org JSON-LD；不替代 Schema.org 语义检查。",
  "type": "object",
  "required": ["schemaVersion", "identifier", "name", "description", "originalUrl", "dataUrl", "webpageId", "entityId", "pageType", "entityType", "mainEntity", "sameAs"],
  "additionalProperties": false,
  "properties": {
    "schemaVersion": {"const": "2.0"},
    "identifier": {
      "type": "object", "required": ["propertyID", "value"], "additionalProperties": false,
      "properties": {"propertyID": {"type": "string", "minLength": 1}, "value": {"type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9_-]*$"}}
    },
    "name": {"type": "string", "minLength": 1},
    "description": {"type": "string", "minLength": 1},
    "entityName": {"type": "string", "minLength": 1},
    "entityDescription": {"type": "string", "minLength": 1},
    "originalUrl": {"$ref": "#/$defs/pageUrl"},
    "dataUrl": {"$ref": "#/$defs/pageUrl"},
    "canonicalUrl": {"$ref": "#/$defs/pageUrl"},
    "webpageId": {"$ref": "#/$defs/idUri"},
    "entityId": {"$ref": "#/$defs/idUri"},
    "pageType": {"enum": ["WebPage", "AboutPage", "CollectionPage"]},
    "entityType": {"type": "array", "minItems": 1, "uniqueItems": true, "items": {"type": "string", "minLength": 1}},
    "mainEntity": {
      "type": "object", "required": ["@id"], "additionalProperties": false,
      "properties": {"@id": {"$ref": "#/$defs/idUri"}}
    },
    "sameAs": {"type": "array", "uniqueItems": true, "items": {"type": "string", "format": "uri", "pattern": "^https?://"}},
    "alternateName": {"type": "array", "uniqueItems": true, "items": {"type": "string", "minLength": 1}},
    "category": {"type": "string", "minLength": 1},
    "inLanguage": {"type": "string", "minLength": 2},
    "provider": {"anyOf": [{"$ref": "#/$defs/organizationReference"}, {"type": "null"}]},
    "publisher": {"$ref": "#/$defs/organizationReference"},
    "sourceUrls": {"type": "array", "uniqueItems": true, "items": {"type": "string", "format": "uri", "pattern": "^https?://"}},
    "dateModified": {"$ref": "#/$defs/dateValue"},
    "datePublished": {"$ref": "#/$defs/dateValue"},
    "schemaUpdatedAt": {"$ref": "#/$defs/dateValue"},
    "author": {
      "type": "object", "required": ["@type", "name"], "additionalProperties": false,
      "properties": {"@type": {"enum": ["Person", "Organization"]}, "@id": {"$ref": "#/$defs/idUri"}, "name": {"type": "string", "minLength": 1}, "url": {"$ref": "#/$defs/pageUrl"}}
    },
    "itemListElement": {
      "type": "array", "items": {
        "type": "object", "required": ["position", "name", "url"], "additionalProperties": false,
        "properties": {"position": {"type": "integer", "minimum": 1}, "entityId": {"$ref": "#/$defs/idUri"}, "name": {"type": "string", "minLength": 1}, "url": {"$ref": "#/$defs/pageUrl"}}
      }
    },
    "numberOfItems": {"type": "integer", "minimum": 0},
    "aboutEntities": {
      "type": "array", "items": {
        "type": "object", "required": ["entityId", "entityType", "name"], "additionalProperties": false,
        "properties": {"entityId": {"$ref": "#/$defs/idUri"}, "entityType": {"type": "string", "minLength": 1}, "name": {"type": "string", "minLength": 1}}
      }
    },
    "type": {"type": "array", "items": {"type": "string", "minLength": 1}, "description": "旧记录兼容字段；生成器不得以此字段替代 pageType 与 entityType。"},
    "priority": {"type": "integer", "minimum": 0, "description": "内部处理顺序；不代表搜索排名。"}
  },
  "allOf": [
    {
      "if": {"properties": {"entityType": {"contains": {"const": "Service"}}}, "required": ["entityType"]},
      "then": {"required": ["provider"], "properties": {"provider": {"$ref": "#/$defs/organizationReference"}}}
    },
    {
      "if": {"properties": {"pageType": {"const": "AboutPage"}}, "required": ["pageType"]},
      "then": {"required": ["entityName"], "properties": {"entityType": {"contains": {"const": "Organization"}}, "provider": {"type": "null"}}}
    }
  ],
  "$defs": {
    "pageUrl": {"type": "string", "format": "uri", "pattern": "^https://[^?#]+$"},
    "idUri": {"type": "string", "format": "uri", "pattern": "^https://"},
    "dateValue": {"anyOf": [{"type": "string", "format": "date"}, {"type": "string", "format": "date-time"}]},
    "organizationReference": {
      "type": "object", "required": ["entityId", "name"], "additionalProperties": false,
      "properties": {"identifier": {"type": "string", "minLength": 1}, "entityId": {"$ref": "#/$defs/idUri"}, "name": {"type": "string", "minLength": 1}}
    }
  }
}
