Skip to content

Commit 7bd9c5e

Browse files
committed
chore: updates performance tests to work with v1
Signed-off-by: Vincent Biret <[email protected]>
1 parent 2db224e commit 7bd9c5e

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

performance/benchmark/Descriptions.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using BenchmarkDotNet.Attributes;
88
using Microsoft.OpenApi;
99
using Microsoft.OpenApi.Models;
10-
using Microsoft.OpenApi.Reader;
10+
using Microsoft.OpenApi.Readers;
1111

1212
namespace performance;
1313

@@ -24,7 +24,7 @@ public async Task<OpenApiDocument> PetStoreYaml()
2424
[Benchmark]
2525
public async Task<OpenApiDocument> PetStoreJson()
2626
{
27-
return await ParseDocumentAsync(PetStoreJsonPath, OpenApiConstants.Json);
27+
return await ParseDocumentAsync(PetStoreJsonPath);
2828
}
2929
[Benchmark]
3030
public async Task<OpenApiDocument> GHESYaml()
@@ -34,7 +34,7 @@ public async Task<OpenApiDocument> GHESYaml()
3434
[Benchmark]
3535
public async Task<OpenApiDocument> GHESJson()
3636
{
37-
return await ParseDocumentAsync(GHESJsonDescriptionUrl, OpenApiConstants.Json);
37+
return await ParseDocumentAsync(GHESJsonDescriptionUrl);
3838
}
3939
private readonly Dictionary<string, MemoryStream> _streams = new(StringComparer.OrdinalIgnoreCase);
4040
[GlobalSetup]
@@ -45,7 +45,6 @@ public async Task GetAllDescriptions()
4545
{
4646
LeaveStreamOpen = true,
4747
};
48-
readerSettings.AddYamlReader();
4948
await LoadDocumentFromAssemblyIntoStreams(PetStoreYamlPath);
5049
await LoadDocumentFromAssemblyIntoStreams(PetStoreJsonPath);
5150
await LoadDocumentFromUrlIntoStreams(GHESYamlDescriptionUrl);
@@ -56,14 +55,14 @@ public async Task GetAllDescriptions()
5655
private const string PetStoreJsonPath = @"petStore.json";
5756
private const string GHESYamlDescriptionUrl = @"https://raw.githubusercontent.com/github/rest-api-description/aef5e31a2d10fdaab311ec6d18a453021a81383d/descriptions/ghes-3.16/ghes-3.16.2022-11-28.yaml";
5857
private const string GHESJsonDescriptionUrl = @"https://raw.githubusercontent.com/github/rest-api-description/aef5e31a2d10fdaab311ec6d18a453021a81383d/descriptions/ghes-3.16/ghes-3.16.2022-11-28.json";
59-
private async Task<OpenApiDocument> ParseDocumentAsync(string fileName, string format = null)
58+
private async Task<OpenApiDocument> ParseDocumentAsync(string fileName)
6059
{
61-
format ??= OpenApiConstants.Yaml;
6260
var stream = _streams[fileName];
6361
stream.Seek(0, SeekOrigin.Begin);
62+
var reader = new OpenApiStreamReader(readerSettings);
6463

65-
var (document, _) = await OpenApiDocument.LoadAsync(stream, format, readerSettings).ConfigureAwait(false);
66-
return document;
64+
var result = await reader.ReadAsync(stream).ConfigureAwait(false);
65+
return result.OpenApiDocument;
6766
}
6867
private HttpClient _httpClient;
6968
private async Task LoadDocumentFromUrlIntoStreams(string url)

performance/benchmark/PerformanceTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</ItemGroup>
2020
<ItemGroup>
2121
<ProjectReference Include="..\..\src\Microsoft.OpenApi\Microsoft.OpenApi.csproj" />
22-
<ProjectReference Include="..\..\src\Microsoft.OpenApi.YamlReader\Microsoft.OpenApi.YamlReader.csproj" />
22+
<ProjectReference Include="..\..\src\Microsoft.OpenApi.Readers\Microsoft.OpenApi.Readers.csproj" />
2323
</ItemGroup>
2424
<ItemGroup>
2525
<EmbeddedResource Include="..\..\test\Microsoft.OpenApi.Readers.Tests\V3Tests\Samples\OpenApiDocument\petStore.yaml" />

0 commit comments

Comments
 (0)