Swashbuckle Swagger UI不显示参数说明

时间:2017-07-20 14:11:33

标签: asp.net swagger swashbuckle

包版本6.0.0-beta902

示例:

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);
}

为什么Swagger UI不显示名称参数说明?

1 个答案:

答案 0 :(得分:2)

这通常是由于缺少配置引起的,请确保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