Asp.net web api ASP Web API帮助页-指向其他页的链接
我正在使用WebAPI帮助页面,我希望能够包含指向其他方法的链接。我从中看到,不支持使用 有没有比写我自己的更好的方法将这些标签输出到帮助中?它对未来的任何变化似乎都很脆弱Asp.net web api ASP Web API帮助页-指向其他页的链接,asp.net-web-api,asp.net-web-api-helppages,Asp.net Web Api,Asp.net Web Api Helppages,我正在使用WebAPI帮助页面,我希望能够包含指向其他方法的链接。我从中看到,不支持使用 有没有比写我自己的更好的方法将这些标签输出到帮助中?它对未来的任何变化似乎都很脆弱 我能想到的唯一替代方法是强制API explorer运行两次—一次缓存所有不同的路由及其相应的帮助页面URL,第二次实际生成文档。但是我不知道该把它挂在哪里(或者如果可能的话)我已经写了一些正确转换链接的东西 大纲是: 在帮助控制器的构造函数中,在cref中找到的字符串(例如:M:Api.Method.Description
我能想到的唯一替代方法是强制API explorer运行两次—一次缓存所有不同的路由及其相应的帮助页面URL,第二次实际生成文档。但是我不知道该把它挂在哪里(或者如果可能的话)我已经写了一些正确转换链接的东西 大纲是: 在帮助控制器的构造函数中,在cref中找到的字符串(例如:M:Api.Method.Description(System.String))和关联的ApiDescription之间创建一个新的惰性IDictionary映射
_methodReferences = new Lazy<IDictionary<string, ApiDescription>>(() => {
var dictionary = new Dictionary<string, ApiDescription>();
var apiExplorer = new ApiExplorer(config);
foreach (var apiDescription in apiExplorer.ApiDescriptions)
{
var descriptor = apiDescription.ActionDescriptor as ReflectedHttpActionDescriptor;
if (descriptor != null)
{
var methodName = string.Format(
@"M:{0}.{1}({2})",
descriptor.MethodInfo.DeclaringType.FullName,
descriptor.MethodInfo.Name,
string.Join(@",",descriptor.GetParameters().Select(x => x.ParameterType.FullName))
);
dictionary[methodName] = apiDescription;
}
}
return dictionary;
});
您会发现,要做到这一点,您需要使各种模型描述从HelpPageModelBase继承,并将父API模型传递给它们(或者更容易传递给懒惰的API模型),但最终它确实起作用
我对这个解决方案不是特别满意;您可能会发现使用某种形式的静态ParseDoc方法更容易,该方法使用默认的Http配置来生成延迟(但由于我所做的其他扩展不适用于我的情况)。如果你看到更好的方法,请分享!希望它能给你一个起点。我已经写了一些正确转换链接的东西 大纲是: 在帮助控制器的构造函数中,在cref中找到的字符串(例如:M:Api.Method.Description(System.String))和关联的ApiDescription之间创建一个新的惰性IDictionary映射
_methodReferences = new Lazy<IDictionary<string, ApiDescription>>(() => {
var dictionary = new Dictionary<string, ApiDescription>();
var apiExplorer = new ApiExplorer(config);
foreach (var apiDescription in apiExplorer.ApiDescriptions)
{
var descriptor = apiDescription.ActionDescriptor as ReflectedHttpActionDescriptor;
if (descriptor != null)
{
var methodName = string.Format(
@"M:{0}.{1}({2})",
descriptor.MethodInfo.DeclaringType.FullName,
descriptor.MethodInfo.Name,
string.Join(@",",descriptor.GetParameters().Select(x => x.ParameterType.FullName))
);
dictionary[methodName] = apiDescription;
}
}
return dictionary;
});
您会发现,要做到这一点,您需要使各种模型描述从HelpPageModelBase继承,并将父API模型传递给它们(或者更容易传递给懒惰的API模型),但最终它确实起作用
我对这个解决方案不是特别满意;您可能会发现使用某种形式的静态ParseDoc方法更容易,该方法使用默认的Http配置来生成Lazy(但由于我所做的其他扩展不适用于我的情况)。如果您看到更好的方法,请分享!希望它能为您提供一个起点
@Html.Raw(Model.ParseDoc(api.Documentation, Url))