aqudgv 2019-07-01
本文包括两个部分:
private static string GetXmlCommentsPath() { return System.String.Format(@"{0}\bin\WebApiDemo.xml", System.AppDomain.CurrentDomain.BaseDirectory); }
把valuescontroller做一些修改
/// <summary> /// ValuesController的注释 /// </summary> public class ValuesController : ApiController { /// <summary> /// 获取列表 /// </summary> /// <returns></returns> [HttpGet] public IEnumerable<string> GetList(int pageIndex, int pageSize, string search = "") { return new string[] { "value1", "value2" }; } /// <summary> /// 设置键值对 /// </summary> /// <param name="value"></param> [HttpPost] public string PostData([FromBody]string key, [FromBody]string value = "value") { return "{\"" + key + "\":\"" + value + "\"}"; } }
重新运行,能看到文档变成了如下,必填的参数显示required,非必填的参数可以不用填,post请求的参数也显示在文档里