2017-07-20 39 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