diff --git a/Directory.Packages.props b/Directory.Packages.props index b9427470..29eb1ebc 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -13,12 +13,10 @@ - + - - @@ -26,12 +24,13 @@ - + + diff --git a/TodoApi/Extensions/OpenApiExtensions.cs b/TodoApi/Extensions/OpenApiExtensions.cs deleted file mode 100644 index 818936cd..00000000 --- a/TodoApi/Extensions/OpenApiExtensions.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Microsoft.OpenApi.Models; -using Swashbuckle.AspNetCore.SwaggerGen; - -namespace TodoApi; - -public static class OpenApiExtensions -{ - private static readonly OpenApiSecurityScheme BearerScheme = new() - { - Type = SecuritySchemeType.Http, - Name = "Bearer", - Scheme = "Bearer", - Reference = new() - { - Type = ReferenceType.SecurityScheme, - Id = "Bearer", - } - }; - - public static void AddOpenApiSecurity( - this SwaggerGenOptions swaggerGenOptions) - { - swaggerGenOptions.AddSecurityDefinition("Bearer", BearerScheme); - } - - // Adds the security scheme to the Open API description - public static IEndpointConventionBuilder AddOpenApiSecurity(this IEndpointConventionBuilder builder) - { - return builder.WithOpenApi(operation => new(operation) - { - Security = - { - new() - { - [BearerScheme] = [] - } - } - }); - } -} diff --git a/TodoApi/Program.cs b/TodoApi/Program.cs index a8aed1c8..6c72f377 100644 --- a/TodoApi/Program.cs +++ b/TodoApi/Program.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.HttpLogging; using Microsoft.AspNetCore.Identity; +using Scalar.AspNetCore; var builder = WebApplication.CreateBuilder(args); @@ -22,8 +23,7 @@ builder.Services.AddCurrentUser(); // Configure Open API -builder.Services.AddEndpointsApiExplorer(); -builder.Services.AddSwaggerGen(o => o.AddOpenApiSecurity()); +builder.Services.AddOpenApi(); // Configure rate limiting builder.Services.AddRateLimiting(); @@ -44,10 +44,11 @@ if (app.Environment.IsDevelopment()) { - app.UseSwagger(); - app.UseSwaggerUI(); + app.MapScalarApiReference(); } +app.MapOpenApi(); + app.MapDefaultEndpoints(); app.Map("/", () => Results.Redirect("/swagger")); diff --git a/TodoApi/Properties/launchSettings.json b/TodoApi/Properties/launchSettings.json index e6858f00..5923995d 100644 --- a/TodoApi/Properties/launchSettings.json +++ b/TodoApi/Properties/launchSettings.json @@ -12,7 +12,7 @@ "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, - "launchUrl": "swagger", + "launchUrl": "scalar/v1", "hotReloadProfile": "aspnetcore", "applicationUrl": "http://localhost:5000", "environmentVariables": { @@ -23,7 +23,7 @@ "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, - "launchUrl": "swagger", + "launchUrl": "scalar/v1", "hotReloadProfile": "aspnetcore", "applicationUrl": "https://localhost:5001;http://localhost:5000", "environmentVariables": { diff --git a/TodoApi/TodoApi.csproj b/TodoApi/TodoApi.csproj index 47c3c8eb..1fe21510 100644 --- a/TodoApi/TodoApi.csproj +++ b/TodoApi/TodoApi.csproj @@ -13,7 +13,7 @@ - + diff --git a/TodoApi/Todos/TodoApi.cs b/TodoApi/Todos/TodoApi.cs index a2b2c9bf..a9a7dcae 100644 --- a/TodoApi/Todos/TodoApi.cs +++ b/TodoApi/Todos/TodoApi.cs @@ -13,8 +13,7 @@ public static RouteGroupBuilder MapTodos(this IEndpointRouteBuilder routes) // Add security requirements, all incoming requests to this API *must* // be authenticated with a valid user. - group.RequireAuthorization(pb => pb.RequireCurrentUser()) - .AddOpenApiSecurity(); + group.RequireAuthorization(pb => pb.RequireCurrentUser()); // Rate limit all of the APIs group.RequirePerUserRateLimit();