{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://answerkb.com/schema/answer.schema.json",
  "title": "Knowledge base answer twin",
  "description": "Fixed schema for the answer.json sibling of each question page.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "id",
    "question",
    "common_queries",
    "short_answer",
    "long_answer",
    "steps",
    "grade",
    "subject",
    "category",
    "tags",
    "sources",
    "updated",
    "last_verified",
    "canonical_url",
    "related"
  ],
  "properties": {
    "id": {
      "type": "string",
      "minLength": 1,
      "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$",
      "description": "Stable lowercase kebab-case identifier."
    },
    "question": {
      "type": "string",
      "minLength": 1
    },
    "short_answer": {
      "type": "string",
      "minLength": 1,
      "description": "One or two sentences; this is also the first paragraph of the page."
    },
    "long_answer": {
      "type": "string",
      "minLength": 1
    },
    "steps": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "text"
        ],
        "properties": {
          "title": {
            "type": "string",
            "minLength": 1
          },
          "text": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    },
    "grade": {
      "type": [
        "string",
        "null"
      ],
      "enum": [
        "k",
        "1",
        "2",
        "3",
        "4",
        "5",
        "6",
        "7",
        "8",
        "9",
        "10",
        "11",
        "12",
        "college",
        null
      ]
    },
    "subject": {
      "type": [
        "string",
        "null"
      ],
      "minLength": 1
    },
    "category": {
      "type": [
        "string",
        "null"
      ],
      "minLength": 1
    },
    "tags": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      }
    },
    "sources": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "title",
          "url"
        ],
        "properties": {
          "title": {
            "type": "string",
            "minLength": 1
          },
          "url": {
            "type": "string",
            "format": "uri"
          }
        }
      }
    },
    "updated": {
      "type": "string",
      "format": "date"
    },
    "last_verified": {
      "type": "string",
      "format": "date",
      "description": "ISO date the answer was last checked against its sources or computed from exact relationships."
    },
    "canonical_url": {
      "type": "string",
      "format": "uri"
    },
    "related": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "easier",
        "harder",
        "siblings"
      ],
      "properties": {
        "easier": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/relatedLink"
          }
        },
        "harder": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/relatedLink"
          }
        },
        "siblings": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/relatedLink"
          }
        }
      }
    },
    "common_queries": {
      "type": "array",
      "description": "Alternate phrasings of the question, as people ask agents. Does not include the canonical question itself.",
      "items": {
        "type": "string",
        "minLength": 1
      }
    }
  },
  "$defs": {
    "relatedLink": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "question",
        "path",
        "canonical_url"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "question": {
          "type": "string",
          "minLength": 1
        },
        "path": {
          "type": "string",
          "minLength": 1,
          "pattern": "^/"
        },
        "canonical_url": {
          "type": "string",
          "format": "uri"
        }
      }
    }
  }
}
