WebApi 空项目生成帮助文档

1、创建一个WebApi的空项目

2、写一些接口,在接口文档中忽略某个方法可以使用  [ApiExplorerSettings(IgnoreApi = true)] 特性

3、在Nuget中添加 Microsoft ASP.NET Web API 2.2 Help Page (这是微软官方的),此时会生成一个Areas

4、将项目生成  XML文档文件  选中,生成地址 App_DataXmlDocument.xml

5、将 AreasHelpPageApp_StartHelpPageConfig.cs 下的下图部分取消注释

6、在Global.asax 中的 Application_Start() 中添加 AreaRegistration.RegisterAllAreas(); 对域进行注册

        protected void Application_Start()
        {
            log4net.Config.XmlConfigurator.Configure(new FileInfo(Server.MapPath("~/Web.config")));
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
        }

7、在 WebApiConfig.cs 中修改默认路由

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

 8、返回对象自定义

在接口顶部加上

[ResponseType(typeof(GameResponseModel))]

  

原文地址:https://www.cnblogs.com/ideacore/p/6893171.html