I need to serve multiple swagger UIs on single C# ASP.NET Core application. This is needed because application API consists of internal "private" API for UI and other stuff and "public" API that can be accessed by other applications and users.
Each Swagger endpoint should be on it's own swagger UI page and have a different URL address. I am able to divide existing API specification to two different json files and the json files in different routes using this code on Startup.cs
Configure
method:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
...
app.UseSwagger()
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("v0.1_public/swagger.json", "Public API v0.1");
c.SwaggerEndpoint("v0.1_private/swagger.json", "Private API v0.1");
});
...
}
I divide the specifications by filtering and adding two Swagger generators in Startup.cs
:
public void ConfigureServices(IServiceCollection services)
{
...
services.AddSwaggerGen(c =>
{
c.DocumentFilter<PublicAPISwaggerFilter>();
c.SwaggerDoc("v0.1_public", new OpenApiInfo
{
Title = "Public API",
Version = "v0.1"
});
});
services.AddSwaggerGen(c =>
{
c.DocumentFilter<PrivateApiSwaggerFilter>();
c.SwaggerDoc("v0.1_private", new OpenApiInfo
{
Title = "Private API",
Version = "v0.1"
});
});
...
}
Swagger UI is then served on https://localhost:port/swagger
and both endpoints are listed on dropdown menu.
How can I create two swagger UIs when other is on route https://locahost:port/private/swagger
and other one is https://locahost:port/public/swagger
and each one them is displaying only one of the endpoints described above?