{
  "id": "http://www.jsonscript.org/schema/schema_strict.json#",
  "$schema": "https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/json-schema-v5.json#",
  "title": "JSONScript schema",
  "description": "JSONScript script with instructions (generated from template)",
  "anyOf": [
    {
      "$ref": "#$exec"
    },
    {
      "$ref": "#$ref"
    },
    {
      "$ref": "#$data"
    },
    {
      "$ref": "#$if"
    },
    {
      "$ref": "#$delay"
    },
    {
      "$ref": "#$func"
    },
    {
      "$ref": "#$call"
    },
    {
      "$ref": "#$quote"
    },
    {
      "$ref": "#macro_exec_0"
    },
    {
      "$ref": "#macro_exec_1"
    },
    {
      "$ref": "#macro_call_0"
    },
    {
      "$ref": "#macro_calc_0"
    },
    {
      "$ref": "#parallel"
    },
    {
      "$ref": "#sequential"
    },
    {
      "$ref": "#scalar"
    }
  ],
  "definitions": {
    "_$exec": {
      "id": "#$exec",
      "title": "$exec",
      "description": "call to external object, $exec and $method values should evaluate to a string",
      "type": "object",
      "properties": {
        "$exec": {
          "anyOf": [
            {
              "type": "string",
              "anyOf": [
                {
                  "pattern": "^[A-Za-z_$][A-Za-z_$0-9]+$"
                },
                {
                  "format": "uuid"
                }
              ]
            },
            {
              "allOf": [
                {
                  "type": [
                    "object",
                    "array"
                  ]
                },
                {
                  "$ref": "#"
                }
              ]
            }
          ]
        },
        "$method": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^[A-Za-z_$][A-Za-z_$0-9]+$"
            },
            {
              "allOf": [
                {
                  "type": [
                    "object",
                    "array"
                  ]
                },
                {
                  "$ref": "#"
                }
              ]
            }
          ]
        },
        "$args": {
          "$ref": "#"
        }
      },
      "additionalProperties": false,
      "required": [
        "$exec"
      ]
    },
    "_$ref": {
      "id": "#$ref",
      "title": "$ref",
      "description": "data/script from the current script using absolute/relative JSON-pointer expression",
      "type": "object",
      "properties": {
        "$ref": {
          "anyOf": [
            {
              "type": "string",
              "anyOf": [
                {
                  "format": "json-pointer"
                },
                {
                  "format": "relative-json-pointer"
                }
              ]
            },
            {
              "allOf": [
                {
                  "type": [
                    "object",
                    "array"
                  ]
                },
                {
                  "$ref": "#"
                }
              ]
            }
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "$ref"
      ]
    },
    "_$data": {
      "id": "#$data",
      "title": "$data",
      "description": "data from the data instance using JSON-pointer expression, $data value should evalute to a string before the expression is evaluated",
      "type": "object",
      "properties": {
        "$data": {
          "anyOf": [
            {
              "type": "string",
              "format": "json-pointer"
            },
            {
              "allOf": [
                {
                  "type": [
                    "object",
                    "array"
                  ]
                },
                {
                  "$ref": "#"
                }
              ]
            }
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "$data"
      ]
    },
    "_$if": {
      "id": "#$if",
      "title": "$if",
      "description": "conditional evaluation",
      "type": "object",
      "properties": {
        "$if": {
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "allOf": [
                {
                  "type": [
                    "object",
                    "array"
                  ]
                },
                {
                  "$ref": "#"
                }
              ]
            }
          ]
        },
        "$then": {
          "$ref": "#"
        },
        "$else": {
          "$ref": "#"
        }
      },
      "additionalProperties": false,
      "required": [
        "$if",
        "$then"
      ]
    },
    "_$delay": {
      "id": "#$delay",
      "title": "$delay",
      "description": "delayed script evaluation",
      "type": "object",
      "properties": {
        "$delay": {
          "$ref": "#"
        },
        "$wait": {
          "anyOf": [
            {
              "type": "integer",
              "default": 0
            },
            {
              "allOf": [
                {
                  "type": [
                    "object",
                    "array"
                  ]
                },
                {
                  "$ref": "#"
                }
              ]
            }
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "$delay"
      ]
    },
    "_$func": {
      "id": "#$func",
      "title": "$func",
      "description": "function definition",
      "type": "object",
      "properties": {
        "$func": {
          "$ref": "#"
        },
        "$name": {
          "anyOf": [
            {
              "type": "string",
              "anyOf": [
                {
                  "pattern": "^[A-Za-z_$][A-Za-z_$0-9]+$"
                },
                {
                  "format": "uuid"
                }
              ]
            },
            {
              "allOf": [
                {
                  "type": [
                    "object",
                    "array"
                  ]
                },
                {
                  "$ref": "#"
                }
              ]
            }
          ]
        },
        "$args": {
          "$ref": "#"
        }
      },
      "additionalProperties": false,
      "required": [
        "$func"
      ]
    },
    "_$call": {
      "id": "#$call",
      "title": "$call",
      "description": "function call",
      "type": "object",
      "properties": {
        "$call": {
          "$ref": "#"
        },
        "$args": {
          "$ref": "#"
        }
      },
      "additionalProperties": false,
      "required": [
        "$call"
      ]
    },
    "_$quote": {
      "id": "#$quote",
      "title": "$quote",
      "description": "use value without evaluation",
      "type": "object",
      "properties": {
        "$quote": {
          "$ref": "#"
        }
      },
      "additionalProperties": false,
      "required": [
        "$quote"
      ]
    },
    "_macro_exec_0": {
      "id": "#macro_exec_0",
      "description": "short syntax for executor call",
      "type": "object",
      "patternProperties": {
        "^\\$\\$([^\\.]+)\\.([^\\.]+)$": {
          "$ref": "#"
        }
      },
      "maxProperties": 1,
      "minProperties": 1,
      "additionalProperties": false,
      "patternRequired": [
        "^\\$\\$([^\\.]+)\\.([^\\.]+)$"
      ]
    },
    "_macro_exec_1": {
      "id": "#macro_exec_1",
      "description": "short syntax for executor call",
      "type": "object",
      "patternProperties": {
        "^\\$\\$([^\\.]+)$": {
          "$ref": "#"
        }
      },
      "maxProperties": 1,
      "minProperties": 1,
      "additionalProperties": false,
      "patternRequired": [
        "^\\$\\$([^\\.]+)$"
      ]
    },
    "_macro_call_0": {
      "id": "#macro_call_0",
      "description": "short syntax for function call",
      "type": "object",
      "patternProperties": {
        "^\\$\\#(.+)$": {
          "$ref": "#"
        }
      },
      "maxProperties": 1,
      "minProperties": 1,
      "additionalProperties": false,
      "patternRequired": [
        "^\\$\\#(.+)$"
      ]
    },
    "_macro_calc_0": {
      "id": "#macro_calc_0",
      "description": "short calculations syntax",
      "type": "object",
      "patternProperties": {
        "\\$([+\\-*/=!<>&\\|^]{1,2})": {
          "$ref": "#"
        }
      },
      "maxProperties": 1,
      "minProperties": 1,
      "additionalProperties": false,
      "patternRequired": [
        "\\$([+\\-*/=!<>&\\|^]{1,2})"
      ]
    },
    "parallel": {
      "id": "#parallel",
      "description": "scripts in the object are executed in parallel, property names should not start with $",
      "type": "object",
      "patternProperties": {
        "^[^$]": {
          "$ref": "#"
        }
      },
      "additionalProperties": false
    },
    "sequential": {
      "id": "#sequential",
      "description": "scripts in array are executed sequentially",
      "type": "array",
      "items": {
        "$ref": "#"
      }
    },
    "scalar": {
      "id": "#scalar",
      "description": "scalar values are also valid JSONScript",
      "type": [
        "string",
        "number",
        "integer",
        "boolean",
        "null"
      ]
    }
  }
}