📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

What is the difference between OpenAPI and Swagger? Explain why the .NET 9+ web API templates no longer ship Swashbuckle, how the built-in Microsoft.AspNetCore.OpenApi package compares with Swashbuckle and NSwag, and what Swagger UI and Scalar actually do.

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.

Junior Theory Beginner api-documentation aspnet-core openapi scalar swagger swashbuckle

🎯 Key points

  • OpenAPI is the specification (OpenAPI Initiative, versions 3.0 and 3.1); Swagger is SmartBear's tooling brand and the old name of the spec (Swagger 2.0)
  • Generator produces the JSON/YAML document; a viewer (Swagger UI, Scalar, ReDoc) only renders it
  • Since .NET 9 the webapi template uses Microsoft.AspNetCore.OpenApi (AddOpenApi / MapOpenApi) and includes neither Swashbuckle nor a UI, though you can still add Swashbuckle or NSwag yourself
  • In .NET 10 the built-in generator emits OpenAPI 3.1 by default; YAML is served only if you map a .yaml route
  • Swashbuckle and NSwag remain maintained third-party options; NSwag also generates C# and TypeScript clients
  • The document is served at /openapi/v1.json by default and is normally only mapped in Development

⏱ 30-second answer

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.

  • Since .NET 9 the templates use Microsoft's own Microsoft.AspNetCore.OpenApi (AddOpenApi, MapOpenApi) instead of Swashbuckle, and ship no UI.
  • In .NET 10 it emits OpenAPI 3.1 by default.
  • Swagger UI or Scalar are optional viewers you add yourself.

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.

🗣 Full answer (senior)

How I would answer this in an interview

"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.OpenApi package instead: builder.Services.AddOpenApi() and app.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."


The terms

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

Generators compared

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

Advantages and limitations

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

How to choose

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

Production example

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.

🔍 What the interviewer is checking

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

  • Defines OpenAPI as the spec and Swagger as the tooling brand and old spec name.
  • Knows the .NET 9+ templates use AddOpenApi / MapOpenApi and ship no UI.
  • Separates generator, viewer and client generator.
  • Mentions OpenAPI 3.1 as the .NET 10 default.

Red flags

  • Thinks Swashbuckle is still the template default.
  • Believes MapOpenApi renders a UI.
  • Exposes the docs in production without thinking about it.

📚 Learn in depth

1. Where the names came from

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.

2. Generator and viewer are separate

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.

3. The built-in package

  • 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.
  • Customisation is through transformers: IOpenApiDocumentTransformer, IOpenApiOperationTransformer, IOpenApiSchemaTransformer.
  • .NET 10 moves to Microsoft.OpenApi 2.x to support 3.1, which changed some object-model types; old transformer code may need small fixes.

4. Viewers

  • Swagger UI: classic try-it-out page (Swashbuckle.AspNetCore.SwaggerUI or static files).
  • Scalar: newer reference UI (Scalar.AspNetCore, app.MapScalarApiReference()), with code samples in many languages.
  • ReDoc: read-only, good for public docs.

A viewer has no knowledge of your code. Point any of them at the JSON URL and they work.

Try it yourself

  1. Create dotnet new webapi on .NET 10 and open /openapi/v1.json. Note the "openapi": "3.1.x" field at the top.
  2. Add Scalar.AspNetCore, call app.MapScalarApiReference() in Development and browse /scalar/v1.
  3. Point Swagger UI at the same JSON and compare the two viewers.
  4. Add a second document with AddOpenApi("internal") and confirm /openapi/internal.json exists.
  5. Map /openapi/{documentName}.yaml and compare its size with the JSON version.

💻 Code

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>

⚠ Common mistakes

  • Mistake: Calling the specification "Swagger" and the UI "OpenAPI". Why it is wrong: It confuses the contract with the tools, and makes conversations about versions (2.0 vs 3.1) meaningless. Instead: Say OpenAPI for the document, and name the generator and the viewer separately.
  • Mistake: Thinking MapOpenApi() gives you a UI. Why it is wrong: It only serves the JSON document. Instead: Add Swagger UI, Scalar or ReDoc explicitly.
  • Mistake: Installing Swashbuckle and the built-in package together. Why it is wrong: Two generators, two documents, confusing differences, and Swashbuckle's SwaggerGen can interfere with build-time generation. Instead: Pick one generator per project.
  • Mistake: Assuming the document is automatically correct. Why it is wrong: Endpoints returning IResult without Produces metadata show no response schema. Instead: Use TypedResults and endpoint metadata.
  • Mistake: Mapping the document and UI unconditionally. Why it is wrong: You publish your full API surface, including internal endpoints, to anyone. Instead: Gate them by environment or protect them with authorisation.
  • Mistake: Assuming every tool reads OpenAPI 3.1. Why it is wrong: Some older client generators and gateways only understand 3.0. Instead: Check your consumers; set options.OpenApiVersion to 3.0 if needed.

🏛 Senior insight: trade-offs

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

🔗 Follow-ups the interviewer may ask

  1. When: Candidate says they use AddOpenApi in new projects. Why: Checks hands-on use of the built-in generator beyond the defaults.
    How to answer

    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:

    • Document transformers change the whole document: Info, servers, security schemes.
    • Operation transformers change one operation: add a security requirement or a header.
    • Schema transformers change the schema of one type: formats, examples.

    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.

  2. When: Candidate maps the UI or the document unconditionally. Why: Checks security thinking about publishing the API surface.
    How to answer

    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.

  3. When: Candidate mentions that metadata quality drives the document. Why: Checks how TypedResults and route groups produce good OpenAPI metadata.
    How to answer

    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.

↩ Usually asked after

More in API Features

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me