【发布时间】:2020-07-19 17:04:14
【问题描述】:
我将 Swashbuckle.AspNet.Core 添加到我的存储库并使用默认值初始化所有内容。
虽然我可以看到来自 /swagger/v1/swagger.json 的 JSON 输出打开 /swagger/index.html 只是产生一个空页面。
为什么?
这是我的代码
public void ConfigureServices(IServiceCollection services)
{
services
.AddSwaggerGen()
.AddControllers()
;
}
// This method gets called by the runtime once. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, Options options)
{
if (env.IsDevelopment()) app.UseDeveloperExceptionPage();
app
.UseHttpsRedirection()
.UseRouting()
.UseAuthorization()
.UseEndpoints(endpoints => endpoints.MapControllers())
.UseSwagger()
;
if (env.IsDevelopment()) app.UseSwaggerUI();
}
【问题讨论】:
-
尝试根目录,即 / 或 /swagger 或 /swagger/index.html。使用
c.RoutePrefix = string.Empty;会导致 UI 页面在 root 上呈现。
标签: swagger swagger-ui swashbuckle.aspnetcore