{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "git-tpl project configuration",
  "description": "The .config/git.tpl.toml contract. Template-specific answers, unique composed owners and repository semantics are checked by git-tpl.",
  "type": "object",
  "properties": {
    "template": {
      "description": "Which template this project came from.",
      "allOf": [
        {
          "$ref": "#/definitions/TemplateRef"
        }
      ]
    },
    "answers": {
      "description": "The answers used to render it.\n\n`BTreeMap` rather than a hash map so the file is written in a stable\norder. A configuration file whose key order changed on every write would\nproduce a diff on every `update`, and reviewing it would be pointless.",
      "type": "object",
      "additionalProperties": {
        "$ref": "#/definitions/Value"
      }
    },
    "composed": {
      "description": "Exact child revisions that contributed to the current rendering; a branch `ref` is followed on the next update.",
      "type": "array",
      "items": {
        "$ref": "#/definitions/ComposedRef"
      }
    }
  },
  "required": [
    "template"
  ],
  "definitions": {
    "TemplateRef": {
      "description": "The `[template]` table.",
      "type": "object",
      "properties": {
        "source": {
          "description": "Any Git URL, or a path on this machine.",
          "type": "string"
        },
        "ref": {
          "description": "Branch, tag or commit. `None` means the remote's default branch.",
          "type": [
            "string",
            "null"
          ]
        },
        "id": {
          "description": "Override the derived template id, and so the ref name.\n\nSet this when a template moves address but is conceptually the same\ntemplate: the id determines `refs/tpl/<id>`, and a changed id starts a\nnew ref with no shared history.",
          "type": [
            "string",
            "null"
          ]
        },
        "root": {
          "description": "Override the manifest's rendered subdirectory.",
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "source"
      ]
    },
    "Value": {
      "description": "A structured value.\n\n`BTreeMap` for tables so that iteration order is deterministic. A template\nthat iterates a table must render the same bytes every time, or the rendered\ntree changes for no reason and `update` commits noise.",
      "anyOf": [
        {
          "description": "An explicitly present null, distinct from a missing context name.",
          "type": "null"
        },
        {
          "description": "A boolean.",
          "type": "boolean"
        },
        {
          "description": "A 64-bit signed integer.",
          "type": "integer",
          "format": "int64"
        },
        {
          "description": "A double-precision float.",
          "type": "number",
          "format": "double"
        },
        {
          "description": "A UTF-8 string.",
          "type": "string"
        },
        {
          "description": "An ordered list.",
          "type": "array",
          "items": {
            "$ref": "#/definitions/Value"
          }
        },
        {
          "description": "A key-value table, iterated in key order.",
          "type": "object",
          "additionalProperties": {
            "$ref": "#/definitions/Value"
          }
        }
      ]
    },
    "ComposedRef": {
      "description": "One selected `[[compose]]` declaration and the commit it resolved to.",
      "type": "object",
      "properties": {
        "from": {
          "allOf": [
            {
              "description": "Parent list question naming this child; unique within a template.",
              "type": "string"
            },
            {
              "minLength": 1
            }
          ]
        },
        "source": {
          "allOf": [
            {
              "description": "Resolved Git URL or local path, after expression evaluation.",
              "type": "string"
            },
            {
              "minLength": 1
            }
          ]
        },
        "ref": {
          "allOf": [
            {
              "description": "Branch, tag or commit the next update should follow.",
              "type": "string"
            },
            {
              "minLength": 1
            }
          ]
        },
        "commit": {
          "allOf": [
            {
              "description": "Full 40-character Git commit used for this rendering.",
              "type": "string"
            },
            {
              "pattern": "^[0-9a-fA-F]{40}$"
            }
          ]
        }
      },
      "required": [
        "from",
        "source",
        "ref",
        "commit"
      ]
    }
  },
  "$id": "https://noirbizarre.github.io/git-tpl/project.schema.json"
}
