With the .NET 10 SDK, what does dotnet new webapi generate by default, and how do --use-controllers, --no-openapi and --no-https change it?
answer
- Minimal APIs unless told otherwise
- -controllers / --use-controllers
- AddOpenApi + MapOpenApi, Development only
- Microsoft.AspNetCore.OpenApi, no Swashbuckle
- --no-https drops UseHttpsRedirection
basics
~20 sIn .NET 10, dotnet new webapi writes a Minimal API project on Microsoft.NET.Sdk.Web: one weather-forecast MapGet, the built-in OpenAPI document mapped in Development, and HTTPS redirection. --use-controllers, --no-openapi and --no-https switch those parts off or over.
solid answer
~30 sA plain `dotnet new webapi` gives a **Minimal API** project: `Program.cs` calls `WebApplication.CreateBuilder`, `AddOpenApi()`, maps `MapOpenApi()` only when `app.Environment.IsDevelopment()`, calls `UseHttpsRedirection()` and maps one `GET /weatherforecast` endpoint. The `.csproj` uses `Microsoft.NET.Sdk.Web` with `Nullable` and `ImplicitUsings` enabled and references just `Microsoft.AspNetCore.OpenApi`, plus a `.http` file for trying the endpoint. `--use-controllers` (`-controllers`) switches to `AddControllers()`, `UseAuthorization()`, `MapControllers()` and a `WeatherForecastController` with `[ApiController]`. `--no-openapi` removes the OpenAPI package and both calls. `--no-https` removes the https launch profile and `UseHttpsRedirection()`. There is no Swashbuckle, no Swagger UI and no `--aot` flag: Native AOT is the separate `webapiaot` template.
code
bash · 1 linedotnet new webapi --use-controllers --no-openapi -o ParcelLockers.Apigo deeper
Recall that the default is Minimal APIs with one weather-forecast endpoint, that controllers need --use-controllers, and that OpenAPI comes from Microsoft.AspNetCore.OpenApi, not Swashbuckle.
Explain each flag's effect on Program.cs and the csproj, why MapOpenApi sits behind IsDevelopment, and why --no-https is ignored for SingleOrg and IndividualB2C.
Show you scaffold deliberately: pick controllers or Minimal APIs for the team, decide whether the document ships beyond Development, and know that AOT means the webapiaot template.
Treat the template as a team baseline: which defaults you keep across services, where the API contract is published, and how a shared scaffold avoids every repo drifting.
## What the default command writes `dotnet new webapi` is the ASP.NET Core Web API template. In the .NET 10 SDK it describes itself as using "ASP.NET Core controllers or minimal APIs, with optional support for OpenAPI and authentication", and the defaults pick **Minimal APIs**, **OpenAPI on**, **HTTPS on** and **no authentication**. A run of `dotnet new webapi -o ParcelLockers.Api` produces: - `ParcelLockers.Api.csproj` with `Sdk="Microsoft.NET.Sdk.Web"`, `TargetFramework` `net10.0`, `<Nullable>enable</Nullable>` and `<ImplicitUsings>enable</ImplicitUsings>`; - a single `PackageReference` to **`Microsoft.AspNetCore.OpenApi`** — everything else comes from the `Microsoft.AspNetCore.App` shared framework; - `Program.cs` holding the whole app, including a `record WeatherForecast`; - `appsettings.json` and `appsettings.Development.json` with log levels and `AllowedHosts`; - a launch-settings file under `Properties/` for local runs; - `ParcelLockers.Api.http`, a request file that issues `GET /weatherforecast/` against the local port. ## The Program.cs the default writes The generated pipeline is short. The builder registers `builder.Services.AddOpenApi()`, the app maps `app.MapOpenApi()` inside an `if (app.Environment.IsDevelopment())` block, calls `app.UseHttpsRedirection()`, and maps `app.MapGet("/weatherforecast", ...)` with `.WithName("GetWeatherForecast")`. The OpenAPI document is served at `/openapi/v1.json` — `MapOpenApi`'s default pattern is `/openapi/{documentName}.json` and the default document name is `v1` — and because of the `IsDevelopment()` guard it is **not** served in Production. In .NET 10 that document is OpenAPI **3.1** by default. What the template does **not** add matters as much in an interview: - **No Swashbuckle and no UI.** Since .NET 9 the templates use the built-in `Microsoft.AspNetCore.OpenApi` generator; `AddSwaggerGen`, `UseSwagger` and `UseSwaggerUI` come only from the separate Swashbuckle.AspNetCore packages, which you add yourself if you want them. - **No controllers folder** unless you ask for one. - **No authentication** unless `--auth` names a scheme. ## The flags that change the shape | Flag | Default | What it changes | |---|---|---| | `-controllers`, `--use-controllers` | false | Generates `Controllers/WeatherForecastController.cs` (`[ApiController]`, `[Route("[controller]")]`), `WeatherForecast.cs`, and a `Program.cs` with `AddControllers()`, `UseAuthorization()`, `MapControllers()` | | `--no-openapi` | false | Drops the `Microsoft.AspNetCore.OpenApi` reference, `AddOpenApi()`, `MapOpenApi()` and the `.WithName(...)` call | | `--no-https` | false | Drops the https launch profile and `UseHttpsRedirection()`; ignored for `--auth SingleOrg` and `--auth IndividualB2C`, which require HTTPS | | `--auth` | `None` | `IndividualB2C`, `SingleOrg` or `Windows`; there is no `Individual` choice on `webapi` | | `--use-program-main` | false | An explicit `Program` class with `Main` instead of top-level statements | | `--exclude-launch-settings` | false | No launch-settings file | Two traps hide in that list. `--use-minimal-apis` (`-minimal`) still exists but is **hidden**: Minimal APIs are already the default and `--use-controllers` overrides it. And there is **no opt-in OpenAPI flag** — OpenAPI is on, and `--no-openapi` is the only switch. ## A worked scaffold A courier start-up wants its parcel-locker API on controllers, with no OpenAPI document because the contract is published separately: 1. Run `dotnet new webapi --use-controllers --no-openapi -o ParcelLockers.Api`. 2. Open `Program.cs`: it registers `AddControllers()` and nothing else, then calls `UseHttpsRedirection()`, `UseAuthorization()` and `MapControllers()`. 3. Add a `LockersController` beside the generated `WeatherForecastController`; it needs `using Microsoft.AspNetCore.Mvc;` because that namespace is not one of the Web SDK's implicit usings. The `UseAuthorization()` call is there even without `--auth`; it lets requests through until an endpoint carries authorization metadata such as `[Authorize]`. ## How the defaults got here - **.NET 8** made Minimal APIs the `webapi` default, added `--use-controllers`, and introduced Native AOT as a separate template, `webapiaot`, rather than a `webapi` flag. - **.NET 9** replaced Swashbuckle in the templates with `AddOpenApi` / `MapOpenApi`. - **.NET 10** generates OpenAPI 3.1 documents by default (`OpenApiOptions.OpenApiVersion`). Anyone who learned on .NET 6 or 7 expects `AddSwaggerGen()` and a Swagger UI page at `/swagger`; on a .NET 10 scaffold neither exists until a package is added. ## Interview traps around this template - **"Minimal APIs are only for tiny services."** The default is a starting style, not a size limit; controllers remain fully supported and one flag away. - **"The template is Production-ready as written."** It is a starting point: there is no authentication, no exception handler, no health check and no ProblemDetails setup — each is added deliberately later. - **"OpenAPI must be on to call the API from a client."** The document only describes the API for tooling; `--no-openapi` changes nothing about how requests are served. - **"The `.http` file is a test suite."** It is a scratch request file for an editor's HTTP client, pointed at the local port through a `@..._HostAddress` variable; it is not run by `dotnet test`. - **"Switching later means re-scaffolding."** Moving from Minimal APIs to controllers, or adding OpenAPI after `--no-openapi`, is a few lines in `Program.cs` and one package reference; the flags only choose the starting state.
- Where is the OpenAPI document of a default .NET 10 webapi project served, and in which environments?At `/openapi/v1.json`: `MapOpenApi()` defaults to the pattern `/openapi/{documentName}.json` and the document name `v1`. The template wraps the call in `if (app.Environment.IsDevelopment())`, so Staging and Production do not expose it unless you move the call. No UI is generated; a Swagger UI or Scalar page is a separate package you add.
- What does --use-minimal-apis do on the .NET 10 webapi template?Practically nothing: it is a hidden option whose value already defaults to Minimal APIs. The template computes `UsingControllers` as `UseControllers || !UseMinimalAPIs`, so `--use-controllers` wins whenever both are passed.
- Why might dotnet new webapi --auth SingleOrg --no-https still produce an HTTPS app?Because `SingleOrg` and `IndividualB2C` set the template's `RequiresHttps` condition. The https profile and `UseHttpsRedirection()` stay, and the http-only profile is dropped; `--no-https` only takes effect with `None` or `Windows` authentication.
- dotnet new webapi adds Swashbuckle with AddSwaggerGen and UseSwaggerUI
- dotnet new webapi creates a Controllers folder unless you pass --use-minimal-apis
- Pass --aot to dotnet new webapi for a Native AOT API
- The template maps MapOpenApi in every environment, so Production serves /openapi/v1.json
- dotnet new webapi --auth Individual gives the API local Identity accounts
Assumes the ASP.NET Core 10.0 templates: Minimal APIs became the webapi default in .NET 8, built-in OpenAPI replaced Swashbuckle in .NET 9, and 10 emits OpenAPI 3.1.