【发布时间】:2016-01-16 03:16:53
【问题描述】:
我正在尝试在 REST API 上启用版本控制,其中版本在标头中指定为 "api-version":2、供应商媒体类型、"accept: application/vnd.company.resource-v2+json、application/json; version=2" 或查询字符串 "?version=2"。该实现使用 IHttpRouteConstraint 和 RouteFactoryAttribute。这完美地工作。但是,Swagger 无法将正确的模型与正确的版本化文档相匹配。 operationId 始终来自版本 1 模型。
public class DevicesController : ApiController
{
[HttpGet, RouteVersion( "api/devices", 1, Name = "v1.devices" )]
[ResponseType( typeof( IEnumerable<Models.V1.Device> ) )]
public IHttpActionResult GetV1( )
{
return Ok( new List<Models.V1.Device> { ... } );
}
[HttpGet, RouteVersion( "api/devices", 2, Name = "v2.devices" )]
[ResponseType( typeof( IEnumerable<Models.V2.Device> ) )]
public IHttpActionResult GetV2( )
{
return Ok( new List<Models.V2.Device> { ... } );
}
}
V2 的 Swagger 文档的 operationId 和 MIME 类型错误。
"tags":
[
"Devices"
],
"summary": "Get a list of device(s) by the device identifier",
"operationId": "Devices_GetV1",
"consumes": [ ],
"produces":
[
"application/vnd.safe.inventory-v1+json",
"application/json",
"text/json",
"application/vnd.safe.inventory-v1+xml",
"application/xml",
"text/xml"
],
...
Swashbuckle 5.2.2
我已尝试按照这些帖子中的描述自定义 ApiExplorer:
github.com/domaindrivendev/Swashbuckle/issues/558
github.com/domaindrivendev/Swashbuckle/issues/317
我也尝试过构建自定义选择器。
我也走这条路,但我不认为这是同一个问题。 https://azure.microsoft.com/en-us/documentation/articles/app-service-api-dotnet-swashbuckle-customize/
寻求任何方向的任何帮助将不胜感激。
提前致谢。
【问题讨论】:
标签: swagger