Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swashbuckle doesn't display attribute based routing endpoints #1446

Open
xjanarhe-rakbank opened this issue Oct 7, 2024 · 0 comments
Open

Comments

@xjanarhe-rakbank
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant