博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WebApiTestClient自定义返回值说明
阅读量:4589 次
发布时间:2019-06-09

本文共 2554 字,大约阅读时间需要 8 分钟。

  WebApiTestClient是基于微软HelpPage一个客户端调试扩展工具,用来做接口调试比较方便。但是对返回值的自定义说明还是有缺陷的。有园友,说可以通过对类进行注释,然后通过在IHttpActionResult上标记ResponseType(typeof(class))即可。

[ResponseType(typeof(CreditRuleDetails))]        public IHttpActionResult GetCreditRuleList(int ruleType = 1)        {            try            {                     }            catch (Exception exception)            {            }        }
CreditRuleDetails类
public class CreditRuleDetails{ ///  /// 规则Id/// public int RuleId{get;set;} ///  /// 规则名称/// public int RuleName{get;set;}}

  但发现返回值的Description中没有summary描述。

弄了半天,也没发现是什么问题,后来转变了下思路。改用C#特性来做,然后更改了下ModelDescriptionGenerator.cs的方法实现。

private ModelDescription GenerateComplexTypeModelDescription(Type modelType)        {            ComplexTypeModelDescription complexModelDescription = new ComplexTypeModelDescription            {                Name = ModelNameHelper.GetModelName(modelType),                ModelType = modelType,                Documentation = CreateDefaultDocumentation(modelType)            };            GeneratedModels.Add(complexModelDescription.Name, complexModelDescription);            bool hasDataContractAttribute = modelType.GetCustomAttribute
() != null; PropertyInfo[] properties = modelType.GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (PropertyInfo property in properties) { if (ShouldDisplayMember(property, hasDataContractAttribute)) { ParameterDescription propertyModel = new ParameterDescription { Name = GetMemberName(property, hasDataContractAttribute) }; if (DocumentationProvider != null) { //======以下是添加的========= DescriptionAttribute myattribute = (DescriptionAttribute)Attribute.GetCustomAttribute(property, typeof(DescriptionAttribute)); if (myattribute != null) { propertyModel.Documentation = myattribute.Description; } //========以上是添加的=========== else { propertyModel.Documentation = DocumentationProvider.GetDocumentation(property); } }

然后将类的属性标记为Description。

[Description("规则名称")]        public string RuleName { get; set; }

最后结果:

  希望能对大家有帮助!

转载于:https://www.cnblogs.com/Jaryleely/p/webapitest.html

你可能感兴趣的文章
python——父类与子类的一些说明
查看>>
2019年3月3日 2018-2019-2 20189205《移动平台应用开发实践》第二周作业
查看>>
MySQL 性能优化--优化数据库结构之优化数据类型
查看>>
软件工程之软件需求分析
查看>>
Electron简介和安装使用
查看>>
Improving Visual C++ Debugging with Better Data Display
查看>>
JDBC
查看>>
workspace 配置
查看>>
C# 针对特定的条件进行锁操作,不用lock,而是mutex
查看>>
Spring归纳
查看>>
MyEclipse Web Project导入Eclipse Dynamic Web Project,无法部署到tomcat问 题
查看>>
24小时学通Linux内核之向内核添加代码
查看>>
python 函数
查看>>
Solr4.0 如何配置使用UUID自动生成id值
查看>>
Marketing™Series用户手册(Marketing™Series Manual)
查看>>
Java动态代理
查看>>
二维码开源库zbar、zxing使用心得
查看>>
框架设计读书笔记--扩展点设计--组合法
查看>>
Web开发小贴士 -- 全面了解Cookie
查看>>
收藏Javascript中常用的55个经典技巧
查看>>