小编Tob*_*bol的帖子

从 swagger 响应中排除 ef 虚拟属性

我使用 ef-core 将 Swashbuckle 添加到了 .net core web-api 项目。我的问题是我的 ef 自动生成的类的虚拟属性被添加到 swagger 示例响应中,这使得响应变得巨大,我只想显示表属性,而不是关系。

控制器的代码示例:

[HttpGet("devices", Name = "GetDevices")]
public async Task<ActionResult<List<Device>>> Devices()
{
    var devices = await _deviceDa.GetDevices();
    return Json(devices);
}
Run Code Online (Sandbox Code Playgroud)

我的问题是 ef 自动生成的类位于一个单独的类库中,我无权更改。我不能简单地将 JsonIgnore 添加到这些虚拟属性中。

是否有可能让 Swashbuckle 忽略所有虚拟属性?

c# swagger swashbuckle asp.net-core-webapi

5
推荐指数
1
解决办法
1804
查看次数

标签 统计

asp.net-core-webapi ×1

c# ×1

swagger ×1

swashbuckle ×1