語言

OpenApiDocumentTransformerContext.DescriptionGroups 屬性

定義

取得應用程式的 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 端點都包含一組 ApiDescription 描述 API 端點的項目。 這些描述提供每個端點的元資料,如 HTTP 方法、相對路徑、支援的請求/回應格式及參數。

此屬性包含應用程式中所有的 API 描述,而非僅限於目前文件中包含的端點。 要判斷哪些描述對應本文件中的端點,請使用 ShouldInclude 來篩選描述。

適用於