C# Web API文档:/swagger URI只是在页面上返回JSON,而不是UI
我已经将Swashback库添加到我的Web API项目中,以处理API文档。然而,访问此文档的URI只是显示我的swagger选项设置的JSON对象 例如,C# Web API文档:/swagger URI只是在页面上返回JSON,而不是UI,c#,asp.net-web-api2,asp.net-core-1.0,swashbuckle,C#,Asp.net Web Api2,Asp.net Core 1.0,Swashbuckle,我已经将Swashback库添加到我的Web API项目中,以处理API文档。然而,访问此文档的URI只是显示我的swagger选项设置的JSON对象 例如,localhost:XXXXX/swagger重定向到localhost/XXXXX/swagger/docs/v1 然后显示以下与UI相反的内容: {"swagger":"2.0","info":{"version":"v1","title":"FA.Service.Web.API"},"host":"localhost:xxxxx","
localhost:XXXXX/swagger
重定向到localhost/XXXXX/swagger/docs/v1
然后显示以下与UI相反的内容:
{"swagger":"2.0","info":{"version":"v1","title":"FA.Service.Web.API"},"host":"localhost:xxxxx","schemes":["http"],"paths":{},"definitions":{}}
有人能告诉我为什么我的API没有显示swagger UI吗
SwaggerConfig:
public class SwaggerConfig
{
// Get the directory for the XML file.
protected static string GetXmlCommentsPath()
{
return System.String.Format(@"{0}\bin\FA.Service.Web.API.XML", System.AppDomain.CurrentDomain.BaseDirectory);
}
public static void Register()
{
var thisAssembly = typeof(SwaggerConfig).Assembly;
GlobalConfiguration.Configuration
.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "FA.Service.Web.API");
c.IgnoreObsoleteActions();
c.GroupActionsBy(apiDesc => apiDesc.HttpMethod.ToString());
})
.EnableSwaggerUi();
}
}
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
HttpConfiguration config = new HttpConfiguration();
config.DependencyResolver = new UnityDependencyResolver(UnityConfig.GetConfiguredContainer());
ConfigureAuth(app);
WebApiConfig.Register(config);
app.UseCors(CorsOptions.AllowAll);
SwaggerConfig.Register();
app.UseWebApi(config);
}
}
启动:
public class SwaggerConfig
{
// Get the directory for the XML file.
protected static string GetXmlCommentsPath()
{
return System.String.Format(@"{0}\bin\FA.Service.Web.API.XML", System.AppDomain.CurrentDomain.BaseDirectory);
}
public static void Register()
{
var thisAssembly = typeof(SwaggerConfig).Assembly;
GlobalConfiguration.Configuration
.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "FA.Service.Web.API");
c.IgnoreObsoleteActions();
c.GroupActionsBy(apiDesc => apiDesc.HttpMethod.ToString());
})
.EnableSwaggerUi();
}
}
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
HttpConfiguration config = new HttpConfiguration();
config.DependencyResolver = new UnityDependencyResolver(UnityConfig.GetConfiguredContainer());
ConfigureAuth(app);
WebApiConfig.Register(config);
app.UseCors(CorsOptions.AllowAll);
SwaggerConfig.Register();
app.UseWebApi(config);
}
}
您是如何添加Swagger的,您使用过软件包管理器吗?是的,我使用了软件包管理器并添加了Swashback.WebAPi软件包,您是否有有效的APIController,其中包含未显示的方法?啊哈,可能是这样的。。。我以为框架为我们解决了这个问题?那么您认为我需要为/swagger路由添加控制器和操作吗?UI的默认路径是
swagger/UI/index
,而不是swagger
。您是如何添加swagger的,是否使用了package manager?是,我使用了软件包管理器并添加了Swashback.WebAPi软件包,您是否有有效的APIController,其中包含未显示的方法?啊哈,可能是这样。。。我以为框架为我们解决了这个问题?那么您认为我需要为/swagger路由添加控制器和操作吗?UI的默认路径是swagger/UI/index
,而不是swagger
。