[英]Swagger ui is unable to load the json specification file in server
[英]Unable to change swagger ui path
我正在使用Swagger / Swashbuckle 5.6版为ASP.Net Web API 2项目生成文档。
默认情况下,可以通过URL http:// localhost:56081 / swagger / ui / index访问API文档。
但是,我希望它应该在http:// localhost:56081 / apihelp /中可用
我进行了大量搜索,尝试更改SwaggerConfig.cs文件中的设置,但似乎没有任何效果。
那么,这可能吗? 如果是,有人可以帮助我吗?
您可以将路径添加到EnableSwaggereUi
的调用,例如:
SwaggerConfig.Register(HttpConfiguration config)
{
config.EnableSwaggerUi("apihelp/{*assetPath}", c =>
... // following lines omitted
}
然后,您可以使用URL http:// localhost:56081 / apihelp / index调用UI
请参阅https://github.com/domaindrivendev/Swashbuckle#custom-routes以获取参考。
请注意:默认设置'swagger'自动重定向到'swagger / ui / index',但是当您仅使用'apihelp'时,此自定义设置不会自动重定向到'apihelp / index'。 要实现自动重定向,您可以在WebApiConfig
添加路由:
config.Routes.MapHttpRoute(
name: "Swagger UI",
routeTemplate: "apihelp",
defaults: null,
constraints: null,
handler: new RedirectHandler(message => message.RequestUri.ToString().TrimEnd('/'), "/index"));
重定向代码基于v.karbovnichy在“ 如何从根url重定向到/ swagger / ui / index?”中的回答。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.