Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why, after owin implementation, swagger not work?

I'm developing an RESTful web service using Microsoft Web API 2 and SwaggerUi.

I've removed default Global.asax and I've configured my Web API using OWIN. This is my Startup.cs code:

    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);

    }

This is my SwaggerConfig.cs code:

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

After this operation I cannot view the actions on swagger like following images:

Swagger screen without actions

Please, can you help me?

Thank you a lot

like image 738
ilMattion Avatar asked Dec 19 '22 11:12

ilMattion


1 Answers

I've resolved changing:

Startup.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 =>
                {
                });
         }
     }
}

I've find the solution on https://github.com/domaindrivendev/Swashbuckle/issues/196

like image 152
ilMattion Avatar answered Dec 24 '22 00:12

ilMattion