OpenApiDocumentTransformerContext.DescriptionGroups 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取应用程序的 API 说明组。
public System.Collections.Generic.IReadOnlyList<Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescriptionGroup> DescriptionGroups { get; init; }
member this.DescriptionGroups : System.Collections.Generic.IReadOnlyList<Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescriptionGroup> with get, set
Public Property DescriptionGroups As IReadOnlyList(Of ApiDescriptionGroup)
属性值
示例
// Filter to only the API descriptions included in this document
var options = context.ApplicationServices
.GetRequiredService<IOptionsMonitor<OpenApiOptions>>()
.Get(context.DocumentName);
var descriptions = context.DescriptionGroups
.SelectMany(g => g.Items)
.Where(options.ShouldInclude);
foreach (var description in descriptions)
{
Console.WriteLine($"{description.HttpMethod} {description.RelativePath}");
}
注解
每个 ApiDescriptionGroup 项都包含描述 API 终结点的 ApiDescription 项集合。 这些说明提供有关每个终结点的元数据,例如 HTTP 方法、相对路径、支持的请求/响应格式和参数。
此属性包含来自应用程序的所有 API 说明,而不仅仅是当前文档中包含的终结点。 若要确定与本文档中的终结点对应的说明,请使用 ShouldInclude 筛选说明。