Swagger UI缺少在WEBAPI中配置的帖子

时间:2018-11-12 11:46:44

标签: .net asp.net-web-api swagger swagger-ui swagger-2.0

我已经安装了Swashbuckle来为我的webapi配置Swagger。但是在浏览时,我无法查看摇摇欲坠的UI。

错误:

 Click here to view error

如何在webapi中启用swagger UI。

1 个答案:

答案 0 :(得分:0)

可以分享您的代码吗?您需要像下面这样在Startup.cs文件中配置设置

public void ConfigureServices(IServiceCollection services)
{
services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info
                {
                    Version = "v1",
                    Title = "some title",
                    Description = "Web API",
                    TermsOfService = "None",
                    Contact = new Contact()
                    {
                        Name = "some name",
                        Email = "someemail@xxxx.com",
                        Url = "<url>"

                    }
                });

                c.OperationFilter<FileUploadOperation>();

            });
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "my api 12345");
            });
}