Treyt.Yarp.ReverseProxy.Swagger
2.0.3
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Treyt.Yarp.ReverseProxy.Swagger --version 2.0.3
NuGet\Install-Package Treyt.Yarp.ReverseProxy.Swagger -Version 2.0.3
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="Treyt.Yarp.ReverseProxy.Swagger" Version="2.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Treyt.Yarp.ReverseProxy.Swagger --version 2.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Treyt.Yarp.ReverseProxy.Swagger, 2.0.3"
#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.
// Install Treyt.Yarp.ReverseProxy.Swagger as a Cake Addin #addin nuget:?package=Treyt.Yarp.ReverseProxy.Swagger&version=2.0.3 // Install Treyt.Yarp.ReverseProxy.Swagger as a Cake Tool #tool nuget:?package=Treyt.Yarp.ReverseProxy.Swagger&version=2.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Introduction
It's an easy to use Swagger extension for the YARP project.
Getting Started
Configure Swagger and YARP for your project.
Update appsettings.json:
{
"ReverseProxy": {
"Clusters": {
"App1Cluster": {
"Destinations": {
"Default": {
"Address": "https://localhost:5101",
"Swaggers": [ // <-- this block
{
"PrefixPath": "/proxy-app1",
"Paths": [
"/swagger/v1/swagger.json"
]
}
]
}
}
}
}
}
}
Create (if doesn't exist) or update ConfigureSwaggerOptions.cs:
public void Configure(SwaggerGenOptions options)
{
var filterDescriptors = new List<FilterDescriptor>();
foreach (var reverseProxyDocumentFilterConfig in _reverseProxyDocumentFilterConfigs)
{
foreach (var cluster in reverseProxyDocumentFilterConfig.Clusters)
{
options.SwaggerDoc(cluster.Key, new OpenApiInfo { Title = cluster.Key, Version = cluster.Key });
}
filterDescriptors.Add(new FilterDescriptor
{
Type = typeof(ReverseProxyDocumentFilter),
Arguments = Array.Empty<object>()
});
}
options.DocumentFilterDescriptors = filterDescriptors;
}
Update Program.cs:
builder.Services.AddTransient<IConfigureOptions<SwaggerGenOptions>, ConfigureSwaggerOptions>();
builder.Services.AddSwaggerGen();
var configuration = builder.Configuration.GetSection("ReverseProxy");
builder.Services
.AddReverseProxy()
.LoadFromConfig(configuration)
.AddSwagger(configuration); // <-- this line
app.UseSwaggerUI(options =>
{
var reverseProxyDocumentFilterConfigs = app.Services.GetServices<ReverseProxyDocumentFilterConfig>();
foreach (var cluster in reverseProxyDocumentFilterConfigs.SelectMany(x => x.Clusters))
{
options.SwaggerEndpoint($"/swagger/{cluster.Key}/swagger.json", cluster.Key);
}
});
After run you will get generated Swagger files by clusters:
Authentication and Authorization
Update appsettings.json:
{
"ReverseProxy": {
"Clusters": {
"App1Cluster": {
"Destinations": {
"Default": {
"Address": "https://localhost:5101",
"AccessTokenClientName": "Identity", // <-- this line
"Swaggers": [
{
"PrefixPath": "/proxy-app1",
"Paths": [
"/swagger/v1/swagger.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
});
});
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net5.0
- IdentityModel.AspNetCore (>= 4.3.0)
- Microsoft.OpenApi.Readers (>= 1.6.4)
- Swashbuckle.AspNetCore.SwaggerGen (>= 6.4.0)
- Yarp.ReverseProxy (>= 1.1.2)
-
net6.0
- IdentityModel.AspNetCore (>= 4.3.0)
- Microsoft.OpenApi.Readers (>= 1.6.4)
- Swashbuckle.AspNetCore.SwaggerGen (>= 6.4.0)
- Yarp.ReverseProxy (>= 2.0.1)
-
net7.0
- IdentityModel.AspNetCore (>= 4.3.0)
- Microsoft.OpenApi.Readers (>= 1.6.4)
- Swashbuckle.AspNetCore.SwaggerGen (>= 6.4.0)
- Yarp.ReverseProxy (>= 2.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.