c# - 为什么在 owin 实现后,swagger 不起作用?

标签 c# asp.net-web-api swagger swagger-ui

我正在使用 Microsoft Web API 2 和 SwaggerUi 开发 RESTful 网络服务。

我删除了默认的 Global.asax,并使用 OWIN 配置了我的 Web API。这是我的 Startup.cs 代码:

    public void Configuration(IAppBuilder app)
    {
        HttpConfiguration config = new HttpConfiguration();

        WebApiConfig.Register(config);

        config.MessageHandlers.Add(new JWTAuthenticationHandler() { StopPipelineHandling = true });

        config.Filters.Add(new MyActionFilter());

        SwaggerConfig.Register();

        app.UseWebApi(config);

    }

这是我的 SwaggerConfig.cs 代码:

        GlobalConfiguration.Configuration 
            .EnableSwagger(c =>
                {
                    c.SingleApiVersion("v1", "MyNamespace.WebApi");
                })
            .EnableSwaggerUi(c =>
                {});

此操作后,我无法像下图那样查看 swagger 上的操作:

Swagger screen without actions

请问,你能帮帮我吗?

非常感谢

最佳答案

我已经决定改变:

启动.cs

public void Configuration(IAppBuilder app)
{
    HttpConfiguration config = new HttpConfiguration();

    // Swagger
    SwaggerConfig.Register(config);

    // Authentication token
    ConfigureOAuth(app);

    // SignalR configuration
    ConfigureSignalR(app);

    // Register routes
    WebApiConfig.Register(config);

    // Allow cross-domain requests
    app.UseCors(CorsOptions.AllowAll);

    app.UseWebApi(config);
}

SwaggerConfig.cs

using Swashbuckle.Application;
using System.Web.Http;

namespace Name.API 
{
     public class SwaggerConfig
     {
          public static void Register(HttpConfiguration config)
          {
                config.EnableSwagger(c =>
                {
                    c.SingleApiVersion("v1", "Name.API");   
                })
            .EnableSwaggerUi(c =>
                {
                });
         }
     }
}

我在 https://github.com/domaindrivendev/Swashbuckle/issues/196 上找到了解决方案

关于c# - 为什么在 owin 实现后,swagger 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41148418/

相关文章:

.net-core - 使用 dotnet 6.0 使用最少的 API 时如何在 Swagger UI 中添加方法描述?

c# - wcf api 的 Swagger 文档

c# - 指纹读取器或拇指读取器

c# - 属性路由不起作用 MVC5

asp.net-mvc-4 - WebAPI 如何指定将到达 Controller 的路由

asp.net-mvc - 多个模型和 Breeze 上下文的元数据问题

c# - 如何让 OpenApi Generator 正确转换 Dictionary<int, string>?

c# - 使用表达式时设置 T 的值

c# - CsvHelper 不向内存流写入任何内容

c# - C#开发者需要什么样的机器