【问题标题】:Swagger / Swashbuckle not working on Visual Studio 2013 Web API 2 projectSwagger / Swashbuckle 不适用于 Visual Studio 2013 Web API 2 项目
【发布时间】:2015-03-09 17:53:41
【问题描述】:
我正在尝试通过 Nuget 包 (Swashbuckle) 安装 Swagger,但无法正常工作。
这是一个香草 VS 2013 Web Api 2 项目。 JS 控制台出现一个错误:Uncaught TypeError: Cannot read property 'tags' of null.
在请求 /swagger/ui/lib/underscore-min.map 时收到 404
我发现一个链接建议在 webconfig 中使用 vs:EnableBrowserLink 禁用 BrowserLink,但它似乎没有任何效果。
有什么想法吗?
【问题讨论】:
标签:
c#
asp.net-web-api2
swagger
swagger-ui
swashbuckle
【解决方案1】:
我安装了 Swashbuckle.Core,确保正在创建 XML 输出,并通过一些配置立即工作。
public static void Register(HttpConfiguration config)
{
...
config
.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "My API Title");
c.IncludeXmlComments(GetXmlCommentsFileLocation());
})
.EnableSwaggerUi();
...
}
private static string GetXmlCommentsFileLocation()
{
var baseDirectory = AppDomain.CurrentDomain.BaseDirectory + "\\bin";
var commentsFileName = Assembly.GetExecutingAssembly().GetName().Name + ".XML";
var commentsFileLocation = Path.Combine(baseDirectory, commentsFileName);
return commentsFileLocation;
}