Skip to content

Commit eaa77f6

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`. - Mark `SerializeAsV2` as obsolete. - Remove `--serializeasv2` switch (maybe can add it back as an obsolete option that means `--openapiversion 2.0`).
1 parent 7796732 commit eaa77f6

File tree

144 files changed

+6954
-180
lines changed

Some content is hidden

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

144 files changed

+6954
-180
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 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@3951f0dfe7a07e2313ec93c75700083e2005cbab # v4.3.0

Directory.Build.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
TODO Fix warning from Swashbuckle.AspNetCore with dotnet pack
2525
-->
2626
<NoWarn>$(NoWarn);NU5128</NoWarn>
27+
<!-- TODO Remove once .NET 10 is stable -->
28+
<NoWarn>$(NoWarn);NU5104</NoWarn>
2729
<NuGetAuditMode>direct</NuGetAuditMode>
2830
<!--
2931
TODO Go through the code and add nullable annotations

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.2" />
3535
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.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.200",
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+
<TargetFrameworks>net10.0;net8.0</TargetFrameworks>
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,13 @@ private static void ApplySwaggerOperationAttribute(
6363
if (swaggerOperationAttribute.OperationId != null)
6464
operation.OperationId = swaggerOperationAttribute.OperationId;
6565

66+
// TODO Fix this
67+
#if !NET10_0_OR_GREATER
6668
if (swaggerOperationAttribute.Tags != null)
6769
{
6870
operation.Tags = [.. swaggerOperationAttribute.Tags.Select(tagName => new OpenApiTag { Name = tagName })];
6971
}
72+
#endif
7073
}
7174

7275
public static void ApplySwaggerOperationFilterAttributes(

src/Swashbuckle.AspNetCore.Annotations/SwaggerResponseAttribute.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ public SwaggerResponseAttribute(int statusCode, string description = null, Type
2222
ContentTypes = contentTypes;
2323
}
2424

25+
#if !NET10_0_OR_GREATER
2526
/// <summary>
2627
/// A short description of the response. GFM syntax can be used for rich text representation.
2728
/// </summary>
2829
public string Description { get; set; }
30+
#endif
2931

3032
/// <summary>
3133
/// A collection of MIME types that the response can be produced with.

src/Swashbuckle.AspNetCore.Annotations/Swashbuckle.AspNetCore.Annotations.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<NoWarn>$(NoWarn);1591</NoWarn>
99
<PackageTags>swagger;documentation;discovery;help;webapi;aspnet;aspnetcore;annotations</PackageTags>
1010
<SignAssembly>true</SignAssembly>
11-
<TargetFrameworks>net9.0;net8.0;net6.0;netstandard2.0</TargetFrameworks>
11+
<TargetFrameworks>net10.0;net9.0;net8.0;net6.0;netstandard2.0</TargetFrameworks>
1212
</PropertyGroup>
1313

1414
<ItemGroup>

0 commit comments

Comments
 (0)