新建webApi的帮助文档

来源:互联网 发布:docker github 源码 编辑:程序博客网 时间:2024/06/07 04:57
1.新建一个WebApi项目
2.用Nuget添加Microsoft ASP.NET Web API Help Page包
3.修改HelpPageConfig文件
  1. public static void Register(HttpConfiguration config)
  2. {
  3. // Uncomment the following to use the documentation from XML documentation file.
  4. config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/PatientView.Service.WebAPI.xml")));
  5. ...
  6. }
4.API方法上写三斜杠的注释
  1. /// <summary>
  2. /// 病区列表
  3. /// </summary>
  4. /// <returns></returns>
  5. [Route("GetLocationUnits")]
  6. public Response<List<LocationUnitModel>> GetLocationUnits()
  7. {
  8. return TryResponse(() => _operatorBll.GetLocationUnits(),
  9. method: "GetLocationUnits");
  10. }
5.打开项目属性,在Build页面里,勾选XML documentation file
App_Data\PatientView.Service.WebAPI.xml
6.用Nuget添加Install the WebApiTestClient package (可以搜索yaohuang)
7.修改文件under Areas\HelpPage\Views\Help 下的Api.cshtml
添加
  • @Html.DisplayForModel("TestClientDialogs")
  • @Html.DisplayForModel("TestClientReferences") 如下
  1. @using System.Web.Http
  2. @using MyApi.Areas.HelpPage.Models
  3. @model HelpPageApiModel
  4. @{
  5. var description = Model.ApiDescription;
  6. ViewBag.Title = description.HttpMethod.Method + " " + description.RelativePath;
  7. }
  8. <div id="body" class="help-page">
  9. <section class="featured">
  10. <div class="content-wrapper">
  11. <p>
  12. @Html.ActionLink("Help Page Home", "Index")
  13. </p>
  14. </div>
  15. </section>
  16. <section class="content-wrapper main-content clear-fix">
  17. @Html.DisplayForModel()
  18. </section>
  19. </div>
  20. @Html.DisplayForModel("TestClientDialogs")
  21. @section Scripts{
  22. @Html.DisplayForModel("TestClientReferences")
  23. <link type="text/css" href="~/Areas/HelpPage/HelpPage.css" rel="stylesheet" />
  24. }
8.添加以下文件修改样式
  • jQuery 1.7.1
  • jQuery.UI.Combined 1.8.20
  • knockoutjs 2.1.0
效果:

 
原创粉丝点击