{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://volland.github.io/obsigraph/spec/tgs/v0.1/tgs.schema.json",
  "title": "Typed Graph Schema (TGS) 0.1 schema note frontmatter",
  "description": "Validates the TGS keys of a schema note's YAML frontmatter, parsed to JSON. Other frontmatter keys are allowed. License: MIT.",
  "type": "object",
  "properties": {
    "tgs": {
      "type": [
        "string",
        "number"
      ],
      "pattern": "^0\\.[0-9]+$",
      "description": "TGS version the note is written for, e.g. \"0.1\"."
    },
    "schema": {
      "$ref": "#/$defs/typeDeclaration",
      "description": "The type named by the note's title; the note body is its template."
    },
    "schemas": {
      "type": "object",
      "description": "Types declared in this note, by type name.",
      "additionalProperties": {
        "$ref": "#/$defs/typeDeclaration"
      }
    },
    "edgeTypes": {
      "type": "object",
      "description": "Edge types declared in this note, by edge type name.",
      "additionalProperties": {
        "$ref": "#/$defs/edgeTypeDeclaration"
      }
    },
    "prefixes": {
      "type": "object",
      "description": "CURIE prefixes for the whole vault.",
      "additionalProperties": {
        "type": "string",
        "minLength": 1
      }
    }
  },
  "$defs": {
    "name": {
      "type": "string",
      "minLength": 1
    },
    "names": {
      "oneOf": [
        {
          "$ref": "#/$defs/name"
        },
        {
          "type": "array",
          "items": {
            "$ref": "#/$defs/name"
          },
          "minItems": 1
        }
      ]
    },
    "iri": {
      "type": "string",
      "pattern": "^[A-Za-z][A-Za-z0-9_.-]*:\\S*$",
      "description": "A full IRI or a CURIE such as schema:Person."
    },
    "scalar": {
      "type": [
        "string",
        "number",
        "boolean"
      ]
    },
    "kind": {
      "enum": [
        "text",
        "number",
        "boolean",
        "date",
        "datetime",
        "link",
        "list"
      ]
    },
    "visualization": {
      "type": "object",
      "description": "Display hints; keys are host-specific."
    },
    "property": {
      "oneOf": [
        {
          "type": "null"
        },
        {
          "$ref": "#/$defs/kind"
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "$ref": "#/$defs/kind"
            },
            "required": {
              "type": "boolean"
            },
            "many": {
              "type": "boolean"
            },
            "values": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/scalar"
              }
            },
            "default": true,
            "uri": {
              "$ref": "#/$defs/iri"
            }
          },
          "additionalProperties": false
        }
      ]
    },
    "properties": {
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/property"
          }
        },
        {
          "type": "array",
          "items": {
            "oneOf": [
              {
                "$ref": "#/$defs/name"
              },
              {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "$ref": "#/$defs/name"
                  },
                  "kind": {
                    "$ref": "#/$defs/kind"
                  },
                  "required": {
                    "type": "boolean"
                  },
                  "many": {
                    "type": "boolean"
                  },
                  "values": {
                    "type": "array",
                    "items": {
                      "$ref": "#/$defs/scalar"
                    }
                  },
                  "default": true,
                  "uri": {
                    "$ref": "#/$defs/iri"
                  }
                },
                "additionalProperties": false
              }
            ]
          }
        }
      ]
    },
    "edgeEntry": {
      "oneOf": [
        {
          "type": "null"
        },
        {
          "$ref": "#/$defs/names"
        },
        {
          "type": "object",
          "properties": {
            "target": {
              "$ref": "#/$defs/names"
            },
            "many": {
              "type": "boolean"
            },
            "required": {
              "type": "boolean"
            }
          },
          "additionalProperties": false
        }
      ]
    },
    "edges": {
      "oneOf": [
        {
          "type": "array",
          "items": {
            "$ref": "#/$defs/name"
          }
        },
        {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/edgeEntry"
          }
        }
      ]
    },
    "typeDeclaration": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "uri": {
          "$ref": "#/$defs/iri"
        },
        "properties": {
          "$ref": "#/$defs/properties"
        },
        "edges": {
          "$ref": "#/$defs/edges"
        },
        "template": {
          "type": "string",
          "minLength": 1
        },
        "visualization": {
          "$ref": "#/$defs/visualization"
        },
        "style": {
          "$ref": "#/$defs/visualization"
        }
      },
      "additionalProperties": false
    },
    "edgeTypeDeclaration": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "from": {
          "$ref": "#/$defs/names"
        },
        "to": {
          "$ref": "#/$defs/names"
        },
        "properties": {
          "$ref": "#/$defs/properties"
        },
        "uri": {
          "$ref": "#/$defs/iri"
        },
        "visualization": {
          "$ref": "#/$defs/visualization"
        },
        "style": {
          "$ref": "#/$defs/visualization"
        }
      },
      "additionalProperties": false
    }
  }
}
