{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:si:feed-record:1.4",
  "title": "Public issue operation 1.4",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "record_contract_version",
    "operation_id",
    "object_type",
    "object_id",
    "previous_revision",
    "revision",
    "kind",
    "reason_code",
    "replacement_ids",
    "effective_at",
    "payload"
  ],
  "properties": {
    "record_contract_version": {
      "const": "1.4"
    },
    "operation_id": {
      "$ref": "#/$defs/identifier"
    },
    "object_type": {
      "const": "issue"
    },
    "object_id": {
      "$ref": "#/$defs/identifier"
    },
    "previous_revision": {
      "anyOf": [
        {
          "$ref": "#/$defs/revision"
        },
        {
          "type": "null"
        }
      ]
    },
    "revision": {
      "$ref": "#/$defs/revision"
    },
    "kind": {
      "enum": [
        "upsert",
        "withdraw",
        "relation_changed",
        "redact",
        "retire"
      ]
    },
    "reason_code": {
      "$ref": "#/$defs/identifier"
    },
    "replacement_ids": {
      "type": "array",
      "maxItems": 64,
      "uniqueItems": true,
      "items": {
        "$ref": "#/$defs/identifier"
      }
    },
    "effective_at": {
      "$ref": "#/$defs/utcTime"
    },
    "payload": {
      "anyOf": [
        {
          "$ref": "#/$defs/issue"
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "kind": {
            "const": "redact"
          }
        }
      },
      "then": {
        "properties": {
          "payload": {
            "type": "null"
          }
        }
      },
      "else": {
        "properties": {
          "payload": {
            "$ref": "#/$defs/issue"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "kind": {
            "const": "withdraw"
          }
        }
      },
      "then": {
        "properties": {
          "payload": {
            "properties": {
              "publication_state": {
                "const": "withdrawn"
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "kind": {
            "const": "retire"
          }
        }
      },
      "then": {
        "properties": {
          "payload": {
            "properties": {
              "support_state": {
                "const": "retired"
              }
            }
          }
        }
      }
    }
  ],
  "$defs": {
    "identifier": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128,
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$",
      "not": {
        "pattern": "[^A-Za-z0-9._:-]"
      }
    },
    "revision": {
      "type": "integer",
      "minimum": 1,
      "maximum": 9007199254740991
    },
    "utcTime": {
      "type": "string",
      "minLength": 20,
      "maxLength": 20,
      "format": "date-time",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
    },
    "issue": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "title",
        "summary",
        "identifiers",
        "confirmation",
        "source_state",
        "publication_state",
        "support_state",
        "source_references",
        "relations",
        "affected_rules",
        "advisory_type"
      ],
      "properties": {
        "title": {
          "type": "string",
          "minLength": 1,
          "maxLength": 1024
        },
        "summary": {
          "type": [
            "string",
            "null"
          ],
          "maxLength": 32768
        },
        "identifiers": {
          "type": "array",
          "minItems": 1,
          "maxItems": 64,
          "uniqueItems": true,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "namespace",
              "id"
            ],
            "properties": {
              "namespace": {
                "$ref": "#/$defs/identifier"
              },
              "id": {
                "$ref": "#/$defs/identifier"
              }
            }
          }
        },
        "confirmation": {
          "enum": [
            "candidate",
            "corroborated",
            "vendor_confirmed",
            "disputed",
            "rejected"
          ]
        },
        "source_state": {
          "enum": [
            "active",
            "corrected",
            "withdrawn",
            "conflicting"
          ]
        },
        "publication_state": {
          "enum": [
            "published",
            "corrected",
            "withdrawn"
          ]
        },
        "support_state": {
          "enum": [
            "active",
            "retired",
            "unknown"
          ]
        },
        "source_references": {
          "type": "array",
          "minItems": 1,
          "maxItems": 64,
          "uniqueItems": true,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "source_id",
              "record_id",
              "revision",
              "url",
              "relationship",
              "attribution"
            ],
            "properties": {
              "source_id": {
                "$ref": "#/$defs/identifier"
              },
              "record_id": {
                "$ref": "#/$defs/identifier"
              },
              "revision": {
                "$ref": "#/$defs/identifier"
              },
              "url": {
                "type": "string",
                "minLength": 1,
                "maxLength": 4096,
                "format": "uri"
              },
              "relationship": {
                "enum": [
                  "supports",
                  "refutes",
                  "quotes",
                  "derived_from"
                ]
              },
              "attribution": {
                "type": "string",
                "minLength": 1,
                "maxLength": 2048,
                "not": {
                  "pattern": "[\u0000-\u001f-]"
                }
              }
            }
          }
        },
        "relations": {
          "type": "array",
          "maxItems": 128,
          "uniqueItems": true,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "kind",
              "issue_id"
            ],
            "properties": {
              "kind": {
                "enum": [
                  "same_as",
                  "upstream_of",
                  "related_to",
                  "possibly_related"
                ]
              },
              "issue_id": {
                "$ref": "#/$defs/identifier"
              }
            }
          }
        },
        "affected_rules": {
          "type": "array",
          "maxItems": 64,
          "items": {
            "$ref": "#/$defs/affectedRule"
          }
        },
        "advisory_type": {
          "enum": [
            "reviewed",
            "unreviewed",
            "malware",
            "canonical-id"
          ]
        }
      }
    },
    "semver2": {
      "type": "string",
      "minLength": 1,
      "maxLength": 256,
      "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(?:-((?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)(?:\\.(?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\\+([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?$"
    },
    "versionBound": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "version",
        "inclusive"
      ],
      "properties": {
        "version": {
          "$ref": "#/$defs/semver2"
        },
        "inclusive": {
          "type": "boolean"
        }
      }
    },
    "affectedRule": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "rule_id",
        "revision",
        "identity",
        "version_scheme",
        "range",
        "original_range",
        "source_references"
      ],
      "properties": {
        "rule_id": {
          "$ref": "#/$defs/identifier"
        },
        "revision": {
          "$ref": "#/$defs/revision"
        },
        "identity": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "ecosystem",
            "name",
            "purl",
            "vendor",
            "platform",
            "constraint_scope"
          ],
          "properties": {
            "ecosystem": {
              "type": "string",
              "minLength": 1,
              "maxLength": 64
            },
            "name": {
              "type": "string",
              "minLength": 1,
              "maxLength": 1024
            },
            "purl": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 2048
                },
                {
                  "type": "null"
                }
              ]
            },
            "vendor": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 256
                },
                {
                  "type": "null"
                }
              ]
            },
            "platform": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 256
                },
                {
                  "type": "null"
                }
              ]
            },
            "constraint_scope": {
              "enum": [
                "unconstrained",
                "constrained",
                "unknown"
              ]
            }
          },
          "allOf": [
            {
              "if": {
                "properties": {
                  "constraint_scope": {
                    "const": "unconstrained"
                  }
                }
              },
              "then": {
                "properties": {
                  "vendor": {
                    "type": "null"
                  },
                  "platform": {
                    "type": "null"
                  }
                }
              }
            }
          ]
        },
        "version_scheme": {
          "enum": [
            "semver2",
            "unsupported"
          ]
        },
        "range": {
          "oneOf": [
            {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "kind",
                "lower",
                "upper"
              ],
              "properties": {
                "kind": {
                  "const": "interval"
                },
                "lower": {
                  "anyOf": [
                    {
                      "$ref": "#/$defs/versionBound"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "upper": {
                  "anyOf": [
                    {
                      "$ref": "#/$defs/versionBound"
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              }
            },
            {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "kind",
                "expression",
                "reason_code"
              ],
              "properties": {
                "kind": {
                  "const": "unsupported"
                },
                "expression": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 32768
                },
                "reason_code": {
                  "$ref": "#/$defs/identifier"
                }
              }
            },
            {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "kind",
                "lower",
                "upper",
                "prerelease_policy",
                "allowed_prerelease_cores"
              ],
              "properties": {
                "kind": {
                  "const": "npm_comparator_intersection"
                },
                "lower": {
                  "anyOf": [
                    {
                      "$ref": "#/$defs/versionBound"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "upper": {
                  "anyOf": [
                    {
                      "$ref": "#/$defs/versionBound"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "prerelease_policy": {
                  "const": "npm_explicit_core_tuples"
                },
                "allowed_prerelease_cores": {
                  "type": "array",
                  "minItems": 0,
                  "maxItems": 32,
                  "uniqueItems": true,
                  "items": {
                    "$ref": "#/$defs/versionCore"
                  }
                }
              }
            }
          ]
        },
        "original_range": {
          "type": "string",
          "minLength": 1,
          "maxLength": 32768
        },
        "source_references": {
          "type": "array",
          "minItems": 1,
          "maxItems": 16,
          "uniqueItems": true,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "source_id",
              "record_id",
              "revision"
            ],
            "properties": {
              "source_id": {
                "$ref": "#/$defs/identifier"
              },
              "record_id": {
                "$ref": "#/$defs/identifier"
              },
              "revision": {
                "$ref": "#/$defs/identifier"
              }
            }
          }
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "version_scheme": {
                "const": "unsupported"
              }
            }
          },
          "then": {
            "properties": {
              "range": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "kind",
                  "expression",
                  "reason_code"
                ],
                "properties": {
                  "kind": {
                    "const": "unsupported"
                  },
                  "expression": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 32768
                  },
                  "reason_code": {
                    "$ref": "#/$defs/identifier"
                  }
                }
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "range": {
                "properties": {
                  "kind": {
                    "const": "npm_comparator_intersection"
                  }
                }
              }
            }
          },
          "then": {
            "properties": {
              "version_scheme": {
                "const": "semver2"
              },
              "identity": {
                "properties": {
                  "ecosystem": {
                    "const": "npm"
                  }
                }
              }
            }
          }
        }
      ]
    },
    "versionCore": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "major",
        "minor",
        "patch"
      ],
      "properties": {
        "major": {
          "type": "string",
          "minLength": 1,
          "maxLength": 252,
          "pattern": "^(0|[1-9][0-9]*)$",
          "not": {
            "pattern": "[^0-9]"
          }
        },
        "minor": {
          "type": "string",
          "minLength": 1,
          "maxLength": 252,
          "pattern": "^(0|[1-9][0-9]*)$",
          "not": {
            "pattern": "[^0-9]"
          }
        },
        "patch": {
          "type": "string",
          "minLength": 1,
          "maxLength": 252,
          "pattern": "^(0|[1-9][0-9]*)$",
          "not": {
            "pattern": "[^0-9]"
          }
        }
      }
    }
  }
}
