Npap.Yarp.ReverseProxy.OpenApi 5.0.6

dotnet add package Npap.Yarp.ReverseProxy.OpenApi --version 5.0.6
                    
NuGet\Install-Package Npap.Yarp.ReverseProxy.OpenApi -Version 5.0.6
                    
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="Npap.Yarp.ReverseProxy.OpenApi" Version="5.0.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Npap.Yarp.ReverseProxy.OpenApi" Version="5.0.6" />
                    
Directory.Packages.props
<PackageReference Include="Npap.Yarp.ReverseProxy.OpenApi" />
                    
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 Npap.Yarp.ReverseProxy.OpenApi --version 5.0.6
                    
#r "nuget: Npap.Yarp.ReverseProxy.OpenApi, 5.0.6"
                    
#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 Npap.Yarp.ReverseProxy.OpenApi@5.0.6
                    
#: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=Npap.Yarp.ReverseProxy.OpenApi&version=5.0.6
                    
Install as a Cake Addin
#tool nuget:?package=Npap.Yarp.ReverseProxy.OpenApi&version=5.0.6
                    
Install as a Cake Tool

From Configuration

Update appsettings.json:

{
  "ReverseProxy": {
    "Clusters": {
      "App1Cluster": {
        "Destinations": {
          "Default": {
            "Address": "https://localhost:5101",
            "OpenApiDocs": [ // <-- this block
              {
                "PrefixPath": "/proxy-app1",
                "Paths": [
                  "/openapi/v1.json"
                ]
              }
            ]
          }
        }
      }
    }
  }
}

Update Program.cs:

var configuration = builder.Configuration.GetSection("ReverseProxy");
builder.Services
    .AddReverseProxy()
    .LoadFromConfig(configuration)
    .AddOpenApi(configuration); // <-- this line

From Code

Update Program.cs:

RouteConfig[] GetRoutes()
{
    return new[]
    {
        new RouteConfig
        {
            RouteId = "App1Route",
            ClusterId = "App1Cluster",
            Match = new RouteMatch
            {
                Path = "/proxy-app1/{**catch-all}"
            },
            Transforms = new[]
            {
                new Dictionary<string, string>
                {
                    {"PathPattern", "{**catch-all}"}
                }
            }
        }
    };
}

ClusterConfig[] GetClusters()
{
    return new[]
    {
        new ClusterConfig
        {
            ClusterId = "App1Cluster",
            Destinations = new Dictionary<string, DestinationConfig>
            {
                {
                    "Default", new DestinationConfig
                    {
                        Address = "https://localhost:5101"
                    }
                }
            }
        }
    };
}

ReverseProxyDocumentFilterConfig GetOpenApiConfig()
{
    return new ReverseProxyDocumentFilterConfig
    {
        Routes = GetRoutes().ToDictionary(_ => _.RouteId, _ => _),
        Clusters = new Dictionary<string, ReverseProxyDocumentFilterConfig.Cluster>
        {
            {
                "App1Cluster", new ReverseProxyDocumentFilterConfig.Cluster
                {
                    Destinations = new Dictionary<string, ReverseProxyDocumentFilterConfig.Cluster.Destination>
                    {
                        {
                            "Default", new ReverseProxyDocumentFilterConfig.Cluster.Destination
                            {
                                Address = "https://localhost:5101",
                                OpenApiDocs = new[]
                                {
                                    new ReverseProxyDocumentFilterConfig.Cluster.Destination.OpenApiDoc
                                    {
                                        PrefixPath = "/proxy-app1",
                                        Paths = new[] {"/openapi/v1.json"}
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    };
}

builder.Services
    .AddReverseProxy()
    .LoadFromMemory(GetRoutes(), GetClusters())
    .AddOpenApi(GetOpenApiConfig()); // <-- this line

Common

Update Program.cs:

builder.Services.AddOpenApi(options =>
{
    options.AddDocumentTransformer<ReverseProxyDocumentFilter>();
});
app.MapOpenApi().AllowAnonymous();
app.UseSwaggerUI(options =>
{
    var config = app.Services.GetRequiredService<IOptionsMonitor<ReverseProxyDocumentFilterConfig>>().CurrentValue;
    foreach (var cluster in config.Clusters)
    {
        options.SwaggerEndpoint($"/openapi/{cluster.Key}.json", cluster.Key);
    }
});

Authentication and Authorization

Update appsettings.json:

{
  "ReverseProxy": {
    "Clusters": {
      "App1Cluster": {
        "Destinations": {
          "Default": {
            "Address": "https://localhost:5101",
            "AccessTokenClientName": "Identity", // <-- this line
            "OpenApiDocs": [
              {
                "PrefixPath": "/proxy-app1",
                "Paths": [
                  "/openapi/v1.json"
                ]
              }
            ]
          }
        }
      }
    }
  }
}

Update Program.cs:

builder.Services.AddAccessTokenManagement(options =>
{
    var identityConfig = builder.Configuration.GetSection("Identity").Get<IdentityConfig>()!;
    
    options.Client.Clients.Add("Identity", new ClientCredentialsTokenRequest
    {
        Address = $"{identityConfig.Url}/connect/token",
        ClientId = identityConfig.ClientId,
        ClientSecret = identityConfig.ClientSecret
    });
});

Common Swagger Document

If you want to combine multiple OpenApi documents into one.

Update appsettings.json:

{
  "ReverseProxy": {
    "OpenApiConfig": { // <-- this block
      "IsCommonDocument": true,
      "CommonDocumentName": "YARP"
    },
  }
}
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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
5.0.6 272 1/31/2026
5.0.5 97 1/31/2026
5.0.4 104 1/31/2026
5.0.3 104 1/31/2026
5.0.2 101 1/31/2026
5.0.1 96 1/30/2026
5.0.0 95 1/30/2026

Include Full Debug Symbols