Bye-Bye Swashbuckle, Hello OpenAPI: What’s New in ASP.NET Core 9?

Bye-Bye Swashbuckle, Hello OpenAPI: What’s New in ASP.NET Core 9?

?? Big Change in ASP.NET Core 9! ??

Swashbuckle is gone from the default template! ?? (Wait, what?!) Yep, no more built-in Swagger docs in .NET 9 because it’s not actively maintained anymore. But don’t panic ,things are actually getting better! ??


What’s the New Buzz?

The .NET team is like, "Why stick with the old when we’ve got something cooler?" ??♂? So, they’ve introduced native support for OpenAPI document generation in .NET 9. ?? Here’s how it goes down:

  • AddOpenApi(): Magic method to register all the OpenAPI dependencies.
  • MapOpenApi(): Boom! Your API docs are now live. ??


But How Do You Actually Use It?

No more 3rd-party tools, just a clean, native way to generate docs:

  1. Add OpenAPI services to your Program.cs like this:

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenApi();
var app = builder.Build();        


  1. Map the OpenAPI endpoints (where the docs live):

app.MapOpenApi(); app.Run();        

Swashbuckle Lovers, Don't Cry! ??

I know, I know... you got a soft spot for Swashbuckle. And yes, you can still add it manually, but why not upgrade? Enter Nswag, the shiny new kid on the block. ?


Why Switch to Nswag?

  • More features ??? (like client code generation in C# and TypeScript!)
  • Actively maintained ?? (unlike Swashbuckle)
  • Flexible ?? (you can still customize like a pro)

How to Add Nswag:

  1. Install it with a single command:

dotnet add package NSwag.AspNetCore        


  1. Update your Program.cs like this:

builder.Services.AddSwaggerDocument();         // Nswag swagger app.UseOpenApi(); app.UseSwaggerUi3();                                       // Slick Swagger UI app.Run();        


So, whether you want a simple, native OpenAPI setup or you still love a good swagger-y interface with Nswag, .NET 9 has you covered. ??


Remember:

  • Swashbuckle is gone, but you can still add it manually.
  • OpenAPI is native in .NET 9—just two quick methods to set it up.
  • Nswag is your new best friend for generating docs and client code.

No more tears, just swagger—oh, wait—Nswag swagger! ??

#DotNetCore #ASPNetCore9 #OpenAPI #Swagger #Nswag #APIDocs #DevLife #CSharp #CodingFun

要查看或添加评论,请登录

社区洞察

其他会员也浏览了