Skip to content

Commit 0f0e228

Browse files
Update packages, adjust for OpenAPI 2.0 (#674)
1 parent 5fc4e8e commit 0f0e228

File tree

13 files changed

+80
-66
lines changed

13 files changed

+80
-66
lines changed

Engine/Internal/GenHTTP.Engine.Internal.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
<ProjectReference Include="..\..\Modules\IO\GenHTTP.Modules.IO.csproj" />
1717

18-
<PackageReference Include="System.IO.Pipelines" Version="9.0.6" />
18+
<PackageReference Include="System.IO.Pipelines" Version="9.0.7" />
1919

2020
</ItemGroup>
2121

Modules/Authentication/GenHTTP.Modules.Authentication.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
<ProjectReference Include="..\Reflection\GenHTTP.Modules.Reflection.csproj" />
1515

16-
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="8.12.1" />
16+
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="8.13.0" />
1717

18-
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.12.1" />
18+
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.13.0" />
1919

2020
</ItemGroup>
2121

Modules/Basics/GenHTTP.Modules.Basics.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<ProjectReference Include="..\..\API\GenHTTP.Api.csproj" />
1313

14-
<PackageReference Include="System.Text.Json" Version="9.0.6" />
14+
<PackageReference Include="System.Text.Json" Version="9.0.7" />
1515

1616
</ItemGroup>
1717

Modules/Caching/GenHTTP.Modules.Caching.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<ProjectReference Include="..\Basics\GenHTTP.Modules.Basics.csproj" />
1515

16-
<PackageReference Include="System.Text.Json" Version="9.0.6" />
16+
<PackageReference Include="System.Text.Json" Version="9.0.7" />
1717

1818
</ItemGroup>
1919

Modules/Compression/GenHTTP.Modules.Compression.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<ProjectReference Include="..\..\API\GenHTTP.Api.csproj" />
1313

14-
<PackageReference Include="ZstdSharp.Port" Version="0.8.5" />
14+
<PackageReference Include="ZstdSharp.Port" Version="0.8.6" />
1515

1616
</ItemGroup>
1717

Testing/Acceptance/AssertX.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static void DoesNotContain(string searchFor, string? content)
3232

3333
public static void Single<T>(IEnumerable<T> collection) => Assert.IsTrue(collection.Count() == 1);
3434

35-
public static void Empty<T>(IEnumerable<T> collection) => Assert.IsFalse(collection.Any());
35+
public static void Empty<T>(IEnumerable<T>? collection) => Assert.IsFalse(collection?.Any() ?? false);
3636

3737
public static void Contains<T>(T value, IEnumerable<T> collection) => Assert.IsTrue(collection.Contains(value));
3838

Testing/Acceptance/GenHTTP.Testing.Acceptance.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333

3434
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
3535

36-
<PackageReference Include="Microsoft.OpenApi" Version="1.6.24" />
37-
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.6.24" />
36+
<PackageReference Include="Microsoft.OpenApi" Version="2.0.0" />
37+
<PackageReference Include="Microsoft.OpenApi.YamlReader" Version="2.0.0" />
3838

3939
<PackageReference Include="MSTest" Version="3.9.3" />
4040

Testing/Acceptance/Modules/OpenApi/ArgumentTests.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using GenHTTP.Modules.IO;
55
using GenHTTP.Modules.Reflection;
66

7-
using Microsoft.OpenApi.Models;
7+
using Microsoft.OpenApi;
88

99
using Microsoft.VisualStudio.TestTools.UnitTesting;
1010

@@ -63,8 +63,8 @@ public async Task TestBodyParam(TestEngine engine)
6363

6464
Assert.AreEqual("/users/filter", path.Item1);
6565

66-
Assert.IsTrue(operation.RequestBody.Content.ContainsKey("application/json"));
67-
Assert.IsTrue(operation.RequestBody.Content.ContainsKey("text/xml"));
66+
Assert.IsTrue(operation.RequestBody?.Content?.ContainsKey("application/json") ?? false);
67+
Assert.IsTrue(operation.RequestBody?.Content?.ContainsKey("text/xml") ?? false);
6868
}
6969

7070
[TestMethod]
@@ -78,7 +78,7 @@ public async Task TestContentParam(TestEngine engine)
7878

7979
Assert.AreEqual("/users/filter", path.Item1);
8080

81-
Assert.IsTrue(operation.RequestBody.Content.ContainsKey("text/plain"));
81+
Assert.IsTrue(operation.RequestBody?.Content?.ContainsKey("text/plain") ?? false);
8282
}
8383

8484
[TestMethod]
@@ -92,8 +92,8 @@ public async Task TestStreamParam(TestEngine engine)
9292

9393
Assert.AreEqual("/users/avatar", path.Item1);
9494

95-
Assert.IsTrue(operation.RequestBody.Content.ContainsKey("*/*"));
96-
Assert.AreEqual("binary", operation.RequestBody.Content["*/*"].Schema.Format);
95+
Assert.IsTrue(operation.RequestBody?.Content?.ContainsKey("*/*") ?? false);
96+
Assert.AreEqual("binary", operation.RequestBody?.Content?["*/*"].Schema?.Format);
9797
}
9898

9999
[TestMethod]
@@ -112,9 +112,11 @@ public async Task TestWildcardParameter(TestEngine engine)
112112

113113
private static void AssertParameter(OpenApiOperation operation, string name, ParameterLocation location)
114114
{
115-
Assert.AreEqual(1, operation.Parameters.Count);
115+
Assert.AreEqual(1, operation.Parameters?.Count);
116116

117-
var param = operation.Parameters.First();
117+
var param = operation.Parameters?.FirstOrDefault();
118+
119+
Assert.IsNotNull(param);
118120

119121
Assert.AreEqual(name, param.Name);
120122
Assert.AreEqual(location, param.In);

Testing/Acceptance/Modules/OpenApi/DiscoveryTests.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using GenHTTP.Modules.Layouting;
66
using GenHTTP.Modules.OpenApi;
77
using GenHTTP.Modules.OpenApi.Discovery;
8-
using Microsoft.OpenApi.Models;
8+
99
using Microsoft.VisualStudio.TestTools.UnitTesting;
1010

1111
using OpenApiDocument = NSwag.OpenApiDocument;
@@ -26,10 +26,10 @@ public async Task TestTraversal(TestEngine engine)
2626
.AddRangeSupport()
2727
.Add(ApiDescription.Create());
2828

29-
var doc = (await api.GetOpenApiAsync(engine)).OpenApiDocument;
29+
var doc = (await api.GetOpenApiAsync(engine)).Document;
3030

31-
Assert.IsTrue(doc.Paths.ContainsKey("/service/method"));
32-
Assert.IsTrue(doc.Paths.ContainsKey("/method2"));
31+
Assert.IsTrue(doc?.Paths.ContainsKey("/service/method") ?? false);
32+
Assert.IsTrue(doc?.Paths.ContainsKey("/method2") ?? false);
3333
}
3434

3535
[TestMethod]
@@ -40,9 +40,9 @@ public async Task TestCustomExplorer(TestEngine engine)
4040

4141
var api = Inline.Create().Add(ApiDescription.With(discovery));
4242

43-
var doc = (await api.GetOpenApiAsync(engine, false)).OpenApiDocument;
43+
var doc = (await api.GetOpenApiAsync(engine, false)).Document;
4444

45-
Assert.AreEqual("Added by explorer", doc.Servers.First().Description);
45+
Assert.AreEqual("Added by explorer", doc?.Servers?.First().Description);
4646
}
4747

4848
[TestMethod]
@@ -54,16 +54,16 @@ public async Task TestSamePathWithDifferentMethods(TestEngine engine)
5454
.Put("/method", (int i) => i)
5555
.Add(ApiDescription.Create());
5656

57-
var doc = (await api.GetOpenApiAsync(engine)).OpenApiDocument;
57+
var doc = (await api.GetOpenApiAsync(engine)).Document!;
5858

59-
Assert.AreEqual(1, doc.Paths.Count);
59+
Assert.AreEqual(1, doc.Paths?.Count ?? 0);
6060

61-
var operations = doc.Paths.First().Value.Operations;
61+
var operations = doc.Paths?.First().Value.Operations;
6262

63-
Assert.AreEqual(2, operations.Count);
63+
Assert.AreEqual(2, operations?.Count ?? 0);
6464

65-
Assert.IsTrue(operations.ContainsKey(OperationType.Get));
66-
Assert.IsTrue(operations.ContainsKey(OperationType.Put));
65+
Assert.IsTrue(operations?.ContainsKey(HttpMethod.Get));
66+
Assert.IsTrue(operations?.ContainsKey(HttpMethod.Put));
6767
}
6868

6969
#region Supporting data structures

Testing/Acceptance/Modules/OpenApi/Extensions.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
using System.Net;
2+
23
using GenHTTP.Api.Content;
4+
35
using GenHTTP.Modules.Functional.Provider;
46
using GenHTTP.Modules.OpenApi;
5-
using Microsoft.OpenApi.Models;
6-
using Microsoft.OpenApi.Readers;
7+
8+
using Microsoft.OpenApi;
9+
using Microsoft.OpenApi.Reader;
710

811
namespace GenHTTP.Testing.Acceptance.Modules.OpenApi;
912

1013
internal static class Extensions
1114
{
1215

13-
internal static async Task<((string, OpenApiPathItem), OpenApiOperation)> GetOperationAsync(TestEngine engine, InlineBuilder api)
16+
internal static async Task<((string, IOpenApiPathItem), OpenApiOperation)> GetOperationAsync(TestEngine engine, InlineBuilder api)
1417
{
15-
var doc = (await api.Add(ApiDescription.Create()).GetOpenApiAsync(engine)).OpenApiDocument;
18+
var doc = (await api.Add(ApiDescription.Create()).GetOpenApiAsync(engine)).Document!;
1619

1720
var path = doc.Paths.First();
1821

19-
return ((path.Key, path.Value), path.Value.Operations.First().Value);
22+
return ((path.Key, path.Value), path.Value.Operations?.First().Value!);
2023
}
2124

2225
internal static async Task<ReadResult> AsOpenApiAsync(this HttpResponseMessage response)
@@ -25,7 +28,11 @@ internal static async Task<ReadResult> AsOpenApiAsync(this HttpResponseMessage r
2528

2629
await using var content = await response.Content.ReadAsStreamAsync();
2730

28-
return await new OpenApiStreamReader().ReadAsync(content);
31+
var settings = new OpenApiReaderSettings();
32+
33+
settings.AddYamlReader();
34+
35+
return await OpenApiDocument.LoadAsync(content, settings: settings);
2936
}
3037

3138
internal static async Task<ReadResult> GetOpenApiAsync(this IHandlerBuilder api, TestEngine engine, bool validate = true)
@@ -38,8 +45,8 @@ internal static async Task<ReadResult> GetOpenApiAsync(this IHandlerBuilder api,
3845

3946
if (validate)
4047
{
41-
AssertX.Empty(result.OpenApiDiagnostic.Errors);
42-
AssertX.Empty(result.OpenApiDiagnostic.Warnings);
48+
AssertX.Empty(result.Diagnostic?.Errors);
49+
AssertX.Empty(result.Diagnostic?.Warnings);
4350
}
4451

4552
return result;

0 commit comments

Comments
 (0)