我有一個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();
});
現在,我有一個基礎控制器和兩個附加的控制器,從基地繼承。不幸的是,我沒有看到控制器的名字和行動在狂歡的頁面。
這裏是我的基本控制器:
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...
}
}
我看不到My1Controller
也不招搖索引頁My2Controller
。我試過My1Controller
和My2Controller
上的ApiExplorerSettings(IgnoreApi = true)]
屬性,但沒有發生任何事情。
是否因爲控制器操作共享通用名稱(具有不同參數類型的多個Post
操作)?我沒有像上面的例子那樣使用RPC風格的URL,而是遵循5級媒體類型(5LMT)提案的RESTful URL。
有什麼建議嗎?
是您的問題帽子看不到從基本控制方法,或者你沒有看到基地和子控制器方法? – bsoulier
@bsoulier正確,我在swagger文檔頁面中看不到這兩個文件 – gdyrrahitis