Skip to content

Commit e8feab0

Browse files
committed
Fix reading relative path file reference
A reference like ./Directory/File.json#/components/schema/abc was before read as: refId = abc externalResource = ./Directory Which dropped the file name, which will be fixed by this commit
1 parent 4821b92 commit e8feab0

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/Microsoft.OpenApi/Reader/V3/OpenApiV3Deserializer.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,11 @@ private static (string, string) GetReferenceIdAndExternalResource(string pointer
193193
var refId = refSegments.Last();
194194
var isExternalResource = !refSegments.First().StartsWith("#", StringComparison.OrdinalIgnoreCase);
195195

196-
string externalResource = isExternalResource ? $"{refSegments.First()}/{refSegments[1].TrimEnd('#')}" : null;
196+
string externalResource = null;
197+
if (isExternalResource)
198+
{
199+
externalResource = pointer.Split('#').FirstOrDefault()?.TrimEnd('#');
200+
}
197201

198202
return (refId, externalResource);
199203
}

src/Microsoft.OpenApi/Reader/V31/OpenApiV31Deserializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private static (string, string) GetReferenceIdAndExternalResource(string pointer
165165
string externalResource = null;
166166
if (isExternalResource && pointer.Contains('#'))
167167
{
168-
externalResource = $"{refSegments.First()}/{refSegments[1].TrimEnd('#')}";
168+
externalResource = pointer.Split('#').FirstOrDefault()?.TrimEnd('#');
169169
}
170170

171171
return (refId, externalResource);

0 commit comments

Comments
 (0)