【发布时间】:2017-10-05 09:30:32
【问题描述】:
我在我的 WebAPI 项目上设置了 Swagger/Swashbuckle。我遵循了guide from Microsoft,其中介绍了如何使用 Swagger 设置 Aspnet.WebApi.Versioning。我的API有多个版本,所以在路由属性中设置了{version}参数,像这样:
[ApiVersion("2")]
[RoutePrefix("api/{version:apiVersion}/values")]
public class AccountController : ApiController
{
[Route("UserInfo")]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
}
我的问题是,这会在文档中显示的路径中显示 {version} 属性,如下所示:
相反,我希望此路径属性实际上具有 ApiVersion 属性中的值,这样阅读文档的客户就不会感到困惑。理想情况下,假设 UrlDiscoverySelector 设置为 v2,上述路径应为:
/api/2/account/userinfo
/api/2/account/externallogin
/api/2/account/manageinfo
我尝试在 UI 中简单地替换 ApiExplorer 的 RelativePath 中的 {version},但由于 {version} 已更改为 query 参数而不是 path,因此破坏了测试功能,这不是我的 API 的配置方式。
是否可以在 swagger 构建文档之前修改 ApiExplorer 中的值,同时仍保留测试功能?
【问题讨论】:
标签: c# asp.net-web-api swagger swashbuckle api-versioning