Skip to content

Commit 18458de

Browse files
Support .NET 10
- Add support for ASP.NET Core 10 and Microsoft.OpenApi v2. - Add opt-in support for OpenAPI 3.1 when targeting `net10.0`.
1 parent 8fe3238 commit 18458de

File tree

189 files changed

+8468
-150
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

189 files changed

+8468
-150
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ jobs:
5353
dotnet-version: |
5454
6.0.x
5555
8.0.x
56+
9.0.x
5657
5758
- name: Setup .NET SDK
5859
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4.3.1
@@ -149,6 +150,7 @@ jobs:
149150
if: |
150151
github.event.repository.fork == false &&
151152
(github.ref_name == github.event.repository.default_branch ||
153+
github.head_ref == 'dotnet-vnext' ||
152154
startsWith(github.ref, 'refs/tags/v'))
153155
154156
environment:

Directory.Build.props

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
TODO Fix warning from Swashbuckle.AspNetCore with dotnet pack
2222
-->
2323
<NoWarn>$(NoWarn);NU5128</NoWarn>
24+
<!-- TODO Remove once .NET 10 is stable -->
25+
<NoWarn>$(NoWarn);NU5104</NoWarn>
2426
<NuGetAuditMode>direct</NuGetAuditMode>
2527
<!--
2628
TODO Go through the code and add nullable annotations
@@ -39,7 +41,7 @@
3941
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
4042
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
4143
<UseArtifactsOutput>true</UseArtifactsOutput>
42-
<VersionPrefix>8.1.0</VersionPrefix>
44+
<VersionPrefix>9.0.0</VersionPrefix>
4345
<WarnOnPackingNonPackableProject>false</WarnOnPackingNonPackableProject>
4446
</PropertyGroup>
4547
<PropertyGroup Condition=" '$(GITHUB_ACTIONS)' != '' AND '$(DEPENDABOT_JOB_ID)' == '' ">

Directory.Packages.props

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,9 @@
3434
<PackageVersion Include="xunit.core" Version="2.9.3" />
3535
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.2" />
3636
</ItemGroup>
37+
<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net10.0'))">
38+
<PackageVersion Update="Microsoft.AspNetCore.OpenApi" Version="10.0.0-preview.1.25120.3" />
39+
<PackageVersion Update="Microsoft.OpenApi" Version="2.0.0-preview5" />
40+
<PackageVersion Update="Microsoft.OpenApi.Readers" Version="2.0.0-preview5" />
41+
</ItemGroup>
3742
</Project>

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "9.0.202",
3+
"version": "10.0.100-preview.1.25120.13",
44
"allowPrerelease": false,
55
"rollForward": "latestMajor"
66
}

perf/Swashbuckle.AspNetCore.Benchmarks/Swashbuckle.AspNetCore.Benchmarks.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<IsPackable>false</IsPackable>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net8.0</TargetFramework>
5+
<TargetFramework>net10.0</TargetFramework>
66
</PropertyGroup>
77
<ItemGroup>
88
<Compile Include="..\..\src\Shared\JsonSchemaTypes.cs" Link="JsonSchemaTypes.cs" />

src/Shared/JsonExtensions.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#if NET10_0_OR_GREATER
2+
using System.Text.Json;
3+
using System.Text.Json.Nodes;
4+
5+
namespace Swashbuckle.AspNetCore;
6+
7+
internal static class JsonExtensions
8+
{
9+
private static readonly JsonSerializerOptions Options = new()
10+
{
11+
NewLine = "\n",
12+
WriteIndented = true,
13+
};
14+
15+
public static string ToJson(this JsonNode value)
16+
=> value.ToJsonString(Options);
17+
}
18+
#endif

src/Shared/JsonSchemaTypes.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1+
#if NET10_0_OR_GREATER
2+
using Microsoft.OpenApi.Models;
3+
#endif
4+
15
namespace Swashbuckle.AspNetCore;
26

37
internal static class JsonSchemaTypes
48
{
9+
#if NET10_0_OR_GREATER
10+
public static readonly JsonSchemaType Array = JsonSchemaType.Array;
11+
public static readonly JsonSchemaType Boolean = JsonSchemaType.Boolean;
12+
public static readonly JsonSchemaType Integer = JsonSchemaType.Integer;
13+
public static readonly JsonSchemaType Number = JsonSchemaType.Number;
14+
public static readonly JsonSchemaType Null = JsonSchemaType.Null;
15+
public static readonly JsonSchemaType Object = JsonSchemaType.Object;
16+
public static readonly JsonSchemaType String = JsonSchemaType.String;
17+
#else
518
public const string Array = "array";
619
public const string Boolean = "boolean";
720
public const string Integer = "integer";
821
public const string Number = "number";
922
public const string Null = "null";
1023
public const string Object = "object";
1124
public const string String = "string";
25+
#endif
1226
}

src/Swashbuckle.AspNetCore.Annotations/AnnotationsOperationFilter.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
using Microsoft.OpenApi.Models;
22
using Swashbuckle.AspNetCore.SwaggerGen;
33

4+
#if NET10_0
5+
using OpenApiTag = Microsoft.OpenApi.Models.References.OpenApiTagReference;
6+
#else
7+
using OpenApiTag = Microsoft.OpenApi.Models.OpenApiTag;
8+
#endif
9+
410
namespace Swashbuckle.AspNetCore.Annotations;
511

612
public class AnnotationsOperationFilter : IOperationFilter
@@ -71,7 +77,11 @@ private static void ApplySwaggerOperationAttribute(
7177

7278
if (swaggerOperationAttribute.Tags is { } tags)
7379
{
80+
#if NET10_0_OR_GREATER
81+
operation.Tags = [.. tags.Select(tagName => new OpenApiTag(tagName, null))];
82+
#else
7483
operation.Tags = [.. tags.Select(tagName => new OpenApiTag { Name = tagName })];
84+
#endif
7585
}
7686
}
7787

0 commit comments

Comments
 (0)