1

I am using .NET CORE 3.1 web application and have setup swagger (Swashbuckle). I am trying to customize the swagger UI URL to be /abc/swagger and below is the configuration I am trying -

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

But I am getting this error -

enter image description here

and the UI works only on /abc and not on /abc/swagger. I am lost as this does not match with the doc I was trying to follow.

Can someone help me setup a custom route for the swagger UI, TIA.

Tried this https://stackoverflow.com/a/55732702/1182982 but didnt work for me, the URL return 404.

Yasser Shaikh
  • 46,934
  • 46
  • 204
  • 281

1 Answers1

0

In Startup.Configure you need define two endpoints, OpenAPI definition and swagger ui. Swagger UI use the OpenAPI to prepare the IHM.

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    ...
    // Define the OpenAPI definition endpoint
    app.UseSwagger(c => 
    {
        c.RouteTemplate = "/abc/swagger.json";
    });
    // Define the IHM endpoint
    app.UseSwaggerUI(c =>
    {
        c.SwaggerEndpoint("swagger.json", "My API V1");
        c.RoutePrefix = "abc";
    });
}

You have correctly configured the UI endpoint, but I think you miss the part to configure the OpenAPI definition endpoint. You check by open navigator's page with the url localhost:5001/abc/swagger.json.

vernou
  • 6,818
  • 5
  • 30
  • 58