Skip to content

Commit 0f23798

Browse files
committed
fix: avoid creating new http clients to load additional documents of the workspace
Signed-off-by: Vincent Biret <[email protected]>
1 parent f257ad5 commit 0f23798

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/Microsoft.OpenApi/Reader/OpenApiModelFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ private static async Task<OpenApiDiagnostic> LoadExternalRefsAsync(OpenApiDocume
263263
var openApiWorkSpace = new OpenApiWorkspace(baseUrl);
264264

265265
// Load this root document into the workspace
266-
var streamLoader = new DefaultStreamLoader(settings.BaseUrl);
266+
var streamLoader = new DefaultStreamLoader(settings.BaseUrl, settings.HttpClient);
267267
var workspaceLoader = new OpenApiWorkspaceLoader(openApiWorkSpace, settings.CustomExternalLoader ?? streamLoader, settings);
268268
return await workspaceLoader.LoadAsync(new OpenApiReference() { ExternalResource = "/" }, document, format ?? OpenApiConstants.Json, null, token).ConfigureAwait(false);
269269
}

src/Microsoft.OpenApi/Reader/Services/DefaultStreamLoader.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@ namespace Microsoft.OpenApi.Reader.Services
1818
public class DefaultStreamLoader : IStreamLoader
1919
{
2020
private readonly Uri baseUrl;
21-
private readonly HttpClient _httpClient = new();
21+
private readonly HttpClient _httpClient;
2222

2323
/// <summary>
2424
/// The default stream loader
2525
/// </summary>
2626
/// <param name="baseUrl"></param>
27-
public DefaultStreamLoader(Uri baseUrl)
27+
/// <param name="httpClient">The HttpClient to use to retrieve documents when needed</param>
28+
public DefaultStreamLoader(Uri baseUrl, HttpClient httpClient)
2829
{
2930
this.baseUrl = baseUrl;
31+
_httpClient = Utils.CheckArgumentNull(httpClient);
3032
}
3133

3234
/// <inheritdoc/>

0 commit comments

Comments
 (0)