Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix reading relative path file reference #2119

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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