我有一个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