From f04d45e11930cf1779a45ee1f54b72a749e8f016 Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Tue, 1 Oct 2024 12:19:02 +0300 Subject: [PATCH 1/4] se workspace baseUrl to settings.BaseUrl --- src/Microsoft.OpenApi/Reader/OpenApiJsonReader.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi/Reader/OpenApiJsonReader.cs b/src/Microsoft.OpenApi/Reader/OpenApiJsonReader.cs index b01a5644e..ba7e1276b 100644 --- a/src/Microsoft.OpenApi/Reader/OpenApiJsonReader.cs +++ b/src/Microsoft.OpenApi/Reader/OpenApiJsonReader.cs @@ -192,7 +192,9 @@ private JsonNode LoadJsonNodes(TextReader input) private async Task 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); From 5046131cdea8851baef9285198ec0ad9a3776cc5 Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Tue, 1 Oct 2024 12:19:50 +0300 Subject: [PATCH 2/4] Use current working directory to resolve file path --- .../Reader/Services/DefaultStreamLoader.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi/Reader/Services/DefaultStreamLoader.cs b/src/Microsoft.OpenApi/Reader/Services/DefaultStreamLoader.cs index dba3c6811..71e26709e 100644 --- a/src/Microsoft.OpenApi/Reader/Services/DefaultStreamLoader.cs +++ b/src/Microsoft.OpenApi/Reader/Services/DefaultStreamLoader.cs @@ -56,7 +56,16 @@ public Stream Load(Uri uri) /// public async Task LoadAsync(Uri uri) { - var absoluteUri = new Uri(baseUrl, uri); + Uri absoluteUri; + if (baseUrl.Equals(OpenApiConstants.BaseRegistryUri)) + { + // use current working directory + absoluteUri = new Uri(Directory.GetCurrentDirectory() + uri); + } + else + { + absoluteUri = new Uri(baseUrl, uri); + } switch (absoluteUri.Scheme) { From e85e4780824002c3932435b5e32d4fe62ffe15f2 Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Tue, 1 Oct 2024 12:25:49 +0300 Subject: [PATCH 3/4] Clean up --- src/Microsoft.OpenApi/Reader/OpenApiJsonReader.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Microsoft.OpenApi/Reader/OpenApiJsonReader.cs b/src/Microsoft.OpenApi/Reader/OpenApiJsonReader.cs index ba7e1276b..fd17a3643 100644 --- a/src/Microsoft.OpenApi/Reader/OpenApiJsonReader.cs +++ b/src/Microsoft.OpenApi/Reader/OpenApiJsonReader.cs @@ -193,7 +193,6 @@ private async Task LoadExternalRefs(OpenApiDocument document, { // Create workspace for all documents to live in. var baseUrl = settings.BaseUrl ?? new Uri(OpenApiConstants.BaseRegistryUri); - var openApiWorkSpace = new OpenApiWorkspace(baseUrl); // Load this root document into the workspace From c3fac4edce6a29a77e3fdcebcfb6be7bff8cee09 Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Tue, 1 Oct 2024 12:39:37 +0300 Subject: [PATCH 4/4] Use ternary operator --- .../Reader/Services/DefaultStreamLoader.cs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.OpenApi/Reader/Services/DefaultStreamLoader.cs b/src/Microsoft.OpenApi/Reader/Services/DefaultStreamLoader.cs index 71e26709e..7c8888abb 100644 --- a/src/Microsoft.OpenApi/Reader/Services/DefaultStreamLoader.cs +++ b/src/Microsoft.OpenApi/Reader/Services/DefaultStreamLoader.cs @@ -57,15 +57,8 @@ public Stream Load(Uri uri) public async Task LoadAsync(Uri uri) { Uri absoluteUri; - if (baseUrl.Equals(OpenApiConstants.BaseRegistryUri)) - { - // use current working directory - absoluteUri = new Uri(Directory.GetCurrentDirectory() + uri); - } - else - { - absoluteUri = new Uri(baseUrl, uri); - } + absoluteUri = baseUrl.AbsoluteUri.Equals(OpenApiConstants.BaseRegistryUri) ? new Uri(Directory.GetCurrentDirectory() + uri) + : new Uri(baseUrl, uri); switch (absoluteUri.Scheme) {