从Swagger Doc

问题描述

在路由参数中,我需要ApiVersion类,如下所示。

    [HttpGet("v{version:apiVersion}/Company/{companyId}/absence/{id}")]
    public async Task<IActionResult> Get([Fromroute]ApiVersion version,[Fromroute] int companyId,[Fromroute]int id)
    {...

但是,包括在内会使您大胆地尝试绑定ApiVersion模型并请求GroupVersion,MajorVersion,MinorVersion和Status。我有办法始终删除这些属性,因为不需要提供它们。

enter image description here

解决方法

您可以将[BindNever]添加到您的ApiVersion属性中:

ApiVersion类示例:

  public class ApiVersion
{
    [BindNever]
    public string GroupVersion { get; set; } = "aaa";

    [BindNever]
    public string MajorVersion { get; set; } = "bbb";

    [BindNever]
    public string MinorVersion { get; set; } = "ccc";

    [BindNever]
    public string Status { get; set; } = "ddd";
}

结果: enter image description here