From 4a357646183e53def00be7cc0a5f8e26a75203ad Mon Sep 17 00:00:00 2001 From: Justin Lampe Date: Sun, 5 Oct 2025 12:17:24 +0200 Subject: [PATCH] bump example to .net 10 --- .../samples/10.x/WebMinOpenApi/Program.cs | 46 ++++++++++--------- .../10.x/WebMinOpenApi/WebMinOpenApi.csproj | 12 ++--- .../samples/10.x/WebMinOpenApi/global.json | 4 +- .../10.x/WebMinOpenApi/projectFile.xml | 6 +-- 4 files changed, 36 insertions(+), 32 deletions(-) diff --git a/aspnetcore/fundamentals/openapi/samples/10.x/WebMinOpenApi/Program.cs b/aspnetcore/fundamentals/openapi/samples/10.x/WebMinOpenApi/Program.cs index b33984981bf1..b31519a65e18 100644 --- a/aspnetcore/fundamentals/openapi/samples/10.x/WebMinOpenApi/Program.cs +++ b/aspnetcore/fundamentals/openapi/samples/10.x/WebMinOpenApi/Program.cs @@ -2,7 +2,7 @@ #define DOCUMENTtransformerInOut //#define DOCUMENTtransformer1 //#define DOCUMENTtransformer2 -// #define DOCUMENTtransformerUse999 +//#define DOCUMENTtransformerUse999 //#define FIRST //#define OPENAPIWITHSCALAR //#define MAPOPENAPIWITHCACHING @@ -61,7 +61,7 @@ internal record WeatherForecast(DateTime Date, int TemperatureC, string? Summary using Microsoft.Extensions.DependencyInjection; using Microsoft.AspNetCore.Builder; -var builder = WebApplication.CreateBuilder(); +var builder = WebApplication.CreateBuilder(args); builder.Services.AddOpenApi(options => { @@ -96,7 +96,7 @@ internal record WeatherForecast(DateTime Date, int TemperatureC, string? Summary using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.OpenApi; using Microsoft.Extensions.DependencyInjection; -using Microsoft.OpenApi.Models; +using Microsoft.OpenApi; var builder = WebApplication.CreateBuilder(); @@ -125,7 +125,7 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf var authenticationSchemes = await authenticationSchemeProvider.GetAllSchemesAsync(); if (authenticationSchemes.Any(authScheme => authScheme.Name == "Bearer")) { - var requirements = new Dictionary + var securitySchemes = new Dictionary { ["Bearer"] = new OpenApiSecurityScheme { @@ -136,7 +136,7 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf } }; document.Components ??= new OpenApiComponents(); - document.Components.SecuritySchemes = requirements; + document.Components.SecuritySchemes = securitySchemes; } } } @@ -149,7 +149,7 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.OpenApi; using Microsoft.Extensions.DependencyInjection; -using Microsoft.OpenApi.Models; +using Microsoft.OpenApi; var builder = WebApplication.CreateBuilder(); @@ -159,6 +159,7 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf { options.AddOperationTransformer((operation, context, cancellationToken) => { + operation.Responses ??= new OpenApiResponses(); operation.Responses.Add("500", new OpenApiResponse { Description = "Internal server error" }); return Task.CompletedTask; }); @@ -183,7 +184,7 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.OpenApi; using Microsoft.Extensions.DependencyInjection; -using Microsoft.OpenApi.Models; +using Microsoft.OpenApi; var builder = WebApplication.CreateBuilder(); @@ -217,7 +218,7 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf if (authenticationSchemes.Any(authScheme => authScheme.Name == "Bearer")) { // Add the security scheme at the document level - var requirements = new Dictionary + var securitySchemes = new Dictionary { ["Bearer"] = new OpenApiSecurityScheme { @@ -228,14 +229,15 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf } }; document.Components ??= new OpenApiComponents(); - document.Components.SecuritySchemes = requirements; + document.Components.SecuritySchemes = securitySchemes; // Apply it as a requirement for all operations foreach (var operation in document.Paths.Values.SelectMany(path => path.Operations)) { + operation.Value.Security ??= []; operation.Value.Security.Add(new OpenApiSecurityRequirement { - [new OpenApiSecurityScheme { Reference = new OpenApiReference { Id = "Bearer", Type = ReferenceType.SecurityScheme } }] = Array.Empty() + [new OpenApiSecuritySchemeReference("Bearer")] = [] }); } } @@ -285,9 +287,9 @@ public class Body { using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.OpenApi; using Microsoft.Extensions.DependencyInjection; -using Microsoft.OpenApi.Models; +using Microsoft.OpenApi; -var builder = WebApplication.CreateBuilder(); +var builder = WebApplication.CreateBuilder(args); builder.Services.AddOpenApi(); @@ -316,9 +318,9 @@ public class Body { using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.OpenApi; using Microsoft.Extensions.DependencyInjection; -using Microsoft.OpenApi.Models; +using Microsoft.OpenApi; -var builder = WebApplication.CreateBuilder(); +var builder = WebApplication.CreateBuilder(args); builder.Services.AddAuthentication().AddJwtBearer(); builder.Services.AddAuthorization(o => @@ -343,9 +345,9 @@ public class Body { using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.OpenApi; using Microsoft.Extensions.DependencyInjection; -using Microsoft.OpenApi.Models; +using Microsoft.OpenApi; -var builder = WebApplication.CreateBuilder(); +var builder = WebApplication.CreateBuilder(args); builder.Services.AddOutputCache(options => { @@ -374,10 +376,10 @@ public class Body { using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.OpenApi; using Microsoft.Extensions.DependencyInjection; -using Microsoft.OpenApi.Models; +using Microsoft.OpenApi; using Scalar.AspNetCore; -var builder = WebApplication.CreateBuilder(); +var builder = WebApplication.CreateBuilder(args); builder.Services.AddOpenApi(); @@ -417,9 +419,9 @@ public class Body { #if DOCUMENTtransformerUse999 // using Microsoft.AspNetCore.OpenApi; -using Microsoft.OpenApi.Models; +using Microsoft.OpenApi; -var builder = WebApplication.CreateBuilder(); +var builder = WebApplication.CreateBuilder(args); builder.Services.AddOpenApi(options => { @@ -485,9 +487,9 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext #if DOCUMENTtransformerInOut // using Microsoft.AspNetCore.OpenApi; -using Microsoft.OpenApi.Models; +using Microsoft.OpenApi; -var builder = WebApplication.CreateBuilder(); +var builder = WebApplication.CreateBuilder(args); builder.Services.AddOpenApi(options => { diff --git a/aspnetcore/fundamentals/openapi/samples/10.x/WebMinOpenApi/WebMinOpenApi.csproj b/aspnetcore/fundamentals/openapi/samples/10.x/WebMinOpenApi/WebMinOpenApi.csproj index d83ead4e0098..3c487b035926 100644 --- a/aspnetcore/fundamentals/openapi/samples/10.x/WebMinOpenApi/WebMinOpenApi.csproj +++ b/aspnetcore/fundamentals/openapi/samples/10.x/WebMinOpenApi/WebMinOpenApi.csproj @@ -1,7 +1,7 @@ - net9.0 + net10.0 enable enable ./ @@ -14,14 +14,14 @@ - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - - + + diff --git a/aspnetcore/fundamentals/openapi/samples/10.x/WebMinOpenApi/global.json b/aspnetcore/fundamentals/openapi/samples/10.x/WebMinOpenApi/global.json index 6091d76c863a..6e016cfb3eeb 100644 --- a/aspnetcore/fundamentals/openapi/samples/10.x/WebMinOpenApi/global.json +++ b/aspnetcore/fundamentals/openapi/samples/10.x/WebMinOpenApi/global.json @@ -1,5 +1,7 @@ { "sdk": { - "version": "9.0.100-rc.1.24414.13" + "version": "10.0.0", + "rollForward": "latestFeature", + "allowPrerelease": true } } diff --git a/aspnetcore/fundamentals/openapi/samples/10.x/WebMinOpenApi/projectFile.xml b/aspnetcore/fundamentals/openapi/samples/10.x/WebMinOpenApi/projectFile.xml index 0ff4d21eb2d5..c92813a8bdd1 100644 --- a/aspnetcore/fundamentals/openapi/samples/10.x/WebMinOpenApi/projectFile.xml +++ b/aspnetcore/fundamentals/openapi/samples/10.x/WebMinOpenApi/projectFile.xml @@ -1,7 +1,7 @@ - net9.0 + net10.0 enable enable @@ -12,8 +12,8 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all