SwaggerDiff.AspNetCore 1.5.2

dotnet add package SwaggerDiff.AspNetCore --version 1.5.2
                    
NuGet\Install-Package SwaggerDiff.AspNetCore -Version 1.5.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SwaggerDiff.AspNetCore" Version="1.5.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SwaggerDiff.AspNetCore" Version="1.5.2" />
                    
Directory.Packages.props
<PackageReference Include="SwaggerDiff.AspNetCore" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SwaggerDiff.AspNetCore --version 1.5.2
                    
#r "nuget: SwaggerDiff.AspNetCore, 1.5.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SwaggerDiff.AspNetCore@1.5.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SwaggerDiff.AspNetCore&version=1.5.2
                    
Install as a Cake Addin
#tool nuget:?package=SwaggerDiff.AspNetCore&version=1.5.2
                    
Install as a Cake Tool

SwaggerDiff.AspNetCore

An in-app OpenAPI diff viewer for ASP.NET Core APIs. Embeds a diff viewer UI and wires up minimal API endpoints — no controllers required.

Compare versioned OpenAPI snapshots side-by-side from within your running application.

Prerequisites

oasdiff

The library uses oasdiff under the hood to compute OpenAPI diffs. You don't need to install it yourself — on the first comparison request, the library will automatically:

  1. Check if oasdiff is already on your PATH
  2. If not, download the correct binary for your platform to ~/.swaggerdiff/bin/{version}/
  3. Cache it for all subsequent calls

Supported platforms for auto-download: Linux (amd64/arm64), macOS (universal), Windows (amd64/arm64).

If you prefer to manage the binary yourself, you can either install oasdiff globally or point to a specific binary:

builder.Services.AddSwaggerDiff(options =>
{
    options.OasDiffPath = "/usr/local/bin/oasdiff";  // skip auto-download, use this binary
});

Installation

dotnet add package SwaggerDiff.AspNetCore

Setup

1. Register services

using SwaggerDiff.AspNetCore.Extensions;

builder.Services.AddSwaggerDiff();

With custom options:

builder.Services.AddSwaggerDiff(options =>
{
    options.VersionsDirectory = "Snapshots";       // default: "Docs/Versions"
    options.FilePattern = "swagger_*.json";         // default: "doc_*.json"
    options.RoutePrefix = "/api-diff";              // default: "/swagger-diff"
    options.OasDiffVersion = "1.11.10";            // default: "1.11.10"
    options.OasDiffPath = "/usr/local/bin/oasdiff"; // default: null (auto-detect/download)
});

2. Map the UI and endpoints

var app = builder.Build();

app.UseSwagger();
app.UseSwaggerUI(options =>
{
    options.AddSwaggerDiffButton();  // adds a "Diff Tool" button to Swagger UI
});

app.UseSwaggerDiff();  // serves the diff viewer + maps /api-docs/versions and /api-docs/compare

That's it. Navigate to /swagger-diff to see the diff viewer, or click the injected button from within Swagger UI.

How it works

AddSwaggerDiff() registers the following services:

  • SwaggerDiffOptions — configurable paths, route prefix, and oasdiff binary settings
  • OasDiffDownloader (singleton) — locates or auto-downloads the oasdiff binary on first use
  • IApiDiffClient / OasDiffClient — shells out to oasdiff to compute HTML diffs
  • SwaggerDiffService — lists available snapshots and orchestrates comparisons

UseSwaggerDiff() does two things:

  1. Maps minimal API endpoints (no controllers, no AddControllers() required):

    • GET /api-docs/versions — returns available snapshot filenames
    • POST /api-docs/compare — accepts { oldVersionName, newVersionName, comparisonType } and returns the HTML diff
    • Both endpoints are excluded from the Swagger spec via .ExcludeFromDescription()
  2. Serves the embedded diff viewer at the configured route prefix using EmbeddedFileProvider, so there are no loose files to deploy.

Snapshot directory

The library expects versioned JSON files in a directory relative to AppDomain.CurrentDomain.BaseDirectory:

bin/Debug/net8.0/
  Docs/
    Versions/
      doc_20250101120000.json
      doc_20250115093000.json

The filenames (minus .json) appear as version options in the diff viewer's dropdowns.

Use the companion CLI tool SwaggerDiff.Tool to generate these snapshots from a built assembly without starting the web server.

Options reference

Property Default Description
VersionsDirectory Docs/Versions Path (relative to base directory) containing snapshot files
FilePattern doc_*.json Glob pattern for discovering snapshot files
RoutePrefix /swagger-diff URL path where the diff viewer UI is served
OasDiffPath null Explicit path to an oasdiff binary. Skips PATH lookup and auto-download when set
OasDiffVersion 1.11.10 oasdiff version to auto-download if not found on PATH

Full example

// Program.cs
using SwaggerDiff.AspNetCore;
using SwaggerDiff.AspNetCore.Extensions;

var builder = WebApplication.CreateBuilder(args);

if (!SwaggerDiffEnv.IsDryRun)
{
    builder.ConfigureSecretVault();
}

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddSwaggerDiff();

var app = builder.Build();

app.UseSwagger();
app.UseSwaggerUI(o => o.AddSwaggerDiffButton());
app.UseSwaggerDiff();

app.MapGet("/hello", () => "world");

app.Run();
Package Description
SwaggerDiff.Tool CLI tool that generates OpenAPI snapshots from built assemblies without running the web server

License

MIT

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.5.2 53 3/10/2026
1.5.1 79 3/6/2026
1.5.0 84 3/1/2026
1.4.1 100 3/1/2026
1.4.0 88 3/1/2026
1.3.0 84 3/1/2026
1.2.1 79 3/1/2026
1.2.0 91 2/28/2026
1.1.1 95 2/28/2026
1.1.0 80 2/28/2026
1.0.0 84 2/28/2026