Skip to content

Commit 3510c72

Browse files
committed
chore: adds a check that we have matching segments for path generation
Signed-off-by: Vincent Biret <[email protected]>
1 parent c53165c commit 3510c72

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/Microsoft.OpenApi/Models/BaseOpenApiReference.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,11 @@ private static string ResolveRelativePointer(string nodeLocation, string relativ
328328
// Locate the first occurrence of relativeRef segments in the full path
329329
for (int i = 0; i <= nodeLocationSegments.Count - relativeSegments.Length; i++)
330330
{
331-
if (relativeSegments.SequenceEqual(nodeLocationSegments.Skip(i).Take(relativeSegments.Length), StringComparer.Ordinal))
331+
if (relativeSegments.SequenceEqual(nodeLocationSegments.Skip(i).Take(relativeSegments.Length), StringComparer.Ordinal) &&
332+
nodeLocationSegments.Take(i + relativeSegments.Length).ToArray() is {Length: > 0} matchingSegments)
332333
{
333334
// Trim to include just the matching segment chain
334-
return $"#/{string.Join("/", [.. nodeLocationSegments.Take(i + relativeSegments.Length)])}";
335+
return $"#/{string.Join("/", matchingSegments)}";
335336
}
336337
}
337338

0 commit comments

Comments
 (0)