I'm using Swashbuckle to enable the use of swagger and swagger-ui in my WebApi project.
In the following image you can see two of my controllers shown in the swagger-ui page. These are named as they are in the C# code, however I was wondering if there was a way to change what is shown here?
This is mainly because as you can see ManagementDashboardWidget
is not a user friendly name, so I want to change it to be user friendly.
You can use tags for that. By default Swashbuckle adds a tag with the name of the controller to every operation. You can override that with the SwaggerOperationAttribute
. For instance, the next line replaces the default tag, Values, with the tag Test:
public class ValuesController : ApiController
{
[SwaggerOperation(Tags = new[] { "Test" })]
public IHttpActionResult Get()
{
// ...
}
}
The Get
operation will now be put in the group Test
.
If you want the operation to appear in multiple groups you can add more tags. For instance:
[SwaggerOperation(Tags = new[] { "Test", "Release1" })]
will put the Get
operation in the groups Test
and Release1
.
That's exactly what I wanted... I just never found much documentation on that part. Thanks very much.
This works, but it still leaves the controller name as a tag in the UI, but with no actions under it. For example, say I have
ABCController
but I've added[SwaggerOperation(Tags = new[] { "DEF" })]
to all routes, the UI shows "ABC" and "DEF", but there is nothing under "ABC". How do we get rid of "ABC" altogether?Take a look to my answer below. I hope it helps you!