Search code examples
asp.net-coreswagger-uiopenapiminimal-apis

How to provide OpenAPI 'tag' group descriptions for a .NET Core 7 minimal API?


I've grouped my API endpoints into two tag/groups: "MCP Provider" and "Nexgen Provider". How can I apply a description to the tags themselves?


Solution

  • First make sure you have already installed the package: Swashbuckle.AspNetCore.Annotations, then adding the following codes in your .csproj file:

    <PropertyGroup>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>   
    </PropertyGroup>
    

    Now adding the codes in program.cs:

    builder.Services.AddSwaggerGen(c =>{
    var xmlFile = ${Assembly.GetExecutingAssembly().GetName().Name}.xml";
    var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
    c.IncludeXmlComments(xmlPath, includeControllerXmlComments: true);
    c.EnableAnnotations();});
    

    Last, adding the description which you want to use in front of the controller via the codes:

    [SwaggerTag("This is a test")]
    

    Here is my test result:
    enter image description here

    You can get more infromation from here.