2016-08-30 22 views
0

私はOWIN、自己ホストWeb APIプロジェクトを持っており、SwaggerドキュメントとSwagger UIを追加したいと思います。Swashbuckle - BaseControllerを継承するWeb APIコントローラは表示されません

私はSwashbuckle.Coreパッケージを含んでおり、手動で設定しました。Startup.csです。

configuration.EnableSwagger(s => 
{ 
    s.SingleApiVersion(Assembly.GetExecutingAssembly().GetName().Version.ToString().Replace('.', ' '), "MyApi").; 
    s.IncludeXmlComments([email protected]"{System.AppDomain.CurrentDomain.BaseDirectory}\MyApi.XML"); 
    s.DescribeAllEnumsAsStrings(); 
}) 
.EnableSwaggerUi(s => 
{ 
    // By default, swagger-ui will validate specs against swagger.io's online validator and display the result 
    // in a badge at the bottom of the page. Use these options to set a different validator URL or to disable the 
    // feature entirely. 
    //c.SetValidatorUrl("http://localhost/validator"); 
    s.DisableValidator(); 
}); 

ここでは、ベースコントローラと、ベースから継承する2つの追加コントローラがあります。残念ながら、私はコントローラの名前とアクションがぼんやりしたページに表示されません。ここで

は私のベースコントローラである:

public class BaseController : ApiController 
{ 
    public BaseController() 
    { 
     // Initialization... 
    } 

    public async Task<IHttpActionResult> MyAction() 
    { 
     // Code here... 
    } 
} 

Controler1:

public class My1Controller : BaseController 
{ 
    public MyController1(...): base(...) 
    { 
     // Initialization... 
    } 

    public async Task<IHttpActionResult> Post(Model1 model) 
    { 
     // Code here... 
    } 

    public async Task<IHttpActionResult> Post(Model2 model) 
    { 
     // Code here... 
    } 
} 

コントローラ2:

public class My2Controller : BaseController 
{ 
    public My2Controller(...): base(...) 
    { 
     // Initialization... 
    } 

    public async Task<IHttpActionResult> Post(Model1 model) 
    { 
     // Code here... 
    } 

    public async Task<IHttpActionResult> Post(Model2 model) 
    { 
     // Code here... 
    } 
} 

私が闊歩インデックスページでMy1ControllerMy2Controllerを見ることはできません。私はMy1ControllerMy2ControllerApiExplorerSettings(IgnoreApi = true)]属性を試しましたが、何も起こりませんでした。

コントローラのアクションが共通の名前を共有していますか(複数のパラメータタイプを持つPostのアクション)?上記の例のようにRPCスタイルのURLを使用しているわけではなく、5レベルのメディアタイプ(5LMT)プロポーザルの次のRESTful URLを使用しています。

提案がありますか?

+0

あなたはベースコントローラからか、ベース&子コントローラからのメソッドが表示されないような方法が表示されていない、あなたの問題の帽子です? – bsoulier

+0

@bsoulier正しい、私はぼんやりとしたドキュメントのページ – gdyrrahitis

答えて

0

ASP.NETのWeb APIは、彼らがControllerで終わる自分の名前を持っていないので、あなたのコントローラーが解析されていないことを意味し、naming conventionsで動作します。

これは、MyController1My1Controllerになることを意味します。

ので、例として、次のようにMyController1を変更すると動作します:

public class My1Controller : BaseController 
{ 
    public MyController1(...): base(...) 
    { 
     // Initialization... 
    } 

    public async Task<IHttpActionResult> Post(Model1 model) 
    { 
     // Code here... 
    } 

    public async Task<IHttpActionResult> Post(Model2 model) 
    { 
     // Code here... 
    } 
} 
+0

には表示されませんこれはデモンストレーションのためのもので、コントローラは命名規則に従います。誤解を招くような質問を更新しています。 – gdyrrahitis

+0

pbなし、次回より実際のサンプルを提供する – bsoulier

関連する問題