{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Verada diagnostic array",
  "description": "The array that --diagnostics json writes. It excludes stdout listings, program output and an invalid command line's human report (B7003). Additional object fields are allowed for forward-compatible consumers.",
  "type": "array",
  "items": {
    "type": "object",
    "required": [
      "code",
      "name",
      "severity",
      "phase",
      "message",
      "primary",
      "secondary",
      "notes",
      "fixes",
      "advice",
      "counterexample",
      "instance"
    ],
    "properties": {
      "code": {
        "type": "string",
        "pattern": "^B[0-9]{4}$"
      },
      "name": {
        "type": "string"
      },
      "severity": {
        "enum": [
          "error",
          "warning",
          "info"
        ]
      },
      "phase": {
        "enum": [
          "lexical",
          "syntax",
          "semantic",
          "flow",
          "proof",
          "runtime",
          "driver",
          "internal"
        ]
      },
      "message": {
        "type": "string"
      },
      "primary": {
        "anyOf": [
          {
            "$ref": "#/$defs/label"
          },
          {
            "type": "null"
          }
        ]
      },
      "secondary": {
        "type": "array",
        "items": {
          "$ref": "#/$defs/label"
        }
      },
      "notes": {
        "type": "array",
        "items": {
          "$ref": "#/$defs/note"
        }
      },
      "fixes": {
        "type": "array",
        "items": {
          "$ref": "#/$defs/fix"
        }
      },
      "advice": {
        "anyOf": [
          {
            "type": "string"
          },
          {
            "type": "null"
          }
        ]
      },
      "counterexample": {
        "anyOf": [
          {
            "$ref": "#/$defs/counterexample"
          },
          {
            "type": "null"
          }
        ]
      },
      "instance": {
        "anyOf": [
          {
            "type": "string",
            "pattern": "^[0-9a-f]{16}$"
          },
          {
            "type": "null"
          }
        ]
      }
    }
  },
  "$defs": {
    "span": {
      "type": "object",
      "required": [
        "start",
        "end"
      ],
      "properties": {
        "start": {
          "type": "integer",
          "minimum": 0
        },
        "end": {
          "type": "integer",
          "minimum": 0
        },
        "line": {
          "type": "integer",
          "minimum": 1
        },
        "column": {
          "type": "integer",
          "minimum": 1
        },
        "endLine": {
          "type": "integer",
          "minimum": 1
        },
        "endColumn": {
          "type": "integer",
          "minimum": 1
        },
        "file": {
          "type": "string"
        }
      },
      "dependentRequired": {
        "file": [
          "line",
          "column",
          "endLine",
          "endColumn"
        ]
      }
    },
    "label": {
      "type": "object",
      "required": [
        "span",
        "label"
      ],
      "properties": {
        "span": {
          "$ref": "#/$defs/span"
        },
        "label": {
          "type": "string"
        }
      }
    },
    "note": {
      "type": "object",
      "required": [
        "text",
        "span"
      ],
      "properties": {
        "text": {
          "type": "string"
        },
        "span": {
          "anyOf": [
            {
              "$ref": "#/$defs/span"
            },
            {
              "type": "null"
            }
          ]
        }
      }
    },
    "fix": {
      "type": "object",
      "required": [
        "span",
        "replacement",
        "description"
      ],
      "properties": {
        "span": {
          "$ref": "#/$defs/span"
        },
        "replacement": {
          "type": "string"
        },
        "description": {
          "type": "string"
        }
      }
    },
    "value": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "choice",
              "value"
            ],
            "properties": {
              "choice": {
                "type": "string"
              },
              "value": {
                "$ref": "#/$defs/value"
              }
            }
          }
        }
      ]
    },
    "counterexample": {
      "type": "object",
      "required": [
        "replayed",
        "bindings"
      ],
      "properties": {
        "replayed": {
          "type": "boolean"
        },
        "bindings": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "name",
              "value",
              "point"
            ],
            "properties": {
              "name": {
                "type": "string"
              },
              "value": {
                "$ref": "#/$defs/value"
              },
              "point": {
                "anyOf": [
                  {
                    "$ref": "#/$defs/span"
                  },
                  {
                    "type": "null"
                  }
                ]
              }
            }
          }
        },
        "region": {
          "anyOf": [
            {
              "$ref": "#/$defs/region"
            },
            {
              "type": "null"
            }
          ]
        }
      }
    },
    "part": {
      "oneOf": [
        {
          "type": "object",
          "required": [
            "atMost"
          ],
          "properties": {
            "atMost": {
              "$ref": "#/$defs/value"
            }
          }
        },
        {
          "type": "object",
          "required": [
            "atLeast"
          ],
          "properties": {
            "atLeast": {
              "$ref": "#/$defs/value"
            }
          }
        },
        {
          "type": "object",
          "required": [
            "from",
            "to"
          ],
          "properties": {
            "from": {
              "$ref": "#/$defs/value"
            },
            "to": {
              "$ref": "#/$defs/value"
            }
          }
        },
        {
          "type": "object",
          "required": [
            "exactly"
          ],
          "properties": {
            "exactly": {
              "$ref": "#/$defs/value"
            }
          }
        }
      ]
    },
    "region": {
      "type": "object",
      "required": [
        "input",
        "exact",
        "parts",
        "text"
      ],
      "properties": {
        "input": {
          "type": "string"
        },
        "exact": {
          "type": "boolean"
        },
        "parts": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/part"
          }
        },
        "text": {
          "type": "string"
        }
      }
    }
  }
}
