# An OpenAPI Document on Every ASP.NET Core Build — Routebase

> AI agents can read every page of this site as Markdown, and the full index is at https://routebase.dev/llms.txt.

> One package gives your ASP.NET Core API interactive docs and writes its OpenAPI document as JSON and YAML at build time. See the setup and what Routebase adds.

Canonical page: https://routebase.dev/blog/aspnet-core-openapi-on-every-build/
Published: 2026-12-01 · The Routebase Team · OpenAPI, ASP.NET Core, Documentation

Your ASP.NET Core API already knows everything its docs need. Every route, every
parameter and every response type is in the code, so getting docs shouldn't
take a separate tool, a hand-written page or an afternoon of setup.

With Routebase.AspNetCore 1.0, it takes one package, one line in `Program.cs`
and one build. This post shows those three steps first, and then the JSON and
YAML documents that the build writes. After that, you'll see what makes the
descriptions clean, what's worth knowing before you ship, and what Routebase
adds when you sign up.

## Docs in three steps

Start with any ASP.NET Core API that uses OpenAPI. A new project from the
`webapi` template already does, because it registers
`builder.Services.AddOpenApi()`.

**1. Add the package.**

```bash
dotnet add package Routebase.AspNetCore
```

**2. Add one line to `Program.cs`,** right after `var app = builder.Build();`.

```csharp
using Routebase.AspNetCore;

var app = builder.Build();
app.MapRoutebaseApiReference();
```

**3. Run your app.**

```bash
dotnet run
```

Open `/routebase` on the address your app prints, and your docs are there.

_Screenshot: The docs that the package serves at /routebase, here in the dark theme with the overview of the API._

The page lists your endpoints by tag, with a search and code samples for each
one. Its playground sends requests to your API straight from the browser, and
**Copy as Markdown** hands an endpoint to an AI assistant with its parameters,
request body and responses. You can also download the document as JSON, as YAML
or as a Postman collection, and every schema has a page of its own.

_Screenshot: Each endpoint shows its parameters, code samples and a playground that sends the request from your browser to your API._

Behind the page, every build now writes your OpenAPI document as JSON and as
YAML, and the docs read that file. So they show exactly the build you deployed,
and they work in production without a runtime document route.

## Generate OpenAPI JSON and YAML at build time

Those two files are useful on their own. After `dotnet build`, your OpenAPI
document sits in the `obj` folder as JSON and as YAML, for example
`obj/OrdersApi.json` and `obj/OrdersApi.yaml`, and you can hand either one to
any tool that reads OpenAPI.

The YAML file is the one you don't get from ASP.NET Core alone. The build-time
generation that ships with it writes JSON only.
[Microsoft's documentation](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/openapi/aspnetcore-openapi),
last updated in November 2026, says that YAML at build time "isn't supported but
planned for a future preview".

With Routebase.AspNetCore, you don't wait for that preview and you don't
maintain a conversion step. Every build writes a YAML copy next to the JSON
document, and the copy holds the same document key for key and in the same
order.

## Clean descriptions

The docs can only be as good as what your code declares. Three things turn a
list of routes into a reference that people can actually work with.

### Say what each endpoint does

Give each endpoint a tag, a summary and a description. The tag groups the
endpoint in the navigation, and the summary and the description tell the reader
what it does and when to use it.

```csharp
app.MapGet("/products/{id:int}", GetProduct)
    .WithTags("Products")
    .WithSummary("Get a product")
    .WithDescription("Returns one product by its ID, or 404 when no product has that ID.");
```

### Let every response show up

A handler that returns `Results.Ok(product)` hides the type from the OpenAPI
generator, which would document a bare 200 without a body and skip the 404. The
package reads such handlers while your app compiles and adds the responses for
you. So the endpoint below shows a 200 with `Product` and a 404 with `ApiError`,
and you don't change a line.

```csharp
app.MapGet("/products/{id:int}", (int id, DataStore db) =>
    db.Products.FirstOrDefault(p => p.Id == id) is { } product
        ? Results.Ok(product)
        : Results.NotFound(new ApiError("NOT_FOUND", "Product not found.")));
```

Where the build can't read a handler, for example because one path returns an
anonymous object, your editor marks it and offers a fix. One click switches the
handler to `TypedResults` or turns the anonymous object into a record, and the
JSON your clients get stays the same. Controllers get the same help, where the
fix adds the missing `[ProducesResponseType]` attributes.

_Screenshot: Where the build can't read a handler, the editor offers a fix that puts the response into the docs._

### Describe your models

Your schemas take their descriptions from the XML comments you may already
write. Switch on the documentation file in the project file, and the second
line keeps the compiler from asking for a comment on every public member.

```xml
<PropertyGroup>
  <GenerateDocumentationFile>true</GenerateDocumentationFile>
  <NoWarn>$(NoWarn);CS1591</NoWarn>
</PropertyGroup>
```

```csharp
/// <summary>A product in the catalog.</summary>
/// <param name="Id">The product ID.</param>
/// <param name="Name">The name shown in the shop.</param>
public record Product(int Id, string Name);
```

## Good to know before you ship

**The build starts your app.** To read your endpoints, the build runs
`Program.cs` in the `Production` environment without its runtime configuration.
A registration that needs a connection string or a secret fails there, so skip
it while the document is written.

```csharp
if (!RoutebaseOpenApi.IsGeneratingDocument)
{
    builder.Services.AddSingleton(new PaymentClient(builder.Configuration["Payments:ApiKey"]!));
}
```

**The document can live in your repository.** The files start out in `obj/`,
which nobody commits. Set the folder in the project file, and every API change
shows up in the diff of the pull request that made it.

```xml
<PropertyGroup>
  <OpenApiDocumentsDirectory>$(MSBuildProjectDirectory)/openapi</OpenApiDocumentsDirectory>
</PropertyGroup>
```

_Screenshot: With the folder set in the project file, the JSON and the YAML document sit next to your code._

**You decide who sees the docs.** The page works in production, so map it
inside `if (app.Environment.IsDevelopment())` to keep it on your machine, or
protect it with `.RequireAuthorization()` like any other endpoint.

**Your generator stays.** The package works with Microsoft.AspNetCore.OpenApi,
Swashbuckle and NSwag, and the build-time generation it brings along adds
nothing to the output of your app.

## What Routebase adds

Up to here, everything runs on your machine without an account. Routebase takes
the same document further, and you start right from your docs page.

### One click from localhost

While your docs run on `localhost`, their header carries the menu **Open in
Routebase**. Each action opens a Routebase tab and takes your document along:

- **Rate and lint** grades the design of your API and checks it against your organization's style guide.
- **Mock server** starts a stand-in for your API that answers from the document, so a frontend can build against it before the backend is done.
- **Publish docs** puts your docs on a hosted docs portal.
- **Smoke tests** creates one quick test per endpoint and runs it against the app on your machine, straight from your browser.

Without an account, you sign up first and land back on the same step. Until you
sign in, your document stays in your browser.

_Screenshot: On localhost, your docs carry a menu that takes the document into Routebase._

Once an action has run, your docs show its result right next to the menu. In
the capture below, the API scored a C with 55 points, the mock server is
running, and all six smoke tests passed against the app on this machine. Each
menu entry links to its result, such as the mock URL or the test run.

_Screenshot: After an action, the docs show its result next to the menu, and each menu entry links to it._

### Every build checked in CI

When you want this on every build instead of one click at a time, pick **Keep in
sync on every build** in the same menu, or **Connect build…** on a spec in the
Routebase app. The sheet fills in the lines for your project file and your CI
step, and it creates a build key with one click. That key only works for specs
in this one project. The package reads it only from the environment variable
`ROUTEBASE_API_KEY`, so it never lands in a committed file.

```xml
<PropertyGroup>
  <RoutebaseProject>3f2b6c1e-0000-0000-0000-000000000000</RoutebaseProject>
</PropertyGroup>
<ItemGroup>
  <RoutebaseSpecLink Include="Orders API" />
</ItemGroup>
```

```yaml
- run: dotnet build
  env:
    ROUTEBASE_API_KEY: ${{ secrets.ROUTEBASE_API_KEY }}
```

_Screenshot: Connect build… fills in the IDs of your project and your spec, and one prompt hands the setup to your coding agent while the key stays with you._

From then on, your CI build does four things on its own:

- **Every merge updates Routebase.** A build of your default branch pushes the document into your API in Routebase, and the tests and mock rules you linked there keep their links.
- **Every pull request shows its effect.** With the key set, its build lists what a push would change, breaking changes included, before you merge.
- **Every push gets a grade.** The API rating scores your API from 0 to 100 with a grade from A to E, and the result lands in your IDE's error list next to your compiler warnings. The rating is part of the Pro plan.
- **Every breaking change waits for a decision.** A change that breaks existing clients, such as a removed endpoint, stops the build, and a page in Routebase lets your team accept it, reject it or review it on a branch.

In the build log, each of these messages carries a code that starts with `RB`,
the same way compiler warnings start with `CS`, and the guide explains every one
of them.

_Figure: The same build ends in three places. A pull request only previews, a build of the default branch pushes and gets its grade, and a breaking change fails the build. The right column shows the code each one leaves in your build log._

_Screenshot: The grade, the failed rating checks and the style-guide findings of every push land in the error list of your IDE._

_Screenshot: A breaking change lands on one page in Routebase, where your team decides whether the contract or the code has to change._

## Get started

Add the package, add the line and run your app, and your docs are there. The
package supports .NET 10 and .NET 11, and it's on
[NuGet](https://www.nuget.org/packages/Routebase.AspNetCore) under the MIT
license.

The guide [Routebase for ASP.NET Core](https://docs.routebase.dev/routebase-for-aspnet-core/)
covers every setting and every build message. When you want the rating, the
mock server and the breaking-change check on every build, connect your first
build from your docs page or from **Connect build…** in Routebase. You can start
on the Free plan, and the rating comes with the 14-day Pro trial, which needs no
credit card.

---

[Routebase](https://routebase.dev/) — [Sign up](https://app.routebase.dev/): Every account starts with a 14-day Pro trial — no credit card required.
