2017-06-20 41 views
0

我創建了VS2015和.Net Core Web API項目。 我下面的例子中http://www.technicalblogs.sentientmindz.com/2017/04/09/enabling-swagger-support-to-the-web-api/在Azure Web API中調用UseSwagger時出錯

我已經安裝了Swashbuckle.AspNetCore和未來努力的代碼,但得到的錯誤使用UseSwagger時。請建議我。

/* Startup.cs */ 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using Microsoft.Owin; 
using Owin; 
using Swashbuckle.AspNetCore.Swagger; 
using Microsoft.Extensions.DependencyInjection; 

[assembly: OwinStartup(typeof(TestApi.Startup))] 

namespace TestApi 
{ 
    public partial class Startup 
    { 
     public void Configuration(IAppBuilder app) 
     { 
     ConfigureAuth(app); 

     /*use swagger added by me*/ 
     app.UseSwagger();  /*ERROR:iAppBuilder does not contain definition for UseSwagger…*/ 
     app.UseSwaggerUI(c =>. /*ERROR :iAppBuilder does not contain definition for UseSwaggerUI…*/ 
     { 
      c.SwaggerEndpoint("/swagger/v1/swagger.json", "Accounts API V1"); 
     }); 

    } 

    //Add framework services by me 
    public void ConfigureServices(IServiceCollection services) { 
     services.AddSwaggerGen(c => 
     { 
      c.SwaggerDoc("v1", new Info { Title = "AcccountsAPI", Version = "v1" }); 
     }); 

     } 
    } 
} 

回答

0

我從你的代碼,您正在使用的.Net核心假設V1.1,這是多麼我已經做到了:

public void Configuration(IAppBuilder app) 
    { 
     HttpConfiguration config = new HttpConfiguration(); 
     WebApiConfig.Register(config); 
     config.EnableSwagger(c => 
     { 
      c.SingleApiVersion("v1", "WebAPI"); 
      c.IncludeXmlComments(GetXmlCommentsPath()); 
      c.ResolveConflictingActions(x => x.First()); 

     }).EnableSwaggerUi(); 
    } 

    protected static string GetXmlCommentsPath() 
    { 
     return System.String.Format([email protected]"{0}\bin\MyApi.XML", 
       System.AppDomain.CurrentDomain.BaseDirectory); 
    } 
相關問題