Search code examples
asp.netswaggeropenapi

ASP.Net Open Api specify endpoint section


I generate an endpoints via minimal api and also try to generate a documentation with Microsoft.AspNetCore.OpenApi package, but I don't know how to set a section and all my endpoints appears in single section in Swagger.

By sections I mean something like that (on screenshot there are sections visible in Swagger when an endpoints are generated with controller, each section name is a controller name) enter image description here

How can I specify a section for an endpoint?


Solution

  • Thanks for this question I found out the way to do it.

    routeHandlerBuilder.WithOpenApi(x =>
    {
        var tag = new OpenApiTag()
        {
            Name = "<your section name>"
        };
        x.Tags = [tag]; // in C# < 12 new List<OpenApiTag>() { tag }
    }