0
我在我的ASP.Net MVC核心项目中安装了Swagger,它精美地记录了我的API。什么导致Web API 2的路由集合中已出现swagger错误?
我的同事让我把它安装在一个完整的框架4.6.1项目中,所以我做了以下工作。
在包控制台管理运行:
Install-Package Swashbuckle
为了让您的测试Web API控制器工作: 1)在WebApi.config评论了这一点:
// config.SuppressDefaultHostAuthentication();
// config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
现在这个网址: http://localhost:33515/api/Test 带回XML:
<ArrayOfstring xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<string>value1</string>
<string>value2</string>
</ArrayOfstring>
在Global.asax中注册()我称之为:
SwaggerConfig.Register();
在AppStart.Swagger.Config寄存器()我把:
public class SwaggerConfig
{
public static void Register()
{
var thisAssembly = typeof(SwaggerConfig).Assembly;
GlobalConfiguration.Configuration
.EnableSwagger(c =>
{
c.SingleApiVersion("v1.0", "HRSA CHAFS");
c.IncludeXmlComments(GetXmlCommentsPath());
})
.EnableSwaggerUi(c =>
{});
}
private static string GetXmlCommentsPath()
{
var path = String.Format(@"{0}bin\Services.XML", AppDomain.CurrentDomain.BaseDirectory);
return path;
}
}
现在我得到这个错误: “命名为A路线“ swagger_docsswagger/docs/{apiVersion}'已经在路由集合中。路线名称必须是唯一的。”
我一直停留在这几个小时。 你如何摆脱呢?
您是否找到解决方案? – MichaelD