2017-07-20 40 views
0

包版本6.0.0-beta902Swashbuckle揚鞭UI不顯示參數描述

例子:

public class TestModel 
{ 
    /// <summary> 
    /// This is description of Name 
    /// </summary> 
    public string Name { get; set; } 
} 

public IActionResult HelloWorld(TestModel model) 
{ 
    return Content("hello " + model.Name); 
} 

爲什麼揚鞭UI不顯示名稱參數說明?

回答

0

這通常是由缺少配置造成的,請確保IncludeXmlComments包含正確的XML文檔路徑。

這裏是一個辦法,包括對配置中的所有XML文檔:

public void ConfigureServices(IServiceCollection services) 
    { 
     // Add Swashbuckle 
     services.AddSwaggerGen(options => 
     { 
      options.DescribeAllEnumsAsStrings(); 
      options.SingleApiVersion(new Swashbuckle.Swagger.Model.Info() 
      { 
       Title = "My API", 
       Version = "v1", 
       Description = "My API", 
       TermsOfService = "Terms Of Service" 
      }); 

      //Set the comments path for the swagger json and ui. 
      var basePath = PlatformServices.Default.Application.ApplicationBasePath; 
      foreach (var name in Directory.GetFiles(basePath, "*.XML", SearchOption.AllDirectories)) 
      { 
       options.IncludeXmlComments(name); 
      } 
     }); 
     // Add framework services. 
     services.AddMvc(); 
    } 



下面是一個例子顯示正確:

http://swashbuckletest.azurewebsites.net/swagger/ui/index?filter=TestEnum#/TestEnum/TestEnum_Put

而且背後的代碼是關於GitHub:

https://github.com/heldersepu/SwashbuckleTest/blob/master/Swagger_Test/Models/ViewModelTest.cs

+0

我確認,我所有的xml文件都包含在內。 Swagger顯示我的模型屬性的評論。但參數說明中沒有任何內容。 –

+0

您可以將您的項目添加到GitHub並在此處發佈鏈接? – HelderSepu

+0

我剛剛嘗試過這個完全相同的版本,它適用於我: https://github.com/heldersepu/csharp-proj/commit/d5043caadf787d409dfa7b00165454c5e3823f3b – HelderSepu