Skip to content

Commit 2c1b0b0

Browse files
committed
[up] upgrade to net10.0 only and Swashbuckle.AspNetCore 10.2.1
* Dropped net8.0 and net9.0 target frameworks * Upgraded Swashbuckle.AspNetCore.SwaggerGen to 10.2.1 * Removed #if NET10_0 preprocessor directives
1 parent dc08c42 commit 2c1b0b0

8 files changed

Lines changed: 6 additions & 132 deletions

src/Simplify.Web.Swagger/ControllerAction.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
using System;
22
using System.Collections.Generic;
3-
#if NET10_0
43
using Microsoft.OpenApi;
54
using NetHttpMethod = System.Net.Http.HttpMethod;
6-
#else
7-
using Microsoft.OpenApi.Models;
8-
#endif
95
using Simplify.Web.Controllers.Meta.Routing;
106

117
namespace Simplify.Web.Swagger;
@@ -46,25 +42,16 @@ public class ControllerAction
4642
/// <value>
4743
/// The type.
4844
/// </value>
49-
#if NET10_0
5045
public NetHttpMethod Type { get; set; } = NetHttpMethod.Get;
51-
#else
52-
public OperationType Type { get; set; }
53-
#endif
5446

5547
/// <summary>
5648
/// Gets the path.
5749
/// </summary>
5850
/// <value>
5951
/// The path.
6052
/// </value>
61-
#if NETSTANDARD2_0
62-
public string Path => ControllerRoute.Path.StartsWith("/") ? ControllerRoute.Path : "/" + ControllerRoute.Path;
63-
#else
6453
public string Path => ControllerRoute.Path.StartsWith('/') ? ControllerRoute.Path : "/" + ControllerRoute.Path;
6554

66-
#endif
67-
6855
/// <summary>
6956
/// Gets or sets the controller route.
7057
/// </summary>

src/Simplify.Web.Swagger/ControllerActionsFactory.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@
77
using Simplify.Web.Controllers.Meta.Routing;
88
using Simplify.Web.Http;
99
using Swashbuckle.AspNetCore.SwaggerGen;
10-
#if NET10_0
1110
using Microsoft.OpenApi;
1211
using NetHttpMethod = System.Net.Http.HttpMethod;
13-
#else
14-
using Microsoft.OpenApi.Models;
15-
#endif
1612

1713
namespace Simplify.Web.Swagger;
1814

@@ -127,7 +123,6 @@ private static string FormatNameSource(string str)
127123
return str;
128124
}
129125

130-
#if NET10_0
131126
private static NetHttpMethod HttpMethodToOperationType(HttpMethod method) =>
132127
method switch
133128
{
@@ -139,19 +134,6 @@ private static NetHttpMethod HttpMethodToOperationType(HttpMethod method) =>
139134
HttpMethod.Options => NetHttpMethod.Options,
140135
_ => NetHttpMethod.Get,
141136
};
142-
#else
143-
private static OperationType HttpMethodToOperationType(HttpMethod method) =>
144-
method switch
145-
{
146-
HttpMethod.Get => OperationType.Get,
147-
HttpMethod.Post => OperationType.Post,
148-
HttpMethod.Put => OperationType.Put,
149-
HttpMethod.Patch => OperationType.Patch,
150-
HttpMethod.Delete => OperationType.Delete,
151-
HttpMethod.Options => OperationType.Options,
152-
_ => OperationType.Get,
153-
};
154-
#endif
155137

156138
private static OpenApiRequestBody CreateRequestBody(
157139
Type controllerType,
@@ -205,9 +187,7 @@ DocumentFilterContext context
205187

206188
foreach (var item in producesResponse.ContentTypes.Distinct())
207189
{
208-
#if NET10_0
209190
response.Content ??= new Dictionary<string, OpenApiMediaType>();
210-
#endif
211191
response.Content.Add(
212192
item,
213193
producesResponse.Type is null

src/Simplify.Web.Swagger/EnumNamesSchemaFilter.cs

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
using System;
2-
using System.Linq;
3-
using Swashbuckle.AspNetCore.SwaggerGen;
4-
#if NET10_0
52
using System.Collections.Generic;
3+
using System.Linq;
64
using System.Text.Json.Nodes;
75
using Microsoft.OpenApi;
8-
#else
9-
using Microsoft.OpenApi.Any;
10-
using Microsoft.OpenApi.Models;
11-
#endif
6+
using Swashbuckle.AspNetCore.SwaggerGen;
127

138
namespace Simplify.Web.Swagger;
149

@@ -18,7 +13,6 @@ namespace Simplify.Web.Swagger;
1813
public class EnumNamesSchemaFilter : ISchemaFilter
1914
{
2015
/// <inheritdoc />
21-
#if NET10_0
2216
public void Apply(IOpenApiSchema schema, SchemaFilterContext context)
2317
{
2418
if (!context.Type.IsEnum)
@@ -38,23 +32,6 @@ public void Apply(IOpenApiSchema schema, SchemaFilterContext context)
3832
concreteSchema.Extensions["x-varnames"] = new JsonNodeExtension(varnames);
3933
concreteSchema.Description = BuildDescription(names, values);
4034
}
41-
#else
42-
public void Apply(OpenApiSchema schema, SchemaFilterContext context)
43-
{
44-
if (!context.Type.IsEnum)
45-
return;
46-
47-
var names = Enum.GetNames(context.Type);
48-
var values = Enum.GetValues(context.Type).Cast<object>().ToArray();
49-
50-
var varnames = new OpenApiArray();
51-
foreach (var name in names)
52-
varnames.Add(new OpenApiString(name));
53-
54-
schema.Extensions["x-varnames"] = varnames;
55-
schema.Description = BuildDescription(names, values);
56-
}
57-
#endif
5835

5936
private static string BuildDescription(string[] names, object[] values) =>
6037
string.Join(", ", names.Select((name, i) => $"{Convert.ToInt64(values[i])} = {name}"));

src/Simplify.Web.Swagger/Simplify.Web.Swagger.csproj

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,10 @@
2424

2525
<PackageReleaseNotes>See https://github.com/SimplifyNet/Simplify.Web.Swagger/tree/master/src/Simplify.Web.Swagger/CHANGELOG.md for details</PackageReleaseNotes>
2626
</PropertyGroup>
27-
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' Or '$(TargetFramework)' == 'net9.0' Or '$(TargetFramework)' == 'net10.0' ">
27+
<ItemGroup>
2828
<PackageReference Include="Asp.Versioning.Mvc" Version="8.1.1" />
29-
</ItemGroup>
30-
<ItemGroup Condition=" '$(TargetFramework)' == 'net10.0' ">
3129
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="10.2.1" />
3230
</ItemGroup>
33-
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' Or '$(TargetFramework)' == 'net9.0' ">
34-
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="9.0.6" />
35-
</ItemGroup>
3631
<ItemGroup>
3732
<PackageReference Include="Simplify.Web" Version="5.2" />
3833
</ItemGroup>

src/Simplify.Web.Swagger/SimplifyWebDocumentFilter.cs

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@
33
using System.Linq;
44
using Simplify.Web.Controllers.Meta.Routing;
55
using Swashbuckle.AspNetCore.SwaggerGen;
6-
#if NET10_0
76
using Microsoft.OpenApi;
87
using JsonNode = System.Text.Json.Nodes.JsonNode;
9-
#else
10-
using Microsoft.OpenApi.Models;
11-
#endif
128

139
namespace Simplify.Web.Swagger;
1410

@@ -55,19 +51,11 @@ var item in controllerActions
5551
PopulateDocumentTags(swaggerDoc, controllerActions);
5652
}
5753

58-
#if NET10_0
5954
private static IList<IOpenApiParameter> CreateParameters(ControllerAction item, DocumentFilterContext context) =>
6055
item.ControllerRoute.Items
6156
.OfType<PathParameter>()
6257
.Select(x => (IOpenApiParameter)CreatePathParameter(x, item, context))
6358
.ToList();
64-
#else
65-
private static IList<OpenApiParameter> CreateParameters(ControllerAction item, DocumentFilterContext context) =>
66-
item.ControllerRoute.Items
67-
.OfType<PathParameter>()
68-
.Select(x => CreatePathParameter(x, item, context))
69-
.ToList();
70-
#endif
7159

7260
private static OpenApiParameter CreatePathParameter(PathParameter pathParam, ControllerAction item, DocumentFilterContext context)
7361
{
@@ -103,21 +91,15 @@ private OpenApiOperation CreateOperation(ControllerAction item, OpenApiDocument
10391
{
10492
var operation = new OpenApiOperation();
10593

106-
#if NET10_0
10794
operation.Tags ??= new HashSet<OpenApiTagReference>();
10895
operation.Tags.Add(new OpenApiTagReference(item.Names.GroupName));
109-
#else
110-
operation.Tags.Add(new OpenApiTag { Name = item.Names.GroupName });
111-
#endif
11296

11397
if (item.Names.Summary != null)
11498
operation.Summary = item.Names.Summary;
11599

116100
foreach (var response in item.Responses)
117101
{
118-
#if NET10_0
119102
operation.Responses ??= new OpenApiResponses();
120-
#endif
121103
operation.Responses.Add(response.Key.ToString(), response.Value);
122104
}
123105

@@ -130,33 +112,13 @@ private OpenApiOperation CreateOperation(ControllerAction item, OpenApiDocument
130112
{
131113
var schemeNames = ResolveSecuritySchemeNames(swaggerDoc);
132114

133-
#if NET10_0
134115
if (schemeNames.Count > 0)
135116
operation.Security = schemeNames
136117
.Select(name => new OpenApiSecurityRequirement
137118
{
138119
[new OpenApiSecuritySchemeReference(name, swaggerDoc)] = [],
139120
})
140121
.ToList();
141-
#else
142-
if (schemeNames.Count > 0)
143-
operation.Security = schemeNames
144-
.Select(name => new OpenApiSecurityRequirement
145-
{
146-
{
147-
new OpenApiSecurityScheme
148-
{
149-
Reference = new OpenApiReference
150-
{
151-
Type = ReferenceType.SecurityScheme,
152-
Id = name,
153-
},
154-
},
155-
new List<string>()
156-
},
157-
})
158-
.ToList();
159-
#endif
160122
}
161123

162124
if (_args == null)
@@ -190,21 +152,12 @@ private static OpenApiParameter CreateAcceptLanguageParameter(AcceptLanguageHead
190152
AllowEmptyValue = true,
191153
};
192154

193-
#if NET10_0
194155
param.Example = args.Default;
195156
param.Schema = new OpenApiSchema
196157
{
197158
Default = args.Default,
198159
Enum = args.Languages.Select(l => (JsonNode)l).ToList()
199160
};
200-
#else
201-
param.Example = new Microsoft.OpenApi.Any.OpenApiString(args.Default);
202-
param.Schema = new OpenApiSchema
203-
{
204-
Default = new Microsoft.OpenApi.Any.OpenApiString(args.Default),
205-
Enum = args.Languages.Select(l => (Microsoft.OpenApi.Any.IOpenApiAny)new Microsoft.OpenApi.Any.OpenApiString(l)).ToList()
206-
};
207-
#endif
208161

209162
return param;
210163
}
@@ -214,12 +167,8 @@ private static void PopulateDocumentTags(
214167
IEnumerable<ControllerAction> actions
215168
)
216169
{
217-
#if NET10_0
218170
var existingNames =
219171
swaggerDoc.Tags?.Select(t => t.Name).ToHashSet(StringComparer.Ordinal) ?? [];
220-
#else
221-
var existingNames = swaggerDoc.Tags.Select(t => t.Name).ToHashSet(StringComparer.Ordinal);
222-
#endif
223172

224173
foreach (
225174
var name in actions
@@ -228,9 +177,7 @@ var name in actions
228177
.Where(n => !existingNames.Contains(n))
229178
)
230179
{
231-
#if NET10_0
232180
swaggerDoc.Tags ??= new HashSet<OpenApiTag>();
233-
#endif
234181
swaggerDoc.Tags.Add(new OpenApiTag { Name = name });
235182
}
236183
}

src/Simplify.Web.Swagger/SimplifyWebSwaggerArgs.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
using System.Collections.Generic;
2-
#if NET10_0
32
using Microsoft.OpenApi;
4-
#else
5-
using Microsoft.OpenApi.Models;
6-
#endif
73

84
namespace Simplify.Web.Swagger;
95

src/TesterApp/Program.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1+
using Microsoft.OpenApi;
12
using Simplify.DI;
23
using Simplify.Web;
34
using Simplify.Web.Swagger;
45
using TesterApp.Setup;
5-
#if NET10_0
6-
using Microsoft.OpenApi;
7-
#else
8-
using Microsoft.OpenApi.Models;
9-
#endif
106

117
var builder = WebApplication.CreateBuilder(args);
128

src/TesterApp/TesterApp.csproj

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
3-
<TargetFrameworks>net10.0;net9.0;net8.0</TargetFrameworks>
3+
<TargetFrameworks>net10.0</TargetFrameworks>
44
<ImplicitUsings>enable</ImplicitUsings>
55
</PropertyGroup>
6-
<ItemGroup Condition=" '$(TargetFramework)' == 'net10.0' ">
6+
<ItemGroup>
77
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="10.2.1" />
88
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="10.2.1" />
99
</ItemGroup>
10-
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' Or '$(TargetFramework)' == 'net9.0' ">
11-
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="9.0.6" />
12-
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="9.0.6" />
13-
</ItemGroup>
1410
<ItemGroup>
1511
<ProjectReference Include="..\Simplify.Web.Swagger\Simplify.Web.Swagger.csproj" />
1612
</ItemGroup>

0 commit comments

Comments
 (0)