簡體   English   中英

Swagger API沒有刷新文檔

[英]Swagger API not refreshing the documentation

我正在使用Swagger API來記錄我的REST服務。 之前我的控制器方法沒有提供信息性的評論,因此Swagger API沒有顯示描述,但現在甚至在更新評論后,我沒有在突出顯示的區域中獲取方法描述。

    /// <summary>
    /// Gets the consumer scores by retailer id and return id
    /// </summary>
    /// <param name="retailerId"></param>
    /// <param name="returnId"></param>
    /// <returns></returns>

在此輸入圖像描述

我錯過了什么嗎?

為了讓Swashbuckle從您的XML注釋中讀取,您需要為目標項目啟用XML文檔文件。 除此之外,您還需要在啟動配置中將Swashbuckle指向該文件。

來自Swashbuckle文檔

打開項目的“屬性”對話框,單擊“構建”選項卡,確保選中“XML文檔文件”。 這將生成一個包含構建時所有XML注釋的文件。

此時,任何未使用XML注釋注釋的類或方法都將觸發構建警告。 要禁止此操作,請在屬性對話框的“Supress warnings”字段中輸入警告代碼“1591”。*

配置Swashbuckle以將文件中的XML注釋合並到生成的Swagger JSON中:

services.AddSwaggerGen(c =>
{
    c.SwaggerDoc("v1",
        new Info
        {
            Title = "My API - V1",
            Version = "v1"
        }
     );

     var filePath = Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, "MyApi.xml");
     c.IncludeXmlComments(filePath);
}

使用摘要,備注和響應標記注釋您的操作

/// <summary>
/// Retrieves a specific product by unique id
/// </summary>
/// <remarks>Awesomeness!</remarks>
/// <response code="200">Product created</response>
/// <response code="400">Product has missing/invalid values</response>
/// <response code="500">Oops! Can't create your product right now</response>
[HttpGet("{id}")]
[ProducesResponseType(typeof(Product), 200)]
[ProducesResponseType(typeof(IDictionary<string, string>), 400)]
[ProducesResponseType(typeof(void), 500)]
public Product GetById(int id)

重建項目以更新XML注釋文件並導航到Swagger JSON端點。 請注意描述如何映射到相應的Swagger字段。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM