No Swagger in .NET 9? Here’s What You Need to Know!

Introduction

With the release of .NET 9, you might have noticed that Swagger Gen is no longer included by default. But don’t worry! Microsoft has introduced OpenAPI support along with a new modern API viewer called Scalar.

What’s N…


This content originally appeared on DEV Community and was authored by Aditya

Introduction

With the release of .NET 9, you might have noticed that Swagger Gen is no longer included by default. But don't worry! Microsoft has introduced OpenAPI support along with a new modern API viewer called Scalar.

What's New in .NET 9?

.NET 9 now ships with OpenAPI support built-in, which offers a more modern and flexible way to document and explore your APIs. Scalar has also been introduced as a fresh, redesigned API viewer that is more intuitive and developer-friendly than the traditional Swagger Gen UI.

Prerequisites

  • .NET 9 sdk (For visual studio code users)
  • Upgrade Visual Studio to latest version for .NET 9 support
  • Coffee (optional)

Adding Scalar/Swagger to Your .NET 9 Project

Here's how you can easily add Scalar to your .NET 9 project:

STEP 1:

Click on Create a new project

Create new project

STEP 2:

On the search bar, search for web api as we want to create a demo web api in .NET 9

Create new project

STEP 3:

Now you need to configure your new project

Configure

STEP 4:

Select the target framework as .NET 9.
Also select Configure for HTTPS, Use Controllers. Enlist in .NET Aspire orchestration is optional.

API setup

STEP 5:

After your project is created, it will look something like

Landing

STEP 6:

Now in your service project, go to Program.cs file, it will look something like this by default.

Program.cs

STEP 7:

Now in order to add Scalar, go to Nuget package manager and install the Scalar.AspNetCore package.
Alternatively, if you want to install Swagger, then install Swashbuckle.AspNetCorepackage.

Add package

STEP 8:

As I'm going with Scalar, so my code will look something like

builder.Services.AddOpenApi();

//some code

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

For swagger, it will look like,

builder.Services.AddSwaggerGen();

// some code

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

Scalar API reference

All Set!

As I used .NET Aspire orchestration, I just need to click on run and Aspire will take care of the rest!

Aspire.net

Result:

Navigate to your-url:portnumber/scalar/v1 to view all the APIs.

URL

Now this is the scalar interface and amazing part is that they provide customizable themes of different types, you can check them out.

Scalar interface

This is my final response after hitting Run button.

API response

Conclusion

If you like this article and find it useful, dont forget to hit the like and follow button for more such upcoming articles. Also, if you face any issue feel free to discuss in the comment section. Happy coding!

Happy-coding


This content originally appeared on DEV Community and was authored by Aditya


Print Share Comment Cite Upload Translate Updates
APA

Aditya | Sciencx (2025-01-11T15:40:48+00:00) No Swagger in .NET 9? Here’s What You Need to Know!. Retrieved from https://www.scien.cx/2025/01/11/no-swagger-in-net-9-heres-what-you-need-to-know/

MLA
" » No Swagger in .NET 9? Here’s What You Need to Know!." Aditya | Sciencx - Saturday January 11, 2025, https://www.scien.cx/2025/01/11/no-swagger-in-net-9-heres-what-you-need-to-know/
HARVARD
Aditya | Sciencx Saturday January 11, 2025 » No Swagger in .NET 9? Here’s What You Need to Know!., viewed ,<https://www.scien.cx/2025/01/11/no-swagger-in-net-9-heres-what-you-need-to-know/>
VANCOUVER
Aditya | Sciencx - » No Swagger in .NET 9? Here’s What You Need to Know!. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/01/11/no-swagger-in-net-9-heres-what-you-need-to-know/
CHICAGO
" » No Swagger in .NET 9? Here’s What You Need to Know!." Aditya | Sciencx - Accessed . https://www.scien.cx/2025/01/11/no-swagger-in-net-9-heres-what-you-need-to-know/
IEEE
" » No Swagger in .NET 9? Here’s What You Need to Know!." Aditya | Sciencx [Online]. Available: https://www.scien.cx/2025/01/11/no-swagger-in-net-9-heres-what-you-need-to-know/. [Accessed: ]
rf:citation
» No Swagger in .NET 9? Here’s What You Need to Know! | Aditya | Sciencx | https://www.scien.cx/2025/01/11/no-swagger-in-net-9-heres-what-you-need-to-know/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.