Skip to content

Commit be1d022

Browse files
committed
fix: update OpenApi namespace for Swashbuckle v10 compatibility
Migrate from Microsoft.OpenApi.Models to Microsoft.OpenApi and refactor security scheme references to use OpenApiSecuritySchemeReference instead of nested OpenApiReference pattern. Changes: - Updated using directives in AuthorizeCheckOperationFilter, ServiceCollectionExtensions, and SwaggerUtilities - Replaced OpenApiSecurityScheme nested Reference with OpenApiSecuritySchemeReference("Bearer", null) - Changed Array.Empty<string>() to new List<string>() for OpenApiSecurityRequirement dictionary values Resolves compilation errors from Swashbuckle.AspNetCore 10.0.1's dependency on Microsoft.OpenApi 2.3.0.
1 parent 91a6b3a commit be1d022

File tree

4 files changed

+51
-63
lines changed

4 files changed

+51
-63
lines changed

src/Dotnet.Samples.AspNetCore.WebApi/Configurations/AuthorizeCheckOperationFilter.cs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Linq;
22
using Microsoft.AspNetCore.Authorization;
3-
using Microsoft.OpenApi.Models;
3+
using Microsoft.OpenApi;
44
using Swashbuckle.AspNetCore.SwaggerGen;
55

66
namespace Dotnet.Samples.AspNetCore.WebApi.Configurations
@@ -25,23 +25,17 @@ public void Apply(OpenApiOperation operation, OperationFilterContext context)
2525
return;
2626

2727
// Add security requirement (shows the lock icon)
28-
operation.Security ??= new List<OpenApiSecurityRequirement>();
29-
operation.Security.Add(
30-
new OpenApiSecurityRequirement
31-
{
28+
// In Microsoft.OpenApi 2.x, use OpenApiSecuritySchemeReference instead of OpenApiSecurityScheme with nested Reference
29+
if (operation is OpenApiOperation openApiOperation)
30+
{
31+
openApiOperation.Security ??= new List<OpenApiSecurityRequirement>();
32+
openApiOperation.Security.Add(
33+
new OpenApiSecurityRequirement
3234
{
33-
new OpenApiSecurityScheme
34-
{
35-
Reference = new OpenApiReference
36-
{
37-
Id = "Bearer",
38-
Type = ReferenceType.SecurityScheme
39-
}
40-
},
41-
Array.Empty<string>()
35+
{ new OpenApiSecuritySchemeReference("Bearer", null), new List<string>() }
4236
}
43-
}
44-
);
37+
);
38+
}
4539
}
4640
}
4741
}

src/Dotnet.Samples.AspNetCore.WebApi/Extensions/ServiceCollectionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using Dotnet.Samples.AspNetCore.WebApi.Validators;
99
using FluentValidation;
1010
using Microsoft.EntityFrameworkCore;
11-
using Microsoft.OpenApi.Models;
11+
using Microsoft.OpenApi;
1212
using Serilog;
1313

1414
namespace Dotnet.Samples.AspNetCore.WebApi.Extensions;

src/Dotnet.Samples.AspNetCore.WebApi/Utilities/SwaggerUtilities.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System.Reflection;
2-
using Microsoft.OpenApi.Models;
2+
using Microsoft.OpenApi;
33

44
namespace Dotnet.Samples.AspNetCore.WebApi.Utilities;
55

@@ -58,17 +58,7 @@ public static OpenApiSecurityRequirement ConfigureSecurityRequirement()
5858
{
5959
return new OpenApiSecurityRequirement
6060
{
61-
{
62-
new OpenApiSecurityScheme
63-
{
64-
Reference = new OpenApiReference
65-
{
66-
Id = "Bearer",
67-
Type = ReferenceType.SecurityScheme
68-
}
69-
},
70-
Array.Empty<string>()
71-
}
61+
{ new OpenApiSecuritySchemeReference("Bearer", null), new List<string>() }
7262
};
7363
}
7464
}

test/Dotnet.Samples.AspNetCore.WebApi.Tests/packages.lock.json

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@
165165
},
166166
"Microsoft.Extensions.ApiDescription.Server": {
167167
"type": "Transitive",
168-
"resolved": "6.0.5",
169-
"contentHash": "Ckb5EDBUNJdFWyajfXzUIMRkhf52fHZOQuuZg/oiu8y7zDCVwD0iHhew6MnThjHmevanpxL3f5ci2TtHQEN6bw=="
168+
"resolved": "8.0.0",
169+
"contentHash": "jDM3a95WerM8g6IcMiBXq1qRS9dqmEUpgnCk2DeMWpPkYtp1ia+CkXabOnK93JmhVlUmv8l9WMPsCSUm+WqkIA=="
170170
},
171171
"Microsoft.Extensions.Caching.Abstractions": {
172172
"type": "Transitive",
@@ -207,10 +207,11 @@
207207
},
208208
"Microsoft.Extensions.Configuration.Binder": {
209209
"type": "Transitive",
210-
"resolved": "9.0.0",
211-
"contentHash": "RiScL99DcyngY9zJA2ROrri7Br8tn5N4hP4YNvGdTN/bvg1A3dwvDOxHnNZ3Im7x2SJ5i4LkX1uPiR/MfSFBLQ==",
210+
"resolved": "10.0.0",
211+
"contentHash": "tMF9wNh+hlyYDWB8mrFCQHQmWHlRosol1b/N2Jrefy1bFLnuTlgSYmPyHNmz8xVQgs7DpXytBRWxGhG+mSTp0g==",
212212
"dependencies": {
213-
"Microsoft.Extensions.Configuration.Abstractions": "9.0.0"
213+
"Microsoft.Extensions.Configuration": "10.0.0",
214+
"Microsoft.Extensions.Configuration.Abstractions": "10.0.0"
214215
}
215216
},
216217
"Microsoft.Extensions.Configuration.FileExtensions": {
@@ -252,11 +253,11 @@
252253
},
253254
"Microsoft.Extensions.DependencyModel": {
254255
"type": "Transitive",
255-
"resolved": "9.0.11",
256-
"contentHash": "DaBLlKcD5AYFLEeX7M07Q0vWOEBd86KYXOb+5ZRdQ1jYtN39cJd6fftxdNbRazEYQc9QqsAZiqKb9ub0gA+q+Q==",
256+
"resolved": "10.0.0",
257+
"contentHash": "RFYJR7APio/BiqdQunRq6DB+nDB6nc2qhHr77mlvZ0q0BT8PubMXN7XicmfzCbrDE/dzhBnUKBRXLTcqUiZDGg==",
257258
"dependencies": {
258-
"System.Text.Encodings.Web": "9.0.11",
259-
"System.Text.Json": "9.0.11"
259+
"System.Text.Encodings.Web": "10.0.0",
260+
"System.Text.Json": "10.0.0"
260261
}
261262
},
262263
"Microsoft.Extensions.Diagnostics.Abstractions": {
@@ -339,8 +340,11 @@
339340
},
340341
"Microsoft.OpenApi": {
341342
"type": "Transitive",
342-
"resolved": "1.6.23",
343-
"contentHash": "tZ1I0KXnn98CWuV8cpI247A17jaY+ILS9vvF7yhI0uPPEqF4P1d7BWL5Uwtel10w9NucllHB3nTkfYTAcHAh8g=="
343+
"resolved": "2.3.0",
344+
"contentHash": "5RZpjyt0JMmoc/aEgY9c1vE5pusdDGvkPl9qKIy9KFbRiIXD+w7gBJxX+unSjzzOcfgRoYxnO4okZyqDAL2WEw==",
345+
"dependencies": {
346+
"System.Text.Json": "8.0.5"
347+
}
344348
},
345349
"Microsoft.TestPlatform.ObjectModel": {
346350
"type": "Transitive",
@@ -366,8 +370,8 @@
366370
},
367371
"Serilog": {
368372
"type": "Transitive",
369-
"resolved": "4.2.0",
370-
"contentHash": "gmoWVOvKgbME8TYR+gwMf7osROiWAURterc6Rt2dQyX7wtjZYpqFiA/pY6ztjGQKKV62GGCyOcmtP1UKMHgSmA=="
373+
"resolved": "4.3.0",
374+
"contentHash": "+cDryFR0GRhsGOnZSKwaDzRRl4MupvJ42FhCE4zhQRVanX0Jpg6WuCBk59OVhVDPmab1bB+nRykAnykYELA9qQ=="
371375
},
372376
"Serilog.AspNetCore": {
373377
"type": "Transitive",
@@ -414,12 +418,12 @@
414418
},
415419
"Serilog.Settings.Configuration": {
416420
"type": "Transitive",
417-
"resolved": "9.0.0",
418-
"contentHash": "4/Et4Cqwa+F88l5SeFeNZ4c4Z6dEAIKbu3MaQb2Zz9F/g27T5a3wvfMcmCOaAiACjfUb4A6wrlTVfyYUZk3RRQ==",
421+
"resolved": "10.0.0",
422+
"contentHash": "LNq+ibS1sbhTqPV1FIE69/9AJJbfaOhnaqkzcjFy95o+4U+STsta9mi97f1smgXsWYKICDeGUf8xUGzd/52/uA==",
419423
"dependencies": {
420-
"Microsoft.Extensions.Configuration.Binder": "9.0.0",
421-
"Microsoft.Extensions.DependencyModel": "9.0.0",
422-
"Serilog": "4.2.0"
424+
"Microsoft.Extensions.Configuration.Binder": "10.0.0",
425+
"Microsoft.Extensions.DependencyModel": "10.0.0",
426+
"Serilog": "4.3.0"
423427
}
424428
},
425429
"Serilog.Sinks.Console": {
@@ -478,35 +482,35 @@
478482
},
479483
"Swashbuckle.AspNetCore": {
480484
"type": "Transitive",
481-
"resolved": "8.1.4",
482-
"contentHash": "qYk8VHyvs6wML+KXtjyCgS9Aj18mcm0ZtnJeNCTlj/DYQ7A3pfLIztQgLuZS/LEMYsrTo1lSKR3IIZ5/HzVCWA==",
485+
"resolved": "10.0.1",
486+
"contentHash": "177+JNAV5TNvy8gLCdrcWBY9n2jdkxiHQDY4vhaExeqUpKrOqDatCcm/kW3kze60GqfnZ2NobD/IKiAPOL+CEw==",
483487
"dependencies": {
484-
"Microsoft.Extensions.ApiDescription.Server": "6.0.5",
485-
"Swashbuckle.AspNetCore.Swagger": "8.1.4",
486-
"Swashbuckle.AspNetCore.SwaggerGen": "8.1.4",
487-
"Swashbuckle.AspNetCore.SwaggerUI": "8.1.4"
488+
"Microsoft.Extensions.ApiDescription.Server": "8.0.0",
489+
"Swashbuckle.AspNetCore.Swagger": "10.0.1",
490+
"Swashbuckle.AspNetCore.SwaggerGen": "10.0.1",
491+
"Swashbuckle.AspNetCore.SwaggerUI": "10.0.1"
488492
}
489493
},
490494
"Swashbuckle.AspNetCore.Swagger": {
491495
"type": "Transitive",
492-
"resolved": "8.1.4",
493-
"contentHash": "w83aYEBJYNa6ZYomziwZWwXhqQPLKhZH0n8MzqqNhF1ElCGBKm71kd7W6pgIr/yu0i6ymQzrZUFSZLdvH1kY5w==",
496+
"resolved": "10.0.1",
497+
"contentHash": "HJYFSP18YF1Z6LCwunL+v8wuZUzzvcjarB8AJna/NVVIpq11FH9BW/D/6abwigu7SsKRbisStmk8xu2mTsxxHg==",
494498
"dependencies": {
495-
"Microsoft.OpenApi": "1.6.23"
499+
"Microsoft.OpenApi": "2.3.0"
496500
}
497501
},
498502
"Swashbuckle.AspNetCore.SwaggerGen": {
499503
"type": "Transitive",
500-
"resolved": "8.1.4",
501-
"contentHash": "aBwO2MF1HHAaWgdBwX8tlSqxycOKTKmCT6pEpb0oSY1pn7mUdmzJvHZA0HxWx9nfmKP0eOGQcLC9ZnN/MuehRQ==",
504+
"resolved": "10.0.1",
505+
"contentHash": "vMMBDiTC53KclPs1aiedRZnXkoI2ZgF5/JFr3Dqr8KT7wvIbA/MwD+ormQ4qf25gN5xCrJbmz/9/Z3RrpSofMA==",
502506
"dependencies": {
503-
"Swashbuckle.AspNetCore.Swagger": "8.1.4"
507+
"Swashbuckle.AspNetCore.Swagger": "10.0.1"
504508
}
505509
},
506510
"Swashbuckle.AspNetCore.SwaggerUI": {
507511
"type": "Transitive",
508-
"resolved": "8.1.4",
509-
"contentHash": "mTn6OwB43ETrN6IgAZd7ojWGhTwBZ98LT3QwbAn6Gg3wJStQV4znU0mWiHaKFlD/+Qhj1uhAUOa52rmd6xmbzg=="
512+
"resolved": "10.0.1",
513+
"contentHash": "a2eLI/fCxJ3WH+H1hr7Q2T82ZBk20FfqYBEZ9hOr3f+426ZUfGU2LxYWzOJrf5/4y6EKShmWpjJG01h3Rc+l6Q=="
510514
},
511515
"System.Collections.Immutable": {
512516
"type": "Transitive",
@@ -605,10 +609,10 @@
605609
"Microsoft.EntityFrameworkCore.Sqlite": "[9.0.11, )",
606610
"Microsoft.Extensions.Configuration.Json": "[10.0.0, )",
607611
"Serilog.AspNetCore": "[9.0.0, )",
608-
"Serilog.Settings.Configuration": "[9.0.0, )",
612+
"Serilog.Settings.Configuration": "[10.0.0, )",
609613
"Serilog.Sinks.Console": "[6.1.1, )",
610614
"Serilog.Sinks.File": "[7.0.0, )",
611-
"Swashbuckle.AspNetCore": "[8.1.4, )"
615+
"Swashbuckle.AspNetCore": "[10.0.1, )"
612616
}
613617
}
614618
}

0 commit comments

Comments
 (0)