swagger是webapi文档描述及调试工具,要在asp.net mvc中使用swagger,需要安装Swashbuckle.Core这个包,安装好后会在app_start中生成SwaggerConfig.cs文件,修改Register方法在文件中指定webapi项目生成的xml文件所在路径,详细配置请参考
https://github.com/domaindrivendev/Swashbuckle
using System.Web.Http;
using WebActivatorEx;
using Nop.Web;
using Swashbuckle.Application;
using System.Linq;
using System.Reflection;
using Nop.Web.App_Start;
using System.Xml.Linq;
using System.Xml.XPath;
[assembly: PreApplicationStartMethod(typeof(SwaggerConfig), "Register")]
namespace Nop.Web
{
public class SwaggerConfig
{
public static void Register()
{
var xmlFile = string.Format("{0}/Plugins/Misc.Client.WebApi/Nop.Plugin.Misc.Client.WebApi.XML", System.AppDomain.CurrentDomain.BaseDirectory);
GlobalConfiguration.Configuration.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "优里可webapi");
c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
if (System.IO.File.Exists(xmlFile)) { c.IncludeXmlComments(xmlFile); }
});
}
}
}
按上述设置后,可以显示action上的注释,输出输出实体的注释等,看起是不是很爽。