Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Set workspace baseUrl when creating a workspace #1849

Merged
merged 4 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
3 changes: 2 additions & 1 deletion src/Microsoft.OpenApi/Reader/OpenApiJsonReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ private JsonNode LoadJsonNodes(TextReader input)
private async Task<OpenApiDiagnostic> LoadExternalRefs(OpenApiDocument document, CancellationToken cancellationToken, OpenApiReaderSettings settings, string format = null)
{
// Create workspace for all documents to live in.
var openApiWorkSpace = new OpenApiWorkspace();
var baseUrl = settings.BaseUrl ?? new Uri(OpenApiConstants.BaseRegistryUri);
var openApiWorkSpace = new OpenApiWorkspace(baseUrl);

// Load this root document into the workspace
var streamLoader = new DefaultStreamLoader(settings.BaseUrl);
Expand Down
11 changes: 10 additions & 1 deletion src/Microsoft.OpenApi/Reader/Services/DefaultStreamLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,16 @@
/// <exception cref="ArgumentException"></exception>
public async Task<Stream> LoadAsync(Uri uri)
{
var absoluteUri = new Uri(baseUrl, uri);
Uri absoluteUri;
if (baseUrl.Equals(OpenApiConstants.BaseRegistryUri))
Fixed Show fixed Hide fixed
{
// use current working directory
absoluteUri = new Uri(Directory.GetCurrentDirectory() + uri);
}
else
{
absoluteUri = new Uri(baseUrl, uri);
}
Fixed Show fixed Hide fixed

switch (absoluteUri.Scheme)
{
Expand Down
Loading