请考虑下列控制人员:
namespace Web.Controllers
{
[ApiVersioning("1.0")
[Route("api/v{version:apiVersion}/[controller]")]
public class Product : ApiController
{
[HttpGet("id")]
public IHttpActionResult<bool> GetProduct(Guid id)
{ /* rest of the code */ }
}
}
namespace Web.Controllers
{
[ApiVersioning("2.0")
[Route("api/v{version:apiVersion}/[controller]")]
public class Product2 : ApiController
{
[HttpGet("id")]
public IHttpActionResult<bool> GetProduct(Guid id)
{ /* rest of the code */ }
}
}以及Startup类中的Swagger文档:
services.AddSwaggerDocument(config =>
{
config.DocumentName = "v1.0";
config.PostProcess = document =>
{
document.Info.Version = "v1.0";
};
});
services.AddSwaggerDocument(config =>
{
config.DocumentName = "v2.0";
config.PostProcess = document =>
{
document.Info.Version = "v2.0";
};
});现在,在用NSwag测试API浏览器之后,它忽略了版本,并显示了v1和v2文档中的所有API。
如何让NSwag将它们分开?
发布于 2020-06-10 09:32:02
我认为您缺少用于选择Api版本的ApiGroupNames属性。请添加类似于下面代码的ApiGroupNames属性并通知我们。
services.AddSwaggerDocument(config =>
{
config.DocumentName = "v1.0";
config.PostProcess = document =>
{
document.Info.Version = "v1.0";
};
config.ApiGroupNames = new[] { "1.0" };
});
services.AddSwaggerDocument(config =>
{
config.DocumentName = "v2.0";
config.PostProcess = document =>
{
document.Info.Version = "v2.0";
};
config.ApiGroupNames = new[] { "2.0" };
});https://stackoverflow.com/questions/62299388
复制相似问题