WebApi(五)-Swagger接口文档①简单集成

1,通过NuGet引用Swashbuckle

2,打开项目属性-->生成,勾选XML文档文件,保存

3,找到项目App_Start文件夹下WebApiConfig查找GetXmlCommentsPath然后去掉注释再加一个model的xml展示如图

 

 

 

4,创建方法GetXmlCommentsPath

private static string GetModelXmlCommentsPath()
        {
            return string.Format("{0}/bin/WSR.Models.xml", System.AppDomain.CurrentDomain.BaseDirectory);
        }

        private static string GetXmlCommentsPath()
        {
            return string.Format("{0}/bin/WSR.WebApi.xml", System.AppDomain.CurrentDomain.BaseDirectory) ;
        }

 

5,大功告成,运行项目访问路径http://localhost:61914/swagger/ui/index(61714是项目运行默认的端口号根据自己的项目不是固定)

 

posted @ 2019-01-14 10:21  wuyubing  阅读(330)  评论(0编辑  收藏  举报