{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "국내 웹 접근성 자료 레코드",
  "description": "KWCAG, NIA 제작기법, KRDS 원문의 절 하나. 내부 주소는 같은 버전 경로의 절대 주소다.",
  "type": "object",
  "additionalProperties": false,
  "required": ["id", "title", "standard", "kind", "source", "location", "text", "parent", "children", "related", "provenance", "dataVersion"],
  "properties": {
    "id": { "type": "string", "pattern": "^(kwcag|nia|krds)-[a-z0-9._-]+$" },
    "title": { "type": "string", "minLength": 1 },
    "standard": { "enum": ["KWCAG", "NIA", "KRDS"] },
    "kind": { "enum": ["requirement", "recommendation", "informative"] },
    "source": { "type": "string", "pattern": "^https://" },
    "location": { "type": "string", "pattern": "^(L[0-9]+–L[0-9]+|P[0-9]+–P[0-9]+)$" },
    "text": { "type": "string" },
    "positions": { "type": "array", "minItems": 1, "items": { "type": "integer", "minimum": 0 } },
    "cases": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["title", "text", "advisory"],
        "properties": {
          "title": { "type": "string", "minLength": 1 },
          "text": { "type": "string" },
          "advisory": { "type": "boolean" }
        }
      }
    },
    "figures": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["caption", "src"],
        "properties": {
          "caption": { "anyOf": [{ "type": "string" }, { "type": "null" }] },
          "src": { "type": "string", "minLength": 1 }
        }
      }
    },
    "gaps": {
      "description": "원문 화면에는 있지만 text에 없는 내용의 자리. js-loaded-code는 페이지 스크립트가 src 파일을 불러와 채우는 코드 블록(원문 HTML에는 비어 있다)이다.",
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["kind", "src"],
        "properties": {
          "kind": { "enum": ["js-loaded-code"] },
          "src": { "type": "string", "pattern": "^https://" }
        }
      }
    },
    "criterion": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": { "type": "string", "pattern": "^[5-8]\\.[0-9]\\.[0-9]$" }
    },
    "parent": { "oneOf": [{ "type": "null" }, { "$ref": "#/$defs/ref" }] },
    "children": { "type": "array", "items": { "$ref": "#/$defs/ref" } },
    "related": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "title", "url", "basis"],
        "properties": {
          "id": { "type": "string", "pattern": "^krds-" },
          "title": { "type": "string", "minLength": 1 },
          "url": { "$ref": "#/$defs/url" },
          "basis": { "enum": ["mentions", "operator"] },
          "note": { "type": "string", "minLength": 1 }
        }
      }
    },
    "basicRules": { "$ref": "#" },
    "more": { "type": "array", "items": { "$ref": "#/$defs/ref" } },
    "review": {
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["reviewed"],
          "properties": { "reviewed": { "const": false } }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["reviewed", "reviewer", "date"],
          "properties": {
            "reviewed": { "const": true },
            "reviewer": { "type": "string", "minLength": 1 },
            "date": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" }
          }
        }
      ]
    },
    "provenance": {
      "type": "object",
      "additionalProperties": false,
      "required": ["retrievedAt", "sha256"],
      "properties": {
        "retrievedAt": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$" },
        "sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
        "commit": { "type": "string", "pattern": "^[0-9a-f]{40}$" }
      }
    },
    "dataVersion": { "type": "string", "pattern": "^v[1-9][0-9]*$" }
  },
  "$defs": {
    "url": {
      "description": "레코드 파일 기준 상대 경로(RFC 3986). 가리키는 레코드는 같은 criteria/ 폴더에 있다. 스킴·origin·앞의 /가 없다.",
      "type": "string",
      "pattern": "^(?!https?:)(?!/)(kwcag|nia|krds)-[a-z0-9._-]+\\.json$"
    },
    "ref": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "title", "url"],
      "properties": {
        "id": { "type": "string", "pattern": "^(kwcag|nia|krds)-[a-z0-9._-]+$" },
        "title": { "type": "string", "minLength": 1 },
        "url": { "$ref": "#/$defs/url" }
      }
    }
  }
}
