Swashbuckle Swagger UI不显示参数说明

问题描述 投票:2回答:1

包版本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不显示Name参数描述?

asp.net swagger swashbuckle
1个回答
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

© www.soinside.com 2019 - 2024. All rights reserved.