'how to add tag on webapi for swagger ui

i am learning asp.net webapi. now i add swagger to my asp.net project.

enter image description here

I noticed that there is a tag filter. but how to add tag to my API action?



Solution 1:[1]

When you Generate new Controller for Example EmployeeController

and Your routes like this (Example):

Get => /api/Employee/

post => /api/Employee/

put => /api/Employee/{id}

Delete => /api/Employee/{id}

your Tag is Employee

enter image description here

You can see in this Link

or you can Add Your Custom Document Filter as below:

public class OrderTagsDocumentFilter: IDocumentFilter {
    public void Apply(OpenApiDocument swaggerDoc, 
               DocumentFilterContext context) {
    swaggerDoc.Tags = swaggerDoc.Tags.OrderBy(x => 
                x.Name).ToList();
    }
}

And add it to your StartUp Class Like Below:

services.AddSwaggerGen(c => {
  c.SwaggerDoc("v1", new OpenApiInfo {
    Title = "Shoppy.WebApi", Version = "v1"
  });
    c.EnableAnnotations();

    c.DocumentFilter<OrderTagsDocumentFilter>();
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1