2

I am adding a group of minimal APIs like this:

var myapi = app.MapGroup("myapi").WithTags("My API").WithOpenApi();

// and then
myapi .MapGet($"/", GetAllStuff).WithName("GetAllStuff");
myapi .MapGet($"/{id}", GetSomeStuff).WithName("GetSomeStuff");

This gives me the Swagger UI, but I am currently not able to have a description for both the APIs, in other words, a summary of the Group. Any ideas?

Guru Stron
  • 102,774
  • 10
  • 95
  • 132
user479338
  • 31
  • 3
  • The same question is asked here, but the answer doesn't pertain to minimal APIs, but controller-based APIs: https://stackoverflow.com/questions/75429292/how-to-provide-openapi-tag-group-descriptions-for-a-net-core-7-minimal-api – user479338 Aug 10 '23 at 14:43

1 Answers1

1

I don't see a build-in way (like WithDescription for endpoints) to provide this data but you can workaround with document filters:

public class TagDescriptionsDocumentFilter : IDocumentFilter
{
    public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
    {
        swaggerDoc.Tags = new List<OpenApiTag>
        {
            new OpenApiTag { Name = "My API", Description = "My API does something" }
        };
    }
}

And

builder.Services.AddSwaggerGen(opts => opts.DocumentFilter<TagDescriptionsDocumentFilter>());

Obviously tag names must match.

enter image description here

Guru Stron
  • 102,774
  • 10
  • 95
  • 132