Skip to content

Swashbuckle doesn't display attribute based routing endpoints #1446

@xjanarhe-rakbank

Description

@xjanarhe-rakbank

VERSION:

Swashbuckle.AspNetCore and Swashbuckle.AspNetCore.Newtonsoft of version 6.8.1

STEPS TO REPRODUCE:

I have created a controller and the web api method as below,

[ApiController]
public class CustomApiController : Microsoft.AspNetCore.Mvc.Controller
{
[HttpPost]
[Route("api/custom/search")]
public JsonResult CustomSearch(CustomSearchRequest request)
{
....
....
return JsonResult(object)
}
}

In Startup.cs

ConfigureServices Method:

services.AddEndpointsApiExplorer();
services.AddSwaggerGen(options =>
{
options.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
});

In Configure method:

app.UseSwagger();
app.UseSwaggerUI();

app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(name: "Default", pattern: "{controller}/{action}/{id?}"); // Default controllers
endpoints.MapControllers(); // Attribute Routing
endpoints.MapControllerRoute(
name: "CustomSearch",
pattern: "api/custom/search",
defaults: new { controller = "CustomApi", action = "CustomSearch" }
);
}

EXPECTED RESULT:

The API endpoint is not shown in swagger UI

ACTUAL RESULT:

It shows all other APIs from the library. The custom API needs to be listed in the Swagger UI.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions