.net core api 集成swagger 文档不显示action中文注释、分层开发形参实体不显示实体属性注释、返回值不显示实体注释问题

在类库或者api项目上右键--属性--生成--输出--XML文档文件上打√,

然后在Startup.cs中ConfigureServices添加如下配置即可:

 services.AddSwaggerGen(config =>
            {

                //var provider = services.BuildServiceProvider().GetRequiredService<IApiVersionDescriptionProvider>();
                config.SwaggerDoc("v1", new OpenApiInfo { Title = "CL.MEStoWMS.WebApi", Version = "v1" });

                // 为 Swagger JSON and UI设置xml文档注释路径
                var basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location);//获取应用程序所在目录(绝对,不受工作目录影响,建议采用此方法获取路径)
                var xmlPath = Path.Combine(basePath, "MEStoWMS.WebApi.xml");//接口action显示注释
                var xmlPath_entity = Path.Combine(basePath, "实体类库.xml");//分层实体显示注释
                config.IncludeXmlComments(xmlPath);
                config.IncludeXmlComments(xmlPath_entity);
            });

  

原文地址:https://www.cnblogs.com/huangshuqiang/p/14304683.html