{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "subject-feeds/contract/feed.schema.json",
  "title": "Subject feed (published contract, version 1)",
  "description": "A JSON Feed 1.1 document with one extension object, _subject_feed, at feed level and on every item. Consumers must ignore members they do not recognise.",
  "type": "object",
  "required": ["version", "title", "language", "items", "_subject_feed"],
  "properties": {
    "version": { "const": "https://jsonfeed.org/version/1.1" },
    "title": { "type": "string", "minLength": 1 },
    "description": { "type": "string" },
    "language": { "type": "string", "minLength": 2 },
    "feed_url": { "type": "string", "pattern": "^https://" },
    "_subject_feed": {
      "type": "object",
      "required": ["contract_version", "subject", "updated", "categories"],
      "properties": {
        "contract_version": {
          "description": "MAJOR.MINOR. A minor bump only adds optional members. A major bump is published at a new path.",
          "type": "string",
          "pattern": "^1\\.[0-9]+$"
        },
        "subject": { "type": "string", "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$" },
        "updated": { "description": "When the most recent publication, change or retraction in this feed happened (UTC).", "type": "string", "format": "date-time" },
        "categories": {
          "description": "Every category an item may carry, with its display label.",
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": ["key", "label"],
            "properties": {
              "key": { "type": "string", "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$" },
              "label": { "type": "string", "minLength": 1 }
            }
          }
        }
      }
    },
    "items": {
      "description": "Newest event first.",
      "type": "array",
      "items": { "$ref": "#/$defs/item" }
    }
  },
  "$defs": {
    "item": {
      "type": "object",
      "required": ["id", "date_published", "_subject_feed"],
      "properties": {
        "id": {
          "description": "'<subject>/<slug>'. Permanent.",
          "type": "string",
          "pattern": "^[a-z0-9-]+/[0-9]{4}-[0-9]{2}-[0-9]{2}-[a-z0-9-]+$"
        },
        "title": { "type": "string" },
        "summary": { "type": "string" },
        "content_text": { "description": "The summary text, or the retraction notice for a retracted item. Present because JSON Feed requires content.", "type": "string" },
        "date_published": { "type": "string", "format": "date-time" },
        "date_modified": { "type": "string", "format": "date-time" },
        "tags": { "type": "array", "items": { "type": "string" } },
        "_subject_feed": {
          "type": "object",
          "required": ["slug", "status", "event_date", "category", "origin", "review"],
          "properties": {
            "slug": { "description": "The id without the subject prefix. Consumers build their own page URL from it.", "type": "string" },
            "status": { "enum": ["published", "retracted"] },
            "retraction_note": { "type": "string" },
            "event_date": { "type": "string", "format": "date" },
            "date_label": { "type": "string" },
            "category": { "type": "string" },
            "body_markdown": { "description": "CommonMark without raw HTML. The consumer renders it.", "type": "string" },
            "sources": {
              "type": "array",
              "items": {
                "type": "object",
                "required": ["label", "url"],
                "properties": {
                  "label": { "type": "string" },
                  "url": { "type": "string", "pattern": "^https://" }
                }
              }
            },
            "origin": { "enum": ["seed", "pipeline", "manual"] },
            "review": { "enum": ["human", "automated"] }
          }
        }
      },
      "allOf": [
        {
          "if": { "properties": { "_subject_feed": { "properties": { "status": { "const": "retracted" } } } } },
          "then": {
            "description": "A retracted item carries no content.",
            "properties": { "_subject_feed": { "required": ["retraction_note"], "not": { "anyOf": [ { "required": ["sources"] }, { "required": ["body_markdown"] } ] } } },
            "required": ["title", "content_text"],
            "not": { "required": ["summary"] }
          },
          "else": {
            "required": ["title", "summary", "content_text"],
            "properties": { "_subject_feed": { "required": ["sources"] } }
          }
        }
      ]
    }
  }
}
