2016-12-19 34 views
1

Swaggerを使用するようにWeb APIプロジェクトを設定しようとしています。Swagger UIでコントローラの操作が表示されない

Swashbuckleをインストールしましたが、http://localhost:55010/swaggerに行ったときにSwagger UIが動作している間に、コントローラの操作が表示されません。私は現在、私のAPIのバージョンが1つだけを持ってhttp://localhost:55010/api/v1/Role

が、私は私がv1を使用していますので、複数のを持っていることを計画しています:

enter image description here

私は私の行動のためのパスのこの種を使用しています私のURLパス(私のControllersフォルダ内のサブフォルダを使って設定します)。ここで

は、私がhttp://localhost:55010/swagger/docs/v1に行くとき、私が見たものである。

{"swagger":"2.0","info":{"version":"v1","title":"Swashbuckle Dummy API V1"},"host":"localhost:55010","schemes":["http"],"paths":{},"definitions":{}} 

これは私が使用していた構成である。

public class SwaggerConfig 
{ 
    public static void Register() 
    { 
     var thisAssembly = typeof(SwaggerConfig).Assembly; 

     GlobalConfiguration.Configuration 
      .EnableSwagger(c => 
       { 
        c.MultipleApiVersions(
         (apiDesc, targetApiVersion) => ResolveVersionSupportByRouteConstraint(apiDesc, targetApiVersion), 
         (vc) => 
         { 
          //vc.Version("v2", "Swashbuckle Dummy API V2"); 
          vc.Version("v1", "Swashbuckle Dummy API V1"); 
         }); 
       }) 
      .EnableSwaggerUi(c => 
       { 
       }); 
    } 

    private static bool ResolveVersionSupportByRouteConstraint(ApiDescription apiDesc, string targetApiVersion) 
    { 
     // I don't know how I am supposed to use this 
     return true; 
    } 
} 

マイルートの設定:

config.Routes.MapHttpRoute(
    name: "WithActionApi", 
    routeTemplate: "api/{folder}/{controller}/{action}/{id}", 
    defaults: new { id = RouteParameter.Optional }, 
    constraints: new { action = @"[A-Za-z]+" } 
); 

config.Routes.MapHttpRoute(
    name: "DefaultApi", 
    routeTemplate: "api/{folder}/{controller}/{id}", 
    defaults: new { action = "DefaultAction", id = RouteParameter.Optional } 
); 

とコントローラの一例:

public class GridTemplateController : BaseController 
{ 
    GridTemplateLogic logic; 

    public GridTemplateController(IPermissionValidator permissionValidator, IRolePermissionLogic logicRolePermission) 
     : base(permissionValidator, logicRolePermission) 
    { 
     logic = new GridTemplateLogic(new GridTemplateRepository(ConnectionString, CurrentUser), permissionValidator); 
    } 

    // GET: api/v1/GridTemplate/ForGrid/5 
    [HttpGet] 
    public IHttpActionResult ForGrid(int id) 
    { 
     try 
     { 
      var entityList = logic.GetAllByGridId(id); 
      return Ok(new ApiResponse(entityList)); 
     } 
     catch (UnauthorizedAccessException) 
     { 
      return Unauthorized(); 
     } 
    } 

    ........... 
+0

は、あなたが質問にルート設定と(の一部)あなたのコントローラを追加することができます? – venerik

+0

@venerikはい私はちょうどそれらを追加しました。ありがとう! – ibiza

+0

'BaseController'は' ApiController'から派生していますか?あなたのAPIは動作していますか?例えば。 'GET/api/v1/GridTemplate/ForGrid/5'を実行すると、期待通りの結果が得られますか? – venerik

答えて

0
これまで

変更闊歩構成:

public class SwaggerConfig 
{ 
    public static void Register(HttpConfiguration config) 
    ... 
} 

そして、すべての他の構成後にそれを設定します。

public partial class Startup 
{ 
    public void Configuration(IAppBuilder app) 
    { 
     ... 
     SwaggerConfig.Register(config); 
    } 
関連する問題