Skip to content
routebase
OpenAPIASP.NET CoreDocumentation

An OpenAPI Document on Every ASP.NET Core Build

· The Routebase Team

A hand-drawn comic of floating islands at night, where a courier carries a scroll labelled OpenAPI from a .NET forge to a hub station, and light trails lead on to islands signed Mocks, Tests, Lint and Docs

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.

dotnet add package Routebase.AspNetCore

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

using Routebase.AspNetCore;
 
var app = builder.Build();
app.MapRoutebaseApiReference();

3. Run your app.

dotnet run

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

API reference in the dark theme with the endpoints grouped by tag in the navigation on the left and the overview with the version, the server, the document downloads and the list of operations on the right.
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.

API reference in the light theme showing GET /products/{id} with its path parameter and responses, a cURL sample, the request playground with id 1 and the 200 response it just returned, and the example responses.
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, 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.

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.

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.

Code editor with a minimal API handler that returns an anonymous object, marked by the RBA0001 suggestion, and the quick-fix menu open with Extract a record for the anonymous response and Use TypedResults.
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.

<PropertyGroup>
  <GenerateDocumentationFile>true</GenerateDocumentationFile>
  <NoWarn>$(NoWarn);CS1591</NoWarn>
</PropertyGroup>
/// <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.

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.

<PropertyGroup>
  <OpenApiDocumentsDirectory>$(MSBuildProjectDirectory)/openapi</OpenApiDocumentsDirectory>
</PropertyGroup>
Code editor with the project explorer open, showing OrdersApi.json and OrdersApi.yaml in an openapi folder next to Program.cs, and the YAML document open in the editor.
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.

Header of the API reference with the Open in Routebase menu expanded, listing Rate and lint, Mock server, Publish docs, Smoke tests and Keep in sync on every build, none of them run yet.
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.

Header of the API reference with the status chip reading In Routebase, Score C 55, Mock running and Tests 6/6 passed, and the expanded Open in Routebase menu with the grade at Rate and lint, the mock URL at Mock server and 6/6 passed at Smoke tests.
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.

<PropertyGroup>
  <RoutebaseProject>3f2b6c1e-0000-0000-0000-000000000000</RoutebaseProject>
</PropertyGroup>
<ItemGroup>
  <RoutebaseSpecLink Include="Orders API" />
</ItemGroup>
- run: dotnet build
  env:
    ROUTEBASE_API_KEY: ${{ secrets.ROUTEBASE_API_KEY }}
Connect build sheet in the Routebase app with the button that copies one prompt for a coding agent, the command that adds the package and the project file lines with the project ID and the spec ID already filled in.
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.

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.
Problems panel of the IDE after a build, listing the Routebase rating summary RB1201 with grade C against a target of B, the failed rating checks RB1202 and the style-guide findings RB1203, one entry each and all from the source dotnet.
The grade, the failed rating checks and the style-guide findings of every push land in the error list of your IDE.
Routebase page for a refused push, listing the breaking changes of the document with the buttons Accept and update the draft, Reject, the code has to change and Open a branch with a merge request.
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 under the MIT license.

The guide Routebase for ASP.NET 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.

Ready to ship on it?

Routebase is live. Design your API once — docs, mocks, tests, and monitoring all follow from the same source.

14-day Pro trial — no credit card required.