Alternatives to Swagger in ASP.NET 9

In ASP.NET 9, Swagger was removed from the templates. However, there are still alternatives for creating and testing APIs interactively.

In the latest version of ASP.NET, specifically ASP.NET 9, the development team has removed the Swagger tool from the standard templates. This Decision was made to push forward the custom implementation, which runs under the Microsoft.AspNetCore.OpenApi namespace, and to avoid a dependency on Swashbuckle, which has not been actively maintained for a while. When creating a new project, developers now only find the minimal example that shows the use of OpenAPI:
builder.Services.AddOpenApi();
var app = builder.Build();

if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}

This shows Steven Giesel in an article. With this configuration, developers can generate the OpenAPI specification by simply https://localhost:/openapi/v1.json However, they will have to do without the familiar interactive user interface that Swagger offered.

There are a few alternatives to restore this functionality. The simplest and most immediate solution is to reinstall Swashbuckle. The package is still actively maintained and is functional as usual. After installation, developers simply add the Program.cs-file:

For many developers, Swagger is of great importance because of its high level of customization.

Another alternative is NSwag which is also capable of providing the Swagger UI. NSwag also offers the ability to automatically create TypeScript types, which can be extremely useful for developers working in modern web applications.
Last but not least, there is the newer tool Scalarwhich can also be integrated with .NET. Scalar offers an attractive user interface and comes with a practical onboarding guide. To integrate Scalar into an ASP.NET project, developers install the package using:

dotnet add package Scalar.AspNetCore

Below is an example code for the Program.cs:

builder.Services.AddOpenApi();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
app.MapScalarApiReference();
}

Source: www.com-magazin.de