How does the newer built-in Microsoft.AspNetCore.OpenApi package (introduced in .NET 9) differ from the third-party Swashbuckle package?
Short answer
Microsoft.AspNetCore.OpenApi is a first-party, built-in package for generating OpenAPI documents, designed for better performance (using source generators and reduced reflection overhead compared to Swashbuckle's runtime reflection-heavy approach) and tighter integration with…
Advertisement
AModel answer
Microsoft.AspNetCore.OpenApi is a first-party, built-in package for generating OpenAPI documents, designed for better performance (using source generators and reduced reflection overhead compared to Swashbuckle's runtime reflection-heavy approach) and tighter integration with minimal APIs, though as of its introduction it doesn't yet include a bundled interactive UI (like Swagger UI) out of the box -- teams often pair it with a separate UI package (like Scalar) or continue using Swashbuckle for its more mature, all-in-one tooling and broader ecosystem.
builder.Services.AddOpenApi(); // built-in, .NET 9+
var app = builder.Build();
app.MapOpenApi(); // exposes /openapi/v1.json
// Pairing with a separate UI, e.g., Scalar
app.MapScalarApiReference();Real-world example
A team building a new minimal-API-only microservice on .NET 9 adopts the built-in Microsoft.AspNetCore.OpenApi package for its lighter weight and native minimal API support, pairing it with Scalar for an interactive documentation UI instead of the heavier Swashbuckle package.
Likely follow-ups
- What functionality does Swashbuckle still offer that the built-in package lacks?
- How do you migrate an existing Swashbuckle-based project to the built-in package?
Related topics