{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://openssom.org/schema/relationship.json",
  "title": "SSOM Relationship",
  "description": "Typed, directed, and optionally time-bounded relationships between SSOM entities, including equipment and device interactions.",
  "type": "object",
  "required": [
    "relationship_id",
    "relationship_type",
    "from_ref",
    "to_ref",
    "provenance",
    "confidence"
  ],
  "properties": {
    "relationship_id": {
      "type": "string",
      "pattern": "^urn:ssom:relationship:"
    },
    "relationship_type": {
      "description": "Relationship code MUST be a governed SSOM core term or a namespaced extension relationship code.",
      "anyOf": [
        {
          "$ref": "common.json#/$defs/coreRelationshipTerm"
        },
        {
          "$ref": "common.json#/$defs/extensionRelationshipCode"
        }
      ]
    },
    "from_ref": {
      "type": "string"
    },
    "to_ref": {
      "type": "string"
    },
    "valid_from": {
      "type": "string",
      "format": "date-time"
    },
    "valid_to": {
      "type": "string",
      "format": "date-time"
    },
    "confidence": {
      "type": "number",
      "minimum": 0,
      "maximum": 1
    },
    "provenance": {
      "$ref": "common.json#/$defs/provenance"
    },
    "relationship_mapping": {
      "$ref": "common.json#/$defs/relationshipMapping"
    },
    "relationship_context": {
      "type": "object",
      "additionalProperties": true
    },
    "source_system": {
      "type": "string"
    },
    "source_record": {
      "type": "string"
    },
    "semantic_profile_version": {
      "type": "string"
    },
    "direction": {
      "$ref": "common.json#/$defs/relationshipDirection"
    },
    "cardinality": {
      "type": "string"
    },
    "extensions": {
      "type": "object",
      "additionalProperties": true
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "relationship_type": {
            "$ref": "common.json#/$defs/extensionRelationshipCode"
          }
        }
      },
      "then": {
        "required": [
          "relationship_mapping"
        ]
      }
    }
  ],
  "additionalProperties": true
}
