Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Core API: Disable multiple route expanding in SwaggerUI

I'm using Swashbuckle.AspNetCore (4.0.1) to generate a simple SwaggerUI for testing like it's described here. My ApiController have two routes:

[Route("api/values")]
[Route("api/{systemId}/values")]

The SwaggerUI displays all controller endpoints two times (one with systemId, one without systemId). This is good, but the problem is, when I click on e.g /api/values/example SwaggerUI expands api/{systemId}/values/example too. Both endpoints are going to the same public C# method inside the controller, it makes sense why SwaggerUI opens both. But it's annoying and confusing.

Is it possible to stop this behavior?

like image 720
Joba Avatar asked Mar 07 '19 07:03

Joba


1 Answers

Add the Name property to the Route.

[Route("api/values", Name = "values1")]
[Route("api/{systemId}/values", Name = "values2")]

This will create different ids in the div containing the endpoint specifications so it will expand only the one you need.

like image 180
ALFA Avatar answered Oct 23 '22 12:10

ALFA