@@ -282,6 +282,12 @@ class RelationshipCardinality(str, Enum):
282282 MANY = "many"
283283
284284
285+ class RelationshipDirection (str , Enum ):
286+ BIDIR = "bidirectional"
287+ OUTBOUND = "outbound"
288+ INBOUND = "inbound"
289+
290+
285291class BranchSupportType (str , Enum ):
286292 AWARE = "aware"
287293 AGNOSTIC = "agnostic"
@@ -339,6 +345,7 @@ class RelationshipSchema(BaseModel):
339345 state : SchemaState = SchemaState .PRESENT
340346 name : str
341347 peer : str
348+ direction : RelationshipDirection = RelationshipDirection .BIDIR
342349 kind : RelationshipKind = RelationshipKind .GENERIC
343350 label : Optional [str ] = None
344351 description : Optional [str ] = None
@@ -413,6 +420,21 @@ def get_relationship_by_identifier(self, id: str, raise_on_error: bool = True) -
413420
414421 raise ValueError (f"Unable to find the relationship { id } " )
415422
423+ def get_matching_relationship (
424+ self , id : str , direction : RelationshipDirection = RelationshipDirection .BIDIR
425+ ) -> RelationshipSchema :
426+ valid_direction = RelationshipDirection .BIDIR
427+ if direction == RelationshipDirection .INBOUND :
428+ valid_direction = RelationshipDirection .OUTBOUND
429+ elif direction == RelationshipDirection .OUTBOUND :
430+ valid_direction = RelationshipDirection .INBOUND
431+
432+ for item in self .relationships :
433+ if item .identifier == id and item .direction == valid_direction :
434+ return item
435+
436+ raise ValueError (f"Unable to find the relationship { id } / ({ valid_direction .value } )" )
437+
416438 @property
417439 def attribute_names (self ) -> list [str ]:
418440 return [item .name for item in self .attributes ]
0 commit comments