【问题标题】:Swagger UI missing post configuring in WEBAPISwagger UI 缺少​​ WEBAPI 中的帖子配置
【发布时间】:2019-04-15 03:14:23
【问题描述】:

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

错误:

如何在 webapi 中启用 Swagger UI。

【问题讨论】:

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


    【解决方案1】:

    您需要在 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");
                });
    }
    

    【讨论】:

    • 在新的 webapi 项目中,我刚刚安装了 Package Swashbuckle 并在浏览 Swagger UI 时显示。但是在我现有的旧 webapi 中,安装 swagger 包后 UI 是空的。
    • 你是否为旧的 web api 配置了相同的设置?请发布一些代码,以便提供解决方案。
    猜你喜欢
    • 2016-07-31
    • 1970-01-01
    • 2019-04-24
    • 2020-09-12
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 2018-06-23
    相关资源
    最近更新 更多