{
  "$id": "https://patchraven.com/schemas/webhook/v1.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "type": {
      "type": "string",
      "enum": ["alert.created", "alert.updated", "test.ping"]
    },
    "timestamp": {
      "type": "string",
      "format": "date-time",
      "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
    },
    "data": {
      "type": "object",
      "properties": {
        "schemaVersion": {
          "type": "number",
          "const": 1
        },
        "test": {
          "type": "boolean"
        },
        "workspace": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string"
            },
            "name": {
              "type": "string"
            }
          },
          "required": ["id", "name"],
          "additionalProperties": false
        },
        "alert": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string"
            },
            "url": {
              "type": "string",
              "format": "uri"
            },
            "primaryAlias": {
              "type": "string"
            },
            "aliases": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "kind": {
              "type": "string",
              "enum": ["vulnerability", "malware", "runtime-prerelease"]
            },
            "title": {
              "type": "string"
            },
            "headline": {
              "type": "string"
            },
            "match": {
              "type": "string",
              "enum": ["affected", "possibly_affected", "watching"]
            },
            "followUp": {
              "anyOf": [
                {
                  "type": "string",
                  "enum": ["severity_up", "newly_affected", "fix_available", "withdrawn", "kev_added"]
                },
                {
                  "type": "null"
                }
              ]
            },
            "severity": {
              "type": "object",
              "properties": {
                "score": {
                  "anyOf": [
                    {
                      "type": "number",
                      "minimum": 0,
                      "maximum": 10
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "band": {
                  "type": "string",
                  "enum": ["critical", "high", "medium", "low", "unscored"]
                },
                "label": {
                  "anyOf": [
                    {
                      "type": "string",
                      "enum": ["critical", "high", "moderate", "low"]
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "cvss31": {
                  "anyOf": [
                    {
                      "type": "object",
                      "properties": {
                        "score": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 10
                        },
                        "vector": {
                          "type": ["string", "null"]
                        }
                      },
                      "required": ["score", "vector"],
                      "additionalProperties": false
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "cvss40": {
                  "anyOf": [
                    {
                      "type": "object",
                      "properties": {
                        "score": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 10
                        },
                        "vector": {
                          "type": ["string", "null"]
                        }
                      },
                      "required": ["score", "vector"],
                      "additionalProperties": false
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "unscored": {
                  "type": "boolean"
                }
              },
              "required": ["score", "band", "label", "cvss31", "cvss40", "unscored"],
              "additionalProperties": false
            },
            "kev": {
              "type": "boolean"
            },
            "withdrawn": {
              "type": "boolean"
            },
            "fixedVersions": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "projects": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": ["string", "null"]
                  },
                  "name": {
                    "type": "string"
                  },
                  "components": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "ecosystem": {
                          "type": "string"
                        },
                        "name": {
                          "type": "string"
                        },
                        "version": {
                          "type": ["string", "null"]
                        },
                        "match": {
                          "type": "string",
                          "enum": ["affected", "possibly_affected", "watching"]
                        },
                        "scope": {
                          "anyOf": [
                            {
                              "type": "string",
                              "enum": ["runtime", "dev", "test"]
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "manifestPath": {
                          "type": ["string", "null"]
                        }
                      },
                      "required": ["ecosystem", "name", "version", "match", "scope", "manifestPath"],
                      "additionalProperties": false
                    }
                  }
                },
                "required": ["id", "name", "components"],
                "additionalProperties": false
              }
            },
            "projectCount": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "truncated": {
              "type": "boolean"
            },
            "references": {
              "type": "array",
              "items": {
                "type": "string",
                "format": "uri"
              }
            }
          },
          "required": [
            "id",
            "url",
            "primaryAlias",
            "aliases",
            "kind",
            "title",
            "headline",
            "match",
            "followUp",
            "severity",
            "kev",
            "withdrawn",
            "fixedVersions",
            "projects",
            "projectCount",
            "truncated",
            "references"
          ],
          "additionalProperties": false
        }
      },
      "required": ["schemaVersion", "test", "workspace", "alert"],
      "additionalProperties": false
    }
  },
  "required": ["type", "timestamp", "data"],
  "additionalProperties": false,
  "title": "Alert webhook payload, version 1",
  "description": "The JSON body of every webhook request. Verify the Standard Webhooks signature before trusting it."
}
