gdy*_*tis 5 c# asp.net-web-api swagger swagger-ui swashbuckle
我有一个 OWIN,自托管的 Web API 项目,我想向其中添加 Swagger 文档和 Swagger UI。
我已经包含了 Swashbuckle.Core 包,并且我已经在Startup.cs
.
configuration.EnableSwagger(s =>
{
s.SingleApiVersion(Assembly.GetExecutingAssembly().GetName().Version.ToString().Replace('.', ' '), "MyApi").;
s.IncludeXmlComments($@"{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();
});
Run Code Online (Sandbox Code Playgroud)
现在,我有一个基本控制器和两个从基本控制器继承的附加控制器。不幸的是,我在 swagger 页面中没有看到控制器的名称和操作。
这是我的基本控制器:
public class BaseController : ApiController
{
public BaseController()
{
// Initialization...
}
public async Task<IHttpActionResult> MyAction()
{
// Code here...
}
}
Run Code Online (Sandbox Code Playgroud)
控制器1:
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...
}
}
Run Code Online (Sandbox Code Playgroud)
控制器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...
}
}
Run Code Online (Sandbox Code Playgroud)
我看不到的My1Controller
,也不是My2Controller
在招摇索引页。我已经尝试了该ApiExplorerSettings(IgnoreApi = true)]
属性My1Controller
,My2Controller
但没有任何反应。
是不是因为控制器动作共享通用名称(Post
具有不同参数类型的多个动作)?我没有像上面的例子那样使用 RPC 风格的 URL,而是使用 RESTful URL,遵循 5 级媒体类型 (5LMT) 提案。
有什么建议吗?
小智 0
您看不到它们的原因是因为 swashbuckle 只读取 ApiCOntrollers,除 OdataController 之外的任何其他都必须由开发人员在自定义文档过滤器的帮助下添加。这是示例 https://github.com/domaindrivendev/Swashbuckle/blob/master/README.md
归档时间: |
|
查看次数: |
3478 次 |
最近记录: |