Skip to content

Commit 4e1305a

Browse files
committed
Fix some .NET 7 preprocessor symbols
1 parent 09a08d7 commit 4e1305a

3 files changed

Lines changed: 31 additions & 3 deletions

File tree

src/Swashbuckle.AspNetCore.ReDoc/ReDocMiddleware.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public ReDocMiddleware(
4141

4242
_jsonSerializerOptions = new JsonSerializerOptions();
4343

44-
#if NET6_0
44+
#if NET6_0_OR_GREATER
4545
_jsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;
4646
#else
4747
_jsonSerializerOptions.IgnoreNullValues = true;

src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIMiddleware.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public SwaggerUIMiddleware(
4242
_staticFileMiddleware = CreateStaticFileMiddleware(next, hostingEnv, loggerFactory, options);
4343

4444
_jsonSerializerOptions = new JsonSerializerOptions();
45-
#if NET6_0
45+
#if NET6_0_OR_GREATER
4646
_jsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;
4747
#else
4848
_jsonSerializerOptions.IgnoreNullValues = true;

test/Swashbuckle.AspNetCore.Cli.Test/ToolTests.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void Can_Generate_Swagger_Json()
3535
}
3636
}
3737

38-
#if NET6_0
38+
#if NET6_0_OR_GREATER
3939
[Fact]
4040
public void Can_Generate_Swagger_Json_ForTopLevelApp()
4141
{
@@ -58,5 +58,33 @@ public void Can_Generate_Swagger_Json_ForTopLevelApp()
5858
}
5959
}
6060
#endif
61+
62+
#if NET7_0_OR_GREATER
63+
[Fact]
64+
public void Can_Generate_Swagger_Json_ForMinimalApiEndpoints()
65+
{
66+
var dir = Directory.CreateDirectory(Path.Join(Path.GetTempPath(), Path.GetRandomFileName()));
67+
try
68+
{
69+
var args = new string[] { "tofile", "--output", $"{dir}/swagger.json", "--serializeasv2", Path.Combine(Directory.GetCurrentDirectory(), "MinimalApiEndpoints.dll"), "v1" };
70+
Assert.Equal(0, Program.Main(args));
71+
72+
// using var document = JsonDocument.Parse(File.ReadAllText(Path.Combine(dir.FullName, "swagger.json")));
73+
using var document = JsonDocument.Parse(File.ReadAllText(Path.Combine(dir.FullName, "swagger.json")));
74+
75+
// verify one of the endpoints
76+
var paths = document.RootElement.GetProperty("paths");
77+
var controllerPath = paths.GetProperty("/helloController");
78+
Assert.True(controllerPath.TryGetProperty("get", out _));
79+
80+
var endpointPath = paths.GetProperty("/helloEndpoint");
81+
Assert.True(endpointPath.TryGetProperty("get", out _));
82+
}
83+
finally
84+
{
85+
dir.Delete(true);
86+
}
87+
}
88+
#endif
6189
}
6290
}

0 commit comments

Comments
 (0)