Skip to content

Commit

Permalink
Use new open api and scalar
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfowl committed Nov 15, 2024
1 parent 3530e8a commit 1449c43
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 53 deletions.
7 changes: 3 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,24 @@
<ItemGroup>
<PackageVersion Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="9.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0" PrivateAssets="all" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.0" />
<PackageVersion Include="Microsoft.NET.Build.Containers" Version="9.0.0" />
<PackageVersion Include="Microsoft.OpenApi" Version="1.6.17" />
<PackageVersion Include="MiniValidation" Version="0.9.0" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageVersion Include="AspNet.Security.OAuth.GitHub" Version="9.0.0" />
<PackageVersion Include="Auth0.AspNetCore.Authentication" Version="1.4.1" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.Google" Version="9.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.MicrosoftAccount" Version="9.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="9.0.0" />
<PackageVersion Include="Yarp.ReverseProxy" Version="2.2.0" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.0" PrivateAssets="all" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.ServiceDiscovery" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.ServiceDiscovery.Yarp" Version="9.0.0" />
<PackageVersion Include="Aspire.Hosting.AppHost" Version="9.0.0" />
<PackageVersion Include="Scalar.AspNetCore" Version="1.2.37" />
</ItemGroup>
<!-- OpenTelemetry -->
<ItemGroup>
Expand Down
40 changes: 0 additions & 40 deletions TodoApi/Extensions/OpenApiExtensions.cs

This file was deleted.

9 changes: 5 additions & 4 deletions TodoApi/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.HttpLogging;
using Microsoft.AspNetCore.Identity;
using Scalar.AspNetCore;

var builder = WebApplication.CreateBuilder(args);

Expand All @@ -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();
Expand All @@ -44,10 +44,11 @@

if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
app.MapScalarApiReference();
}

app.MapOpenApi();

app.MapDefaultEndpoints();

app.Map("/", () => Results.Redirect("/swagger"));
Expand Down
4 changes: 2 additions & 2 deletions TodoApi/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"launchUrl": "scalar/v1",
"hotReloadProfile": "aspnetcore",
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
Expand All @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion TodoApi/TodoApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" />
<PackageReference Include="Microsoft.OpenApi" />
<PackageReference Include="MiniValidation" />
<PackageReference Include="Swashbuckle.AspNetCore" />
<PackageReference Include="Scalar.AspNetCore" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 1 addition & 2 deletions TodoApi/Todos/TodoApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 1449c43

Please sign in to comment.