关于ASP.NET Web Api的HelpPage文档注释问题
关于ASP.NET Web Api的HelpPage文档注释问题
以前我用微软的HelpPage来自动生成的webAPI帮助文档。在使用了一段时间后发现只能显示Controller上面写的注释文档内容。以前总以为是微软这个类库的bug。后来才明白了是由于我的设置不当。



我们可以很清楚的看到,返回的`AlarmRecodrdDto`并没有注释文档啊!可是我已经在类库的中写过了该代码的注释的。为毛就没有呢???
其实啊,我们的注释文档是自动生成xml文件,再由HelpPage来读取该xml中的注释信息,最后展示在页面上。那些没有注释的文档是由于我们的代码注释没有生成对应的注释xml文件,所以就没法读取啦!!!
明白问题出在哪里了就可以动手解决问题了!!!
1. 设置指定类库中要生成的注释xml路径



2. 添加一个可以读取xml文件信息的类
using System;
using System.Linq;
using System.Reflection;
using System.Web.Http.Controllers;
using System.Web.Http.Description;
using GTCASP.Website.Areas.HelpPage.ModelDescriptions;
namespace GTCASP.Website.Areas.HelpPage.Models
{
/// <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));
}
}
}
请将类添加到如下位置

3. 修改HelpPageConfig.cs
中的代码。

做完以上设置后,大功告成。妹子,现在我们可以出去玩啦!!!
咦,妹子人呢?
关于ASP.NET Web Api的HelpPage文档注释问题的更多相关文章
- 关于Web Api的HelpPage文档注释问题
之前使用Microsoft.AspNet.WebApi.HelpPage的时候,一直为返回对象的注释发愁,以为这是个BUG. 这个注释的解决办法其实要从其原理理解就明白了. 因为HelpPage是读取 ...
- ASP.NET Core 中文文档 第二章 指南 (09) 使用 Swagger 生成 ASP.NET Web API 在线帮助测试文档
原文:ASP.NET Web API Help Pages using Swagger 作者:Shayne Boyer 翻译:谢炀(kiler) 翻译:许登洋(Seay) 对于开发人员来说,构建一个消 ...
- asp.net core web api 生成 swagger 文档
asp.net core web api 生成 swagger 文档 Intro 在前后端分离的开发模式下,文档就显得比较重要,哪个接口要传哪些参数,如果一两个接口还好,口头上直接沟通好就可以了,如果 ...
- Effective Java 第三版——56. 为所有已公开的API元素编写文档注释
Tips 书中的源代码地址:https://github.com/jbloch/effective-java-3e-source-code 注意,书中的有些代码里方法是基于Java 9 API中的,所 ...
- 第四十四条:为所有导出的API元素编写文档注释
简而言之,要为API编写文档,文档注释是最好,最有效的途径.对于所有可导出的API元素来说,使用文档注释应该被看作是强制性的.要 采用一致的风格来遵循标准的约定.记住,在文档注释内部出现任何的HTML ...
- 1.1 WEB API 在帮助文档页面进行测试
这篇文章http://www.cnblogs.com/landeanfen/p/5210356.html写得比较详细, 我就挑简单的来说. 首先用这功能要在WEB API创建的帮助文档下面,如果你使用 ...
- 使用swagger实现web api在线接口文档
一.前言 通常我们的项目会包含许多对外的接口,这些接口都需要文档化,标准的接口描述文档需要描述接口的地址.参数.返回值.备注等等:像我们以前的做法是写在word/excel,通常是按模块划分,例如一个 ...
- 使用swagger实现web api在线接口文档(转载)
一.前言 通常我们的项目会包含许多对外的接口,这些接口都需要文档化,标准的接口描述文档需要描述接口的地址.参数.返回值.备注等等:像我们以前的做法是写在word/excel,通常是按模块划分,例如一个 ...
- 为ASP.NET WEB API生成人性化说明文档
一.为什么要生成说明文档 我们大家都知道,自己写的API要供他人调用,就需要用文字的方式将调用方法和注意事项等写成一个文档以更好的展示我们设计时的想法和思路,便于调用者更加高效的使用我们的API. 当 ...
随机推荐
- PHP生成带有干扰线的验证码,干扰点、字符倾斜
PHP生成验证码的类代码,本验证码类支持生成干扰点.干扰线等干扰像素,还可以使字符倾斜.在类中你可以定义验证码宽度.高度.长度.倾斜角度等参数,后附有用法: <?php class class_ ...
- js架构设计模式——理解javascript中的MVVM开发模式
理解javascript中的MVVM开发模式 http://blog.csdn.net/slalx/article/details/7856769 MVVM的全称是Model View ViewMod ...
- Java的IO操作中有面向字节(Byte)和面向字符(Character)两种方式
解析:Java的IO操作中有面向字节(Byte)和面向字符(Character)两种方式.面向字节的操作为以8位为单位对二进制的数据进行操作,对数据不进行转换,这些类都是InputStream和Out ...
- 配置FMS发布/HDS/HLS流
一.前言 安装完FMS4.5以后就有了apache2.2,由于在FMS安装目录里面,他是对外面已经安装的是没有影响的,默认情况向, FMS监听80端口接收traffic然后传递给Apache的8134 ...
- Bootstrap入门(二十八)JS插件5:工具提醒
Bootstrap入门(二十八)JS插件5:工具提醒 工具提示在使用过程中比较常见,但是实现起来有些麻烦,而bootstrap则很好地解决了这个问题. 我们来写一个简单的实例 先引入CSS文件和JS文 ...
- yii2 中布局文件的 设置方法
网页主题应用的属性: [yii\base\Application::layout|layout 该属性指定渲染 视图 默认使用的布局名字,默认值为 'main' 对应布局路径下的 main.php 文 ...
- Hadoop权威指南:压缩
Hadoop权威指南:压缩 [TOC] 文件压缩的两个好处: 减少储存文件所需要的磁盘空间 加速数据在网络和磁盘上的传输 压缩格式总结: 压缩格式 工具 算法 文件扩展名 是否可切分 DEFLATE ...
- 使用fullPage.js遇到的问题以及翻译
使用fullPage.js做一简单页面,遇一古怪问题:.section中的h1标签始终被一插件生成的标签包裹,导致样式调整好不困难!花费数小时排查为何会生成这样一个标签,最终在fullPage.js的 ...
- ECJTUACM16 Winter vacation training #4 题解&源码
A......................................................................................... 题目链接→Code ...
- 睡不着,复习一下C++基础中的基础(深拷贝与浅拷贝)
#include <iostream> #include <string> #include <assert.h> using namespace std; //声 ...