我添加了一组最小的 API,如下所示:
var myapi = app.MapGroup("myapi").WithTags("My API").WithOpenApi();
// and then
myapi .MapGet($"/", GetAllStuff).WithName("GetAllStuff");
myapi .MapGet($"/{id}", GetSomeStuff).WithName("GetSomeStuff");
这为我提供了 Swagger UI,但我目前无法获得这两个 API 的描述,换句话说,无法获得该组的摘要。有任何想法吗?
我没有看到内置的方式(比如WithDescription
对于端点)来提供此数据,但您可以使用以下解决方法文档过滤器 https://github.com/domaindrivendev/Swashbuckle.AspNetCore#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>());
显然标签名称必须匹配。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)