帮助页面中的C#WebAPI多响应类型-s
考虑以下exmaple:帮助页面中的C#WebAPI多响应类型-s,c#,asp.net-web-api2,C#,Asp.net Web Api2,考虑以下exmaple: [ActionName("SomeTestAction")] [ResponseType(typeof(SomeObject))] public IHttpActionResult SomeTestAction(string id) { SomeObject o = SomeMethod(id); if (o == null) { var message = string.Format("Nothing found for id = {0}
[ActionName("SomeTestAction")]
[ResponseType(typeof(SomeObject))]
public IHttpActionResult SomeTestAction(string id)
{
SomeObject o = SomeMethod(id);
if (o == null)
{
var message = string.Format("Nothing found for id = {0}", id);
HttpError err = new HttpError(message);
return Content(HttpStatusCode.NotFound, err);
}
else
{
return Content(HttpStatusCode.OK, o);
}
}
例如,基于数据库查询的结果,此方法可以有两个不同的ResponseType-s。有没有办法在WebAPI的帮助页中指定此行为,以便用户知道错误响应是什么样子的 根据我的经验,我认为这是不可能的,因为生成的文档是静态的
您必须选择是要返回匿名对象(在运行时解析多个类型)还是要显式返回类型,并支持文档详细信息