Skip to content

Commit b9976d4

Browse files
committed
if the Target is a reference, and reference equals this, return null, otherwise, return the parent
1 parent 9ab8890 commit b9976d4

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

src/Microsoft.OpenApi/Models/References/OpenApiTagReference.cs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,13 @@ public OpenApiTagReference? Parent
6868
{
6969
get
7070
{
71-
// Prevent stack overflow by checking for self-reference
72-
var targetParent = Target?.Parent;
73-
if (targetParent == null)
71+
var target = Target;
72+
if (target is OpenApiTagReference targetRef && ReferenceEquals(targetRef.Reference, this.Reference))
73+
{
7474
return null;
75-
76-
// Check if the target's parent reference is the same as this reference
77-
if (ReferenceEquals(targetParent.Reference, this.Reference))
78-
return null;
79-
80-
// Check if the target's parent name is the same as this tag's name
81-
if (string.Equals(targetParent.Name, this.Name, StringComparison.OrdinalIgnoreCase))
82-
return null;
83-
84-
return targetParent;
75+
}
76+
77+
return target?.Parent;
8578
}
8679
}
8780

0 commit comments

Comments
 (0)