{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://sentier-dev.github.io/sentier-bafu/schema/finding.schema.json",
  "title": "Finding record, version 2",
  "description": "One file per finding: community/findings/<number // 1000>/F<number>.json. A record holds what was observed and the dated evidence of what happened to it. It holds no status: the status is computed from the evidence (the first that applies of closed, fixed_in, answer, sent, repeated with result reproduced; otherwise the finding is filed). `python3 scripts/community.py check` validates every record against this schema and adds the rules a schema cannot express: the file path, the identity rule (above F47 the id is F<issue>), real calendar dates in order, known release ids, a second measurement by someone other than the reporter, Markdown without images, headings or relative links, and references between records.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema", "id", "issue", "title", "kind", "datasets", "scope", "releases", "observation",
    "exposure", "method", "reported", "repeated", "sent", "answer", "fixed_in", "closed",
    "related", "threads", "next", "retained", "notes"
  ],
  "properties": {
    "schema": {"const": 2, "description": "Version of this record format."},
    "id": {"$ref": "#/$defs/finding_id", "description": "Never changes. From F48 on it is F followed by the issue number; F1 to F32 follow an older numbering."},
    "issue": {"type": ["integer", "null"], "minimum": 1, "description": "The issue in this repository where the finding is discussed, or null."},
    "title": {"$ref": "#/$defs/line", "description": "What was observed, in one line. No status, no remedy."},
    "kind": {"enum": ["defect", "question", "difference"], "description": "defect: something in the data looks wrong. question: a question to the provider about what the data means. difference: a difference in method, scope or convention."},
    "datasets": {
      "type": "array",
      "items": {"$ref": "#/$defs/dataset"},
      "description": "Every dataset the finding is about, by code. Empty when the finding is not about listed datasets; then `scope` says what it is about."
    },
    "scope": {"$ref": "#/$defs/optional_line", "description": "Free text for what the finding concerns beyond the listed datasets: a group of datasets, a flow, a workbook, a file of a release."},
    "releases": {
      "type": "array",
      "items": {"$ref": "#/$defs/release_id"},
      "uniqueItems": true,
      "description": "Provider releases in which it was observed, as ids from the list in site/config.json."
    },
    "observation": {"$ref": "#/$defs/required_text", "description": "What the data says, what it was compared with, and the question to the provider if there is one. Markdown. Names and single values only, never text from a report."},
    "exposure": {"$ref": "#/$defs/text", "description": "What it affects, if known: scores, consumers. Markdown; may be empty."},
    "method": {"$ref": "#/$defs/text", "description": "How it was measured and on which files, and what was not measured. Markdown."},
    "reported": {
      "type": "object",
      "additionalProperties": false,
      "required": ["by", "date", "url"],
      "properties": {
        "by": {"$ref": "#/$defs/optional_person", "description": "Who reported it: a GitHub login or a name."},
        "date": {"$ref": "#/$defs/optional_date"},
        "url": {"$ref": "#/$defs/url", "description": "The issue or thread in which it was reported."}
      },
      "description": "Who reported the finding, when and where. Null values are accepted only on the ids that predate this format."
    },
    "repeated": {
      "type": ["object", "null"],
      "additionalProperties": false,
      "required": ["by", "date", "url", "result"],
      "properties": {
        "by": {"$ref": "#/$defs/person", "description": "The second person: a GitHub login or a name. Never the reporter."},
        "date": {"$ref": "#/$defs/date"},
        "url": {"$ref": "#/$defs/url", "description": "Where the second person says what they got."},
        "result": {"enum": ["reproduced", "not-reproduced"]}
      },
      "description": "The second measurement, by a named second person."
    },
    "sent": {
      "type": ["object", "null"],
      "additionalProperties": false,
      "required": ["batch", "date", "url"],
      "properties": {
        "batch": {"type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]*$", "description": "Findings reported together share a batch id and its date."},
        "date": {"$ref": "#/$defs/date"},
        "url": {"$ref": "#/$defs/url"}
      },
      "description": "When the finding was reported to the provider."
    },
    "answer": {
      "type": ["object", "null"],
      "additionalProperties": false,
      "required": ["date", "outcome", "summary", "url"],
      "properties": {
        "date": {"$ref": "#/$defs/date"},
        "outcome": {"enum": ["confirmed", "declined", "explained"]},
        "summary": {"$ref": "#/$defs/required_text", "description": "The provider's answer in our own words, attributed to the provider. No person's name, no quotation from correspondence."},
        "url": {"$ref": "#/$defs/url", "description": "A public place where the answer is summarised."}
      },
      "description": "The provider's answer. An answer does not correct anything; only `fixed_in` does."
    },
    "fixed_in": {
      "type": ["object", "null"],
      "additionalProperties": false,
      "required": ["release", "date", "url"],
      "properties": {
        "release": {"$ref": "#/$defs/release_id"},
        "detail": {"$ref": "#/$defs/text", "description": "The file of that release that carries the correction, when a release has more than one."},
        "date": {"$ref": "#/$defs/date", "description": "When the correction was checked in that release."},
        "url": {"$ref": "#/$defs/url", "description": "The public evidence of that check."}
      },
      "description": "The provider release that contains the correction, once it has been checked there."
    },
    "closed": {
      "type": ["object", "null"],
      "additionalProperties": false,
      "required": ["as", "date", "reason", "url"],
      "properties": {
        "as": {"enum": ["withdrawn", "not-a-defect"]},
        "date": {"$ref": "#/$defs/optional_date"},
        "reason": {"$ref": "#/$defs/required_text"},
        "url": {"$ref": "#/$defs/url"}
      },
      "description": "Leaves the path: withdrawn (it did not hold when measured again) or not-a-defect (kept for information)."
    },
    "related": {
      "type": "array",
      "items": {"$ref": "#/$defs/finding_id"},
      "uniqueItems": true,
      "description": "Other findings this one refers to. One direction is enough; the site shows both."
    },
    "threads": {
      "type": "array",
      "items": {"$ref": "#/$defs/url"},
      "uniqueItems": true,
      "description": "Discussion elsewhere: a thread in another project, or a second issue here."
    },
    "next": {
      "type": ["object", "null"],
      "additionalProperties": false,
      "required": ["action", "role"],
      "properties": {
        "action": {"$ref": "#/$defs/required_text"},
        "role": {"enum": ["data user", "partner", "reviewer", "maintainer", "flow curator", "importer maintainer"]}
      },
      "description": "The next step and who takes it, for maintainers."
    },
    "retained": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["kind", "text", "evidence_url"],
        "properties": {
          "kind": {"enum": ["ask", "objection", "earlier-interpretation"]},
          "text": {"$ref": "#/$defs/required_text"},
          "evidence_url": {"$ref": "#/$defs/url"}
        }
      },
      "description": "Requests to other projects, objections and earlier readings that stay on record."
    },
    "notes": {"$ref": "#/$defs/text", "description": "Longer detail. Markdown; may be empty."}
  },
  "$defs": {
    "raw_html": {"type": "string", "pattern": "<[A-Za-z/!]", "description": "What no text of a record may hold: the site renders records into pages."},
    "finding_id": {"type": "string", "pattern": "^F[1-9][0-9]*$"},
    "release_id": {"type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]*$", "description": "The id of a provider release, as site/config.json lists it: the check of the records refuses an id the list does not have."},
    "date": {"type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"},
    "optional_date": {"type": ["string", "null"], "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"},
    "url": {"type": "string", "pattern": "^https://[^\\s()<>\"|]+$"},
    "text": {"type": "string", "not": {"$ref": "#/$defs/raw_html"}, "description": "Markdown, never raw HTML."},
    "required_text": {"type": "string", "pattern": "\\S", "not": {"$ref": "#/$defs/raw_html"}},
    "line": {
      "type": "string",
      "pattern": "^(?=.*\\S)[^|\\r\\n\\u000b\\u000c\\u001c-\\u001e\\u0085\\u2028\\u2029]+$",
      "not": {"$ref": "#/$defs/raw_html"},
      "description": "One line without a table bar: it is shown in tables."
    },
    "optional_line": {
      "type": "string",
      "pattern": "^[^|\\r\\n\\u000b\\u000c\\u001c-\\u001e\\u0085\\u2028\\u2029]*$",
      "not": {"$ref": "#/$defs/raw_html"}
    },
    "person": {
      "type": "string",
      "pattern": "^(?=.*\\S)[^|\\r\\n\\u000b\\u000c\\u001c-\\u001e\\u0085\\u2028\\u2029]+$",
      "not": {"$ref": "#/$defs/raw_html"}
    },
    "optional_person": {
      "type": ["string", "null"],
      "pattern": "^(?=.*\\S)[^|\\r\\n\\u000b\\u000c\\u001c-\\u001e\\u0085\\u2028\\u2029]+$",
      "not": {"$ref": "#/$defs/raw_html"}
    },
    "dataset": {
      "type": "object",
      "additionalProperties": false,
      "required": ["code", "name", "location"],
      "properties": {
        "code": {"type": "integer", "minimum": 1, "description": "The dataset number in the provider's release."},
        "name": {"$ref": "#/$defs/line"},
        "location": {"$ref": "#/$defs/line"},
        "role": {"enum": ["subject", "affected", "named"], "description": "subject (the default): the observation is in this dataset. affected: a result of this dataset changes because it uses a subject dataset. named: named in the finding as a supplier or for comparison."}
      }
    }
  }
}
