Skip to content

Commit

Permalink
Fix reading relative path file reference
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dldl-cmd committed Feb 4, 2025
1 parent 4821b92 commit e8feab0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Microsoft.OpenApi/Reader/V3/OpenApiV3Deserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,11 @@ private static (string, string) GetReferenceIdAndExternalResource(string pointer
var refId = refSegments.Last();
var isExternalResource = !refSegments.First().StartsWith("#", StringComparison.OrdinalIgnoreCase);

string externalResource = isExternalResource ? $"{refSegments.First()}/{refSegments[1].TrimEnd('#')}" : null;
string externalResource = null;
if (isExternalResource)
{
externalResource = pointer.Split('#').FirstOrDefault()?.TrimEnd('#');
}

return (refId, externalResource);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi/Reader/V31/OpenApiV31Deserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private static (string, string) GetReferenceIdAndExternalResource(string pointer
string externalResource = null;
if (isExternalResource && pointer.Contains('#'))
{
externalResource = $"{refSegments.First()}/{refSegments[1].TrimEnd('#')}";
externalResource = pointer.Split('#').FirstOrDefault()?.TrimEnd('#');
}

return (refId, externalResource);
Expand Down

0 comments on commit e8feab0

Please sign in to comment.