2016-12-14 4 views
1

Ich entwickle einen RESTful Web Service mit Microsoft Web API 2 und SwaggerUi.Warum, nach der Implementierung, funktioniert Swagger nicht?

Ich habe Standard Global.asax entfernt und ich habe meine Web-API mit OWIN konfiguriert. Das ist mein 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); 

    } 

Das ist mein SwaggerConfig.cs Code ist:

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

Nach dieser Operation ich nicht die Aktionen auf Prahlerei wie folgende Bilder betrachten:

Swagger screen without actions

Bitte, können Sie mir helfen?

Danke viel

+2

Ich schlage vor, dass Sie Ihre Browser-Entwickler-Tools (F12) verwenden, um zu sehen, was von Ihrer Web-API zurückgegeben wird. Höchstwahrscheinlich erhalten Sie Fehlerstatuscodes, die Sie dann beheben müssen. –

+0

Hallo Martin, ich habe es ausprobiert und ich kann meine API richtig nutzen. – ilMattion

+0

Versuchen Sie dies, anstatt mit "GlobalConfiguration.Configuration" zu übergeben, übergeben Sie die httpConfiguration an das Swagger-Register. public static void Register (HttpConfiguration config) { config.EnableSwagger (c => { c.SingleApiVersion ("v1", "MyNamespace.WebApi");}) .EnableSwaggerUi();} – Prashant

Antwort

2

ich Wechsel behoben haben:

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

Ich habe die Lösung auf https://github.com/domaindrivendev/Swashbuckle/issues/196 finden

Verwandte Themen