Skip to content

Commit e60bc1f

Browse files
authored
bump example to .net 10 (#36184)
1 parent 6f814e4 commit e60bc1f

File tree

4 files changed

+36
-32
lines changed

4 files changed

+36
-32
lines changed

aspnetcore/fundamentals/openapi/samples/10.x/WebMinOpenApi/Program.cs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define DOCUMENTtransformerInOut
33
//#define DOCUMENTtransformer1
44
//#define DOCUMENTtransformer2
5-
// #define DOCUMENTtransformerUse999
5+
//#define DOCUMENTtransformerUse999
66
//#define FIRST
77
//#define OPENAPIWITHSCALAR
88
//#define MAPOPENAPIWITHCACHING
@@ -61,7 +61,7 @@ internal record WeatherForecast(DateTime Date, int TemperatureC, string? Summary
6161
using Microsoft.Extensions.DependencyInjection;
6262
using Microsoft.AspNetCore.Builder;
6363

64-
var builder = WebApplication.CreateBuilder();
64+
var builder = WebApplication.CreateBuilder(args);
6565

6666
builder.Services.AddOpenApi(options =>
6767
{
@@ -96,7 +96,7 @@ internal record WeatherForecast(DateTime Date, int TemperatureC, string? Summary
9696
using Microsoft.AspNetCore.Builder;
9797
using Microsoft.AspNetCore.OpenApi;
9898
using Microsoft.Extensions.DependencyInjection;
99-
using Microsoft.OpenApi.Models;
99+
using Microsoft.OpenApi;
100100

101101
var builder = WebApplication.CreateBuilder();
102102

@@ -125,7 +125,7 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf
125125
var authenticationSchemes = await authenticationSchemeProvider.GetAllSchemesAsync();
126126
if (authenticationSchemes.Any(authScheme => authScheme.Name == "Bearer"))
127127
{
128-
var requirements = new Dictionary<string, OpenApiSecurityScheme>
128+
var securitySchemes = new Dictionary<string, IOpenApiSecurityScheme>
129129
{
130130
["Bearer"] = new OpenApiSecurityScheme
131131
{
@@ -136,7 +136,7 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf
136136
}
137137
};
138138
document.Components ??= new OpenApiComponents();
139-
document.Components.SecuritySchemes = requirements;
139+
document.Components.SecuritySchemes = securitySchemes;
140140
}
141141
}
142142
}
@@ -149,7 +149,7 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf
149149
using Microsoft.AspNetCore.Builder;
150150
using Microsoft.AspNetCore.OpenApi;
151151
using Microsoft.Extensions.DependencyInjection;
152-
using Microsoft.OpenApi.Models;
152+
using Microsoft.OpenApi;
153153

154154
var builder = WebApplication.CreateBuilder();
155155

@@ -159,6 +159,7 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf
159159
{
160160
options.AddOperationTransformer((operation, context, cancellationToken) =>
161161
{
162+
operation.Responses ??= new OpenApiResponses();
162163
operation.Responses.Add("500", new OpenApiResponse { Description = "Internal server error" });
163164
return Task.CompletedTask;
164165
});
@@ -183,7 +184,7 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf
183184
using Microsoft.AspNetCore.Builder;
184185
using Microsoft.AspNetCore.OpenApi;
185186
using Microsoft.Extensions.DependencyInjection;
186-
using Microsoft.OpenApi.Models;
187+
using Microsoft.OpenApi;
187188

188189
var builder = WebApplication.CreateBuilder();
189190

@@ -217,7 +218,7 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf
217218
if (authenticationSchemes.Any(authScheme => authScheme.Name == "Bearer"))
218219
{
219220
// Add the security scheme at the document level
220-
var requirements = new Dictionary<string, OpenApiSecurityScheme>
221+
var securitySchemes = new Dictionary<string, IOpenApiSecurityScheme>
221222
{
222223
["Bearer"] = new OpenApiSecurityScheme
223224
{
@@ -228,14 +229,15 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf
228229
}
229230
};
230231
document.Components ??= new OpenApiComponents();
231-
document.Components.SecuritySchemes = requirements;
232+
document.Components.SecuritySchemes = securitySchemes;
232233

233234
// Apply it as a requirement for all operations
234235
foreach (var operation in document.Paths.Values.SelectMany(path => path.Operations))
235236
{
237+
operation.Value.Security ??= [];
236238
operation.Value.Security.Add(new OpenApiSecurityRequirement
237239
{
238-
[new OpenApiSecurityScheme { Reference = new OpenApiReference { Id = "Bearer", Type = ReferenceType.SecurityScheme } }] = Array.Empty<string>()
240+
[new OpenApiSecuritySchemeReference("Bearer")] = []
239241
});
240242
}
241243
}
@@ -285,9 +287,9 @@ public class Body {
285287
using Microsoft.AspNetCore.Builder;
286288
using Microsoft.AspNetCore.OpenApi;
287289
using Microsoft.Extensions.DependencyInjection;
288-
using Microsoft.OpenApi.Models;
290+
using Microsoft.OpenApi;
289291

290-
var builder = WebApplication.CreateBuilder();
292+
var builder = WebApplication.CreateBuilder(args);
291293

292294
builder.Services.AddOpenApi();
293295

@@ -316,9 +318,9 @@ public class Body {
316318
using Microsoft.AspNetCore.Builder;
317319
using Microsoft.AspNetCore.OpenApi;
318320
using Microsoft.Extensions.DependencyInjection;
319-
using Microsoft.OpenApi.Models;
321+
using Microsoft.OpenApi;
320322

321-
var builder = WebApplication.CreateBuilder();
323+
var builder = WebApplication.CreateBuilder(args);
322324

323325
builder.Services.AddAuthentication().AddJwtBearer();
324326
builder.Services.AddAuthorization(o =>
@@ -343,9 +345,9 @@ public class Body {
343345
using Microsoft.AspNetCore.Builder;
344346
using Microsoft.AspNetCore.OpenApi;
345347
using Microsoft.Extensions.DependencyInjection;
346-
using Microsoft.OpenApi.Models;
348+
using Microsoft.OpenApi;
347349

348-
var builder = WebApplication.CreateBuilder();
350+
var builder = WebApplication.CreateBuilder(args);
349351

350352
builder.Services.AddOutputCache(options =>
351353
{
@@ -374,10 +376,10 @@ public class Body {
374376
using Microsoft.AspNetCore.Builder;
375377
using Microsoft.AspNetCore.OpenApi;
376378
using Microsoft.Extensions.DependencyInjection;
377-
using Microsoft.OpenApi.Models;
379+
using Microsoft.OpenApi;
378380
using Scalar.AspNetCore;
379381

380-
var builder = WebApplication.CreateBuilder();
382+
var builder = WebApplication.CreateBuilder(args);
381383

382384
builder.Services.AddOpenApi();
383385

@@ -417,9 +419,9 @@ public class Body {
417419
#if DOCUMENTtransformerUse999
418420
// <snippet_transUse>
419421
using Microsoft.AspNetCore.OpenApi;
420-
using Microsoft.OpenApi.Models;
422+
using Microsoft.OpenApi;
421423

422-
var builder = WebApplication.CreateBuilder();
424+
var builder = WebApplication.CreateBuilder(args);
423425

424426
builder.Services.AddOpenApi(options =>
425427
{
@@ -485,9 +487,9 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
485487
#if DOCUMENTtransformerInOut
486488
// <snippet_transInOut>
487489
using Microsoft.AspNetCore.OpenApi;
488-
using Microsoft.OpenApi.Models;
490+
using Microsoft.OpenApi;
489491

490-
var builder = WebApplication.CreateBuilder();
492+
var builder = WebApplication.CreateBuilder(args);
491493

492494
builder.Services.AddOpenApi(options =>
493495
{
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<OpenApiDocumentsDirectory>./</OpenApiDocumentsDirectory>
@@ -14,14 +14,14 @@
1414
</PropertyGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
18-
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.0" />
19-
<PackageReference Include="Microsoft.Extensions.ApiDescription.Server" Version="9.0.0">
17+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.0-rc.1.25451.107" />
18+
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.0-rc.1.25451.107" />
19+
<PackageReference Include="Microsoft.Extensions.ApiDescription.Server" Version="10.0.0-rc.1.25451.107">
2020
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2121
<PrivateAssets>all</PrivateAssets>
2222
</PackageReference>
23-
<PackageReference Include="Scalar.AspNetCore" Version="1.2.50" />
24-
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUi" Version="7.1.0" />
23+
<PackageReference Include="Scalar.AspNetCore" Version="2.8.10" />
24+
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUi" Version="9.0.6" />
2525
</ItemGroup>
2626

2727
</Project>
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"sdk": {
3-
"version": "9.0.100-rc.1.24414.13"
3+
"version": "10.0.0",
4+
"rollForward": "latestFeature",
5+
"allowPrerelease": true
46
}
57
}

aspnetcore/fundamentals/openapi/samples/10.x/WebMinOpenApi/projectFile.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
</PropertyGroup>
@@ -12,8 +12,8 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.*-*" />
16-
<PackageReference Include="Microsoft.Extensions.ApiDescription.Server" Version="9.0.*-*">
15+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.*-*" />
16+
<PackageReference Include="Microsoft.Extensions.ApiDescription.Server" Version="10.0.*-*">
1717
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1818
<PrivateAssets>all</PrivateAssets>
1919
</PackageReference>

0 commit comments

Comments
 (0)