在使用webapi框架进行接口开发的时候,编写文档会需要与接口同步更新,如果采用手动式的更新的话效率会非常低。webapi框架下提供了一种自动生成文档的help Page页的功能。

但是原始版本的效果不是很好,最重要的一点是没有对数据模型的详细注解提供展示。这种请情况下需要我们自己对其进行拓展,方便显示出接口和数据模型注解,在将接口提供给其他人使用时提高可读性。

下面先上两份效果图 

在这里讲一下最重要的两个步骤

1:重写拓展一个XmlDocumentationProvider类 

    /// <summary>A custom
/// <see cref="IDocumentationProvider"/>
/// that reads the API documentation from a collection of XML documentation files.
/// </summary>
public class MultiXmlDocumentationProvider : IDocumentationProvider, IModelDocumentationProvider
{
/*********
** Properties
*********/
/// <summary>The internal documentation providers for specific files.</summary>
private readonly XmlDocumentationProvider[] Providers; /*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
/// <param name="paths">The physical paths to the XML documents.</param>
public MultiXmlDocumentationProvider(params string[] paths)
{
this.Providers = paths.Select(p => new XmlDocumentationProvider(p)).ToArray();
} /// <summary>Gets the documentation for a subject.</summary>
/// <param name="subject">The subject to document.</param>
public string GetDocumentation(MemberInfo subject)
{
return this.GetFirstMatch(p => p.GetDocumentation(subject));
} /// <summary>Gets the documentation for a subject.</summary>
/// <param name="subject">The subject to document.</param>
public string GetDocumentation(Type subject)
{
return this.GetFirstMatch(p => p.GetDocumentation(subject));
} /// <summary>Gets the documentation for a subject.</summary>
/// <param name="subject">The subject to document.</param>
public string GetDocumentation(HttpControllerDescriptor subject)
{
return this.GetFirstMatch(p => p.GetDocumentation(subject));
} /// <summary>Gets the documentation for a subject.</summary>
/// <param name="subject">The subject to document.</param>
public string GetDocumentation(HttpActionDescriptor subject)
{
return this.GetFirstMatch(p => p.GetDocumentation(subject));
} /// <summary>Gets the documentation for a subject.</summary>
/// <param name="subject">The subject to document.</param>
public string GetDocumentation(HttpParameterDescriptor subject)
{
return this.GetFirstMatch(p => p.GetDocumentation(subject));
} /// <summary>Gets the documentation for a subject.</summary>
/// <param name="subject">The subject to document.</param>
public string GetResponseDocumentation(HttpActionDescriptor subject)
{
return this.GetFirstMatch(p => p.GetDocumentation(subject));
} /*********
** Private methods
*********/
/// <summary>Get the first valid result from the collection of XML documentation providers.</summary>
/// <param name="expr">The method to invoke.</param>
private string GetFirstMatch(Func<XmlDocumentationProvider, string> expr)
{
return this.Providers
.Select(expr)
.FirstOrDefault(p => !String.IsNullOrWhiteSpace(p));
}
}

2改写 HelpPageConfig 文件  

然后指定下xml的生成目录  打开项目属性设置 即可 然后运行 就是一个可以显示注释的良好页面了

Asp.net Web Api开发Help Page 添加对数据模型生成注释的配置和扩展的更多相关文章

  1. Asp.net Web Api开发Help Page配置和扩展

    为了方面APP开发人员,服务端的接口都应当提供详尽的API说明.但每次有修改,既要维护代码,又要维护文档,一旦开发进度紧张,很容易导致代码与文档不一致. Web API有一个Help Page插件,可 ...

  2. Asp.Net Web API开发微信后台

    如果说用Asp.Net开发微信后台是非主流,那么Asp.Net Web API的微信后台绝对是不走寻常路. 需要说明的是,本人认为Asp.Net Web API在开发很多不同的请求方法的Restful ...

  3. 水果项目第3集-asp.net web api开发入门

    app后台开发,可以用asp.net webservice技术. 也有一种重量级一点的叫WCF,也可以用来做app后台开发. 现在可以用asp.net web api来开发app后台. Asp.net ...

  4. 创建 ASP.NET Web API的Help Page

    转:创建WEBAPI项目 转:添加测试API中的ASP.NET Web API帮助页面

  5. [目录]ASP.NET web api开发实战

    第一章:Restful web service v.s. RPC style web service 第二章:ASP.NET web api v.s. WCF v.s. ASP.NET web ser ...

  6. Asp.net Web Api开发(第四篇)Help Page配置和扩展

    https://blog.csdn.net/sqqyq/article/details/52708613

  7. asp.net web api 开发时应当注意的事项

    Self referencing when returning chain of objects. This can be solved using a design pattern called t ...

  8. 入门 ASP.NET Web API 2 (C#)

    入门 ASP.NET Web API 2 (C#) HTTP 不只是为了生成 web 页面.它也是一个强大的建设公开服务和数据 Api的平台. HTTP 的特性:简单. 灵活和无处不在.你能想到的几乎 ...

  9. ASP.net Web API综合示例

    目录 概述 功能介绍 程序结构 服务器端介绍 客户端介绍 “契约” Web API设计规则 并行写入冲突与时间戳 身份验证详解 Web API验证规则 客户端MVVM简介 Web.Config 本DE ...

随机推荐

  1. Hibernate映射Map属性2

    Hibernate在映射Map属性时生成映射文件.需要注意的一些地方.下面是我的一个例子. Java类如下 public class NameAndNumber { private Integer i ...

  2. 阿里云maven仓库镜像mirror,速度超快

    <mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http:/ ...

  3. 浅析webpack打包输出内容

    当我们执行npm run bundle的时候输出了很多信息,那么这些信息都是什么意思呢 Hash: 221e7fd2e8bf82149df7 Version: webpack 4.30.0 Time: ...

  4. centos7修改主机名和ip映射

    1.修改主机名:命令:/etc/hostname文件输入:HOSTNAME=node3想永久修改,应该修改配置文件 /etc/sysconfig/network. 输入:NETWORKING=yes ...

  5. IBAction作用相当于void,NSLog(@"被调用的方法名是%s",__func__);

    IBAction作用相当于void,NSLog(@"被调用的方法名是%s",__func__);

  6. 对于dequeueReusableCellWithIdentifier:的理解

      Table Data Source Methods中的一个必要实现的方法tableView: cellForRowAtIndexPath: 中经常会包含一段代码: static NSString  ...

  7. Xcode-push到远程仓库不能使用邮箱名,需使用昵称

    1.Xcode-push到远程仓库不能使用邮箱 2.Xcode-push到远程仓库需使用昵称

  8. Jquery中on绑定事件 点击一次 执行多次 的解决办法

    举个例子,在同一个页面有下拉选择框 <select class="mySelect"> <option value="user">按用户 ...

  9. ORCLE10安装常见配置问题-oui.exe停止工作

    其实这是一个在安装过程中很常见的问题,之前小编说过关于甲骨文的软件用起来都很强大,但是大腕出厂,出场费是很高的,就像甲骨文的软件使用的话对于他的安装和配置的换将也是很挑剔的,出现这个问题就是因为安装文 ...

  10. iOS 类似美团或饿了么评价中的星星评分控件

    1.做的好几个项目都用到了评分控件,可以用来展示评分,也可以用来写评分,图片和间距大小都可以定制,之前就已经简单封装了一个,现在把它分享出来,有需要的拿去用. 2.下面是展示截图:   image.p ...