Advertisements
I have this configuration for dotnet swagger gen:
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Title = "Demo",
Version = "v1",
Description = "This is a demo api"
});
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);
});
Is there any way to config so that when user goes to localhost:port/ lands directly to swagger docs?
>Solution :
Yes, you need to change config for the swagger UI:
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
options.RoutePrefix = "";
});