{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://universalpaper.org/research/schema/0/entry.schema.json",
  "title": "Universal Paper Research entry (up-research/entry/0)",
  "description": "One entry in Universal Paper Research: a note, an experiment, a reusable or a question. The same shape is used in the index and in each entry's entry.json, which adds detail and refs. Research is not part of the Universal Paper language. These formats may change or be withdrawn, and no agreement depends on them.",
  "type": "object",
  "required": [
    "format",
    "number",
    "kind",
    "slug",
    "title",
    "summary",
    "status",
    "topics",
    "language_change",
    "built_on",
    "published",
    "url"
  ],
  "additionalProperties": false,
  "properties": {
    "$schema": {
      "type": "string",
      "format": "uri"
    },
    "format": {
      "const": "up-research/entry/0"
    },
    "notice": {
      "type": "string",
      "minLength": 1
    },
    "number": {
      "type": "integer",
      "minimum": 1,
      "description": "Permanent. An entry keeps its number and its address after it is withdrawn."
    },
    "kind": {
      "enum": [
        "note",
        "experiment",
        "reusable",
        "question"
      ],
      "description": "note: An idea argued in full, with a worked example. experiment: Something that was run: a claim, a method, a result, and what it did not show. reusable: Files published to build on: manifests, traces, test vectors and schemas. question: An open problem, stated so that someone can settle it."
    },
    "slug": {
      "type": "string",
      "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$",
      "description": "The last part of the address: /research/<slug>/."
    },
    "title": {
      "type": "string",
      "minLength": 1
    },
    "summary": {
      "type": "string",
      "minLength": 1,
      "description": "One or two sentences. Backticks mark code."
    },
    "status": {
      "enum": [
        "open",
        "answered",
        "exploring",
        "prototype",
        "concluded",
        "withdrawn"
      ],
      "description": "open: A question with no answer yet. answered: A question that another entry settles. It links to the answer. exploring: Early work with an example you can check. prototype: Running code you can try. concluded: Finished. The result is recorded, and the limits say what was not tested. withdrawn: No longer pursued. The entry says why."
    },
    "topics": {
      "type": "array",
      "items": {
        "enum": [
          "queries",
          "fingerprints",
          "mandates",
          "fees",
          "pricing",
          "membership",
          "sealing",
          "lifecycle",
          "engines"
        ]
      },
      "minItems": 1,
      "maxItems": 3,
      "uniqueItems": true,
      "description": "From a fixed list. The first is the primary topic."
    },
    "language_change": {
      "enum": [
        "none",
        "proposes"
      ],
      "description": "none: needs no change to the language. proposes: would change it."
    },
    "built_on": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "uniqueItems": true,
      "description": "The Terms, rules and engine calls the entry uses, by their real names, such as UP:Admin-Fee, A9 or simulate_amendment."
    },
    "published": {
      "type": "string",
      "format": "date"
    },
    "updated": {
      "type": "string",
      "format": "date"
    },
    "parent": {
      "type": "integer",
      "minimum": 1,
      "description": "The number of the entry this one came out of. A note has none."
    },
    "parts": {
      "type": "array",
      "items": {
        "type": "integer",
        "minimum": 1
      },
      "uniqueItems": true,
      "description": "The numbers of the entries that came out of this one. The inverse of parent."
    },
    "related": {
      "type": "array",
      "items": {
        "type": "integer",
        "minimum": 1
      },
      "uniqueItems": true,
      "description": "Other entries worth reading with this one."
    },
    "answered_by": {
      "type": "integer",
      "minimum": 1,
      "description": "For a question: the number of the entry that settles it. Required when status is answered."
    },
    "outcome": {
      "enum": [
        "held",
        "held_in_part",
        "did_not_hold",
        "inconclusive"
      ],
      "description": "For an experiment: its result, one of the outcomes the index defines."
    },
    "simulated": {
      "type": "boolean",
      "description": "True when the data is an example with hypothetical parties."
    },
    "license": {
      "type": "string",
      "minLength": 1,
      "description": "An SPDX identifier."
    },
    "reading_minutes": {
      "type": "integer",
      "minimum": 1
    },
    "url": {
      "type": "string",
      "format": "uri",
      "description": "The page."
    },
    "markdown": {
      "type": "string",
      "format": "uri",
      "description": "The same content as Markdown."
    },
    "json": {
      "type": "string",
      "format": "uri",
      "description": "The full record: this shape plus detail and refs."
    },
    "detail": {
      "type": "object",
      "description": "Fields that depend on the kind. Present in entry.json, left out of the index."
    },
    "refs": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/ref"
      },
      "description": "Every entry named in parent, parts and related, resolved to a title and an address."
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "kind": {
            "const": "question"
          }
        }
      },
      "then": {
        "properties": {
          "status": {
            "enum": [
              "open",
              "answered",
              "withdrawn"
            ]
          }
        }
      },
      "else": {
        "properties": {
          "status": {
            "enum": [
              "exploring",
              "prototype",
              "concluded",
              "withdrawn"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "kind": {
            "const": "note"
          }
        }
      },
      "then": {
        "not": {
          "required": [
            "parent"
          ]
        }
      }
    },
    {
      "if": {
        "properties": {
          "status": {
            "const": "answered"
          }
        }
      },
      "then": {
        "required": [
          "answered_by"
        ]
      }
    },
    {
      "if": {
        "properties": {
          "kind": {
            "const": "note"
          }
        }
      },
      "then": {
        "properties": {
          "detail": {
            "$ref": "#/$defs/note"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "kind": {
            "const": "experiment"
          }
        }
      },
      "then": {
        "properties": {
          "detail": {
            "$ref": "#/$defs/experiment"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "kind": {
            "const": "reusable"
          }
        }
      },
      "then": {
        "properties": {
          "detail": {
            "$ref": "#/$defs/reusable"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "kind": {
            "const": "question"
          }
        }
      },
      "then": {
        "properties": {
          "detail": {
            "$ref": "#/$defs/question"
          }
        }
      }
    }
  ],
  "$defs": {
    "note": {
      "type": "object",
      "required": [
        "claim"
      ],
      "additionalProperties": false,
      "properties": {
        "claim": {
          "type": "string",
          "minLength": 1
        },
        "adds_to_language": {
          "type": "object",
          "required": [
            "terms",
            "event_kinds",
            "required_fields"
          ],
          "additionalProperties": false,
          "properties": {
            "terms": {
              "type": "integer"
            },
            "event_kinds": {
              "type": "integer"
            },
            "required_fields": {
              "type": "integer"
            }
          }
        },
        "sections": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "id",
              "title"
            ],
            "additionalProperties": false,
            "properties": {
              "id": {
                "type": "string",
                "minLength": 1
              },
              "title": {
                "type": "string",
                "minLength": 1
              },
              "url": {
                "type": "string",
                "format": "uri"
              }
            }
          }
        },
        "summary_json": {
          "type": "string",
          "format": "uri"
        }
      }
    },
    "experiment": {
      "type": "object",
      "required": [
        "claim",
        "method",
        "result",
        "limits"
      ],
      "additionalProperties": false,
      "properties": {
        "claim": {
          "type": "string",
          "minLength": 1,
          "description": "The statement the experiment tests."
        },
        "method": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "result": {
          "type": "object",
          "required": [
            "outcome",
            "summary"
          ],
          "additionalProperties": false,
          "properties": {
            "outcome": {
              "enum": [
                "held",
                "held_in_part",
                "did_not_hold",
                "inconclusive"
              ]
            },
            "summary": {
              "type": "string",
              "minLength": 1
            }
          }
        },
        "checks": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "what",
              "by",
              "result"
            ],
            "additionalProperties": false,
            "properties": {
              "what": {
                "type": "string",
                "minLength": 1
              },
              "by": {
                "type": "string",
                "minLength": 1,
                "description": "The implementations that computed the value."
              },
              "result": {
                "enum": [
                  "equal",
                  "different",
                  "not_compared"
                ]
              }
            }
          }
        },
        "limits": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "description": "What the experiment does not show."
        },
        "run": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "label",
              "command"
            ],
            "additionalProperties": false,
            "properties": {
              "label": {
                "type": "string",
                "minLength": 1
              },
              "command": {
                "type": "string",
                "minLength": 1
              }
            }
          }
        },
        "files": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/file"
          }
        }
      }
    },
    "reusable": {
      "type": "object",
      "required": [
        "files"
      ],
      "additionalProperties": false,
      "properties": {
        "files": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/file"
          },
          "minItems": 1
        },
        "schemas": {
          "type": "array",
          "items": {
            "type": "string",
            "format": "uri"
          }
        },
        "use": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "title",
              "text"
            ],
            "additionalProperties": false,
            "properties": {
              "title": {
                "type": "string",
                "minLength": 1
              },
              "text": {
                "type": "string",
                "minLength": 1
              }
            }
          }
        },
        "source": {
          "type": "object"
        }
      }
    },
    "question": {
      "type": "object",
      "required": [
        "question",
        "why",
        "settle"
      ],
      "additionalProperties": false,
      "properties": {
        "question": {
          "type": "string",
          "minLength": 1
        },
        "why": {
          "type": "string",
          "minLength": 1,
          "description": "Why the answer matters."
        },
        "known": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "description": "What is established so far."
        },
        "options": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "label",
              "text"
            ],
            "additionalProperties": false,
            "properties": {
              "label": {
                "type": "string",
                "minLength": 1
              },
              "text": {
                "type": "string",
                "minLength": 1
              }
            }
          },
          "description": "Candidate answers. None is a decision."
        },
        "settle": {
          "type": "string",
          "minLength": 1,
          "description": "The evidence or decision that would close the question."
        }
      }
    },
    "file": {
      "type": "object",
      "required": [
        "name",
        "url",
        "media_type"
      ],
      "additionalProperties": false,
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1
        },
        "url": {
          "type": "string",
          "format": "uri"
        },
        "media_type": {
          "type": "string",
          "minLength": 1
        },
        "describes": {
          "type": "string",
          "minLength": 1
        },
        "format": {
          "type": "string",
          "description": "The research format the file is written in, such as up-research/query-trace/0."
        },
        "schema": {
          "type": "string",
          "format": "uri",
          "description": "The JSON Schema the file validates against."
        },
        "fingerprint": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$",
          "description": "Content hash of the JSON value: RFC 8785 canonical JSON, then SHA-256, with any top-level sigs member left out. It is not a hash of the file as stored."
        },
        "bytes": {
          "type": "integer",
          "minimum": 0
        },
        "license": {
          "type": "string",
          "minLength": 1
        },
        "simulated": {
          "type": "boolean"
        }
      }
    },
    "ref": {
      "type": "object",
      "required": [
        "number",
        "kind",
        "title",
        "url"
      ],
      "additionalProperties": false,
      "properties": {
        "number": {
          "type": "integer",
          "minimum": 1
        },
        "kind": {
          "enum": [
            "note",
            "experiment",
            "reusable",
            "question"
          ]
        },
        "title": {
          "type": "string",
          "minLength": 1
        },
        "status": {
          "enum": [
            "open",
            "answered",
            "exploring",
            "prototype",
            "concluded",
            "withdrawn"
          ]
        },
        "relation": {
          "enum": [
            "parent",
            "part",
            "related"
          ]
        },
        "url": {
          "type": "string",
          "format": "uri"
        },
        "json": {
          "type": "string",
          "format": "uri"
        }
      }
    }
  }
}
