我已经为ASP.NET Web应用程序启用了详尽的文档。如何设置basePath?
GlobalConfiguration.Configuration .EnableSwagger(c => {
c.SingleApiVersion("v1", "MyApi") .Description("This is my API.");
c.IncludeXmlComments($@"{AppDomain.CurrentDomain.BaseDirectory}\bin\MyApi.XML");
}) .EnableSwaggerUi(c => {});
当前生成的API描述如下:
"swagger": "2.0",
"host": "localhost:8080",
"basePath": "/",
我想将其更改为:
"swagger": "2.0",
"host": "localhost:8080",
"basePath": "/myapi",
答案 0 :(得分:2)
您需要将 RootUrl 添加到您的配置中,例如:
GlobalConfiguration.Configuration .EnableSwagger(c => {
c.SingleApiVersion("v1", "MyApi") .Description("This is my API.");
c.IncludeXmlComments($@"{AppDomain.CurrentDomain.BaseDirectory}\bin\MyApi.XML");
c.RootUrl(req => { return "http://localhost:8080/myapi"; });
}) .EnableSwaggerUi(c => {});