Theory question separating the OpenAPI specification from the Swagger tooling brand, the move from Swashbuckle to Microsoft.AspNetCore.OpenApi in the .NET 9+ templates, how the three document generators compare, and the role of UI viewers such as Swagger UI and Scalar.
OpenAPI is the vendor-neutral specification for describing HTTP APIs (paths, operations, schemas, security), currently 3.0 and 3.1. Swagger was the original name of that spec up to 2.0 and is now SmartBear's tooling brand (Swagger UI, Swagger Editor). In ASP.NET Core two jobs are separate: a generator builds the OpenAPI document from your endpoints, and a viewer renders it.
Microsoft.AspNetCore.OpenApi (AddOpenApi, MapOpenApi) instead of Swashbuckle, and ship no UI.The trade-off: the built-in generator is first-party and AOT-friendly, while Swashbuckle and NSwag have more mature extensions and, for NSwag, client generation.
"OpenAPI and Swagger get used as if they were the same thing, but they're not. OpenAPI is the specification: a JSON or YAML document that describes every path, operation, parameter, response schema and security scheme of an HTTP API. It's run by the OpenAPI Initiative, and the versions you see in .NET today are 3.0 and 3.1. Swagger was the original name of the spec up to version 2.0; after it was donated to the Linux Foundation it was renamed OpenAPI, and 'Swagger' became SmartBear's tooling brand, so Swagger UI and Swagger Editor are tools that read an OpenAPI document.
In ASP.NET Core you need two separate pieces. A generator inspects your endpoints through API Explorer and produces the document; a viewer renders it as an interactive page. For years the template used Swashbuckle for both. Since .NET 9, the web API template uses Microsoft's own
Microsoft.AspNetCore.OpenApipackage instead:builder.Services.AddOpenApi()andapp.MapOpenApi(), which serves/openapi/v1.json. It ships no UI, so you add Swagger UI or Scalar yourself if you want one, and nothing stops you adding Swashbuckle or NSwag instead. In .NET 10 the built-in generator produces OpenAPI 3.1 by default, and it will also serve YAML if you map a route ending in.yaml.The mistake I see is people saying 'we use Swagger' when they mean three different things: the spec, the generator and the UI. Being precise matters because they're chosen independently. My default today is the built-in generator plus Scalar in Development only, and I'd keep Swashbuckle or NSwag where a project already depends on their filters or client generation."
| Term | What it is | Owner |
|---|---|---|
| OpenAPI 3.0 / 3.1 | The specification for describing HTTP APIs | OpenAPI Initiative (Linux Foundation) |
| Swagger 2.0 | The previous name and version of the spec | Historic |
| Swagger UI / Editor | Tools that render or edit an OpenAPI document | SmartBear |
| Swashbuckle | Third-party .NET generator plus bundled Swagger UI | Community |
| NSwag | Third-party .NET generator plus C#/TypeScript client generator | Community |
| Microsoft.AspNetCore.OpenApi | First-party generator (since .NET 9) | Microsoft |
| Scalar, ReDoc | Alternative viewers | Third party |
| Built-in | Swashbuckle | NSwag | |
|---|---|---|---|
| In the template | Yes (.NET 9+) | No longer | No |
| Customisation | Document, operation and schema transformers | Document, operation and schema filters | Processors |
| Native AOT | Supported | Reflection-heavy | Reflection-heavy |
| Client generation | No (use Kiota or NSwag) | No | Yes |
| Built-in UI | No | Swagger UI | Swagger UI, ReDoc |
| Generator | Advantages | Limitations |
|---|---|---|
| Built-in | First-party, ships with each .NET release, schemas come from the System.Text.Json contract the API really uses, AOT-friendly, build-time generation supported | Younger: fewer community extensions; no UI or client generator; transformer API changed with Microsoft.OpenApi 2.x in .NET 10 |
| Swashbuckle | Mature, many examples and filter packages, bundled UI | Separate release cadence, reflection-based, no AOT; check that its version supports your .NET and OpenAPI version |
| NSwag | Generator and client generator in one tool, CLI and MSBuild integration | Larger surface and its own conventions; overkill if you only need a document |
| Situation | Choice |
|---|---|
| New .NET 10 service | Built-in generator, add Scalar or Swagger UI for Development |
| Existing project with many Swashbuckle filters | Keep Swashbuckle until there's a reason to migrate |
| You want a generated C# or TypeScript client from the same tool | NSwag, or the built-in generator plus Kiota |
| Team unfamiliar with transformers, deadline close | Stay with what the team knows; migrate as a separate task |
On a new .NET 10 service we replaced Swashbuckle with AddOpenApi() and Scalar. The document moved from OpenAPI 3.0 to 3.1, nullable types came out as type: ["string", "null"] instead of nullable: true, and two of our three custom filters became small transformers of about 15 lines each. The UI is mapped only in Development, so the production attack surface is just the API itself.
Checks that the candidate understands the specification versus tooling distinction and knows the current .NET defaults rather than a pre-.NET 9 setup.
Green flags
AddOpenApi / MapOpenApi and ship no UI.Red flags
MapOpenApi renders a UI.2011 Swagger spec created (Wordnik)
2014 Swagger 2.0
2015 SmartBear donates the spec to the Linux Foundation -> OpenAPI Initiative
2017 OpenAPI 3.0 (components, requestBody, oneOf/anyOf)
2021 OpenAPI 3.1 (full JSON Schema 2020-12 alignment, type arrays for nullability, webhooks)
2024 OpenAPI 3.1.1 (clarifications, no new features)
2025 OpenAPI 3.2 published; ASP.NET Core 10 still emits 3.1 (or 3.0 on request)
The spec is the contract; everything else is tooling built around it. Check what version your consumers (gateways, client generators, linters) accept before assuming the newest one.
Endpoints + metadata
|
v
API Explorer (IApiDescriptionGroupCollectionProvider)
|
v
Generator ----------------> /openapi/v1.json (or .yaml if mapped)
(built-in, Swashbuckle, NSwag) |
v
Viewer: Swagger UI, Scalar, ReDoc
Clients: Kiota, NSwag, openapi-generator
CI: linting, breaking-change checks
All three generators read the same API Explorer data that ASP.NET Core builds from route templates, parameter binding and response metadata. That is why the quality of your metadata (Produces, TypedResults, names, tags) matters more than which generator you pick.
AddOpenApi("v1") registers a named document; you can register several (internal, public).MapOpenApi() maps /openapi/{documentName}.json. For YAML, map a second route such as app.MapOpenApi("/openapi/{documentName}.yaml"); the .yaml extension selects the format.IOpenApiDocumentTransformer, IOpenApiOperationTransformer, IOpenApiSchemaTransformer.Swashbuckle.AspNetCore.SwaggerUI or static files).Scalar.AspNetCore, app.MapScalarApiReference()), with code samples in many languages.A viewer has no knowledge of your code. Point any of them at the JSON URL and they work.
dotnet new webapi on .NET 10 and open /openapi/v1.json. Note the "openapi": "3.1.x" field at the top.Scalar.AspNetCore, call app.MapScalarApiReference() in Development and browse /scalar/v1.AddOpenApi("internal") and confirm /openapi/internal.json exists./openapi/{documentName}.yaml and compare its size with the JSON version.A .NET 10 Minimal API with the built-in generator and a Development-only viewer.
// Program.cs
using Scalar.AspNetCore;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenApi(); // registers the "v1" document, OpenAPI 3.1 by default in .NET 10
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.MapOpenApi(); // /openapi/v1.json
app.MapOpenApi("/openapi/{documentName}.yaml"); // same document as YAML
app.MapScalarApiReference(); // /scalar/v1, a viewer, not a generator
}
app.MapGet("/products/{id:int}", (int id) => TypedResults.Ok(new Product(id, "Flat white", 5.20m)))
.WithName("GetProduct")
.WithTags("Products");
app.Run();
public sealed record Product(int Id, string Name, decimal Price);
<!-- Shop.Api.csproj: only the generator ships with the template; the viewer is your choice -->
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.*" />
<PackageReference Include="Scalar.AspNetCore" Version="2.*" />
</ItemGroup>
MapOpenApi() gives you a UI. Why it is wrong: It only serves the JSON document. Instead: Add Swagger UI, Scalar or ReDoc explicitly.IResult without Produces metadata show no response schema. Instead: Use TypedResults and endpoint metadata.options.OpenApiVersion to 3.0 if needed.The generator choice is less important than people think, because every generator reads the same API Explorer metadata. A senior focuses on the metadata quality, on who consumes the document (UI, client generators, gateways, CI checks) and on keeping one source of truth. For a new .NET 10 service I'd choose the built-in generator because it is first-party, supports Native AOT and follows the framework's release cadence, and add Scalar or Swagger UI only for Development.
| Option | When it fits | Cost | When not to |
|---|---|---|---|
Built-in Microsoft.AspNetCore.OpenApi |
New .NET 9/10 services, AOT | Fewer community extensions | You rely on a Swashbuckle-only filter ecosystem |
| Swashbuckle | Existing projects with many filters | Reflection-heavy, separate release cadence | Greenfield AOT services |
| NSwag | You want generator and C#/TypeScript client in one tool | Larger tool, its own conventions | You already use Kiota |
| No UI in production | Most internal APIs | Developers use Development or a portal | Public developer portals with auth |
You register a document with builder.Services.AddOpenApi("v1", o => ...) and serve it with app.MapOpenApi(), which maps /openapi/v1.json (a .yaml route also works in .NET 10). Customisation happens in transformers:
Info, servers, security schemes.For JWT you add a bearer scheme to Components.SecuritySchemes and a requirement on operations that have IAuthorizeData metadata. In .NET 10 the output is OpenAPI 3.1 by default (JSON Schema 2020-12, nullability as type arrays) on Microsoft.OpenApi 2.x, so some .NET 9 transformer code needs updating. The trade-off: transformers are explicit and AOT-friendly but you write the plumbing Swashbuckle filters used to give you.
Hiding the docs is not security: every endpoint must be protected by authentication and authorisation regardless. But publishing the full document hands an attacker a map: internal and admin endpoints, parameter names, limits, error shapes, sometimes examples with real personal data or OAuth client settings in the UI config.
My default for internal APIs is to map MapOpenApi() and the UI only in Development. If people need it in production, I put it behind RequireAuthorization("api-docs"), serve a separate curated document that excludes internal endpoints, or publish through an API Management developer portal.
For public or partner APIs a public document is the right call, as long as it's curated and the UI is patched. The trade-off: convenience for consumers versus cheaper reconnaissance.
I'd turn Program.cs back into a composition root and move endpoints into feature folders. Each feature gets one extension method, MapOrderEndpoints(this IEndpointRouteBuilder app), that creates a MapGroup("/orders") and applies shared metadata once: RequireAuthorization, WithTags, endpoint filters, rate limiting. Handlers become named static methods that return Results<Ok<OrderDto>, NotFound> built with TypedResults, so every outcome is compile-time checked and appears in the OpenAPI document. Then testing is easy at two levels: unit tests call the static handler directly and assert the result type, and integration tests use WebApplicationFactory<Program> with ConfigureTestServices to swap the database or external clients. The trade-off: a little more structure up front, in exchange for endpoints that stay readable at 80 or 800.
Last updated 23 Nov 2026.