Customize Swagger UI and JSON URLs using Swashbuckle and .NET CORE 3.1

Viewed 1150

NET Core 3.1 Web application with Swashbuckle.AspNetCore for swagger. I want to have a custom name added to both my swagger UI URL and swagger JSON URL. We have a proxy which redirects to different app based on URL, so I want to be able to identify this swagger URL is of my application and forward to it.

I am trying the below code

app.UseSwaggerUI(c =>
{
    c.SwaggerEndpoint("/yasser-swagger/v1/swagger.json", "My API V1");
    c.RoutePrefix = "yasser";
});

The swagger UI is able to load on https://localhost:6001/yasser which redirects to https://localhost:6001/yasser/index.html and shows Swagger UI

BUT, its throwing an error about not able to find the swagger.json file.

enter image description here

Any idea on how to get around this?

1 Answers

Found the configuration to make it work -

app.UseSwagger(c =>
{
    c.RouteTemplate = "abc-swagger/{documentName}/swagger.json";
});

app.UseSwaggerUI(c =>
{
    c.SwaggerEndpoint("/abc-swagger/v1/swagger.json", "My API V1");
    c.RoutePrefix = "abc-swagger";
});
Related