小编OhW*_*elp的帖子

Swagger 按位枚举标志处理

我有一个类似的枚举;

[Flags]
public enum MeteoType : ushort
{
    Wind = 1 << 0,
    Pressure = 1 << 1,
    Temperature = 1 << 2,
    Waves = 1 << 4,
    Currents = 1 << 9,
    Swell = 1 << 13,
    WindWave = 1 << 14,
}
Run Code Online (Sandbox Code Playgroud)

我有一个模型;

public class Params
{
    public List<MeteoType> Meteo { get; set; } = new List<MeteoType>()
    {
        MeteoType.Wind
    };
    ....
}
Run Code Online (Sandbox Code Playgroud)

在我的控制器方法中,我从查询中请求这个模型;

public async Task<IActionResult> Get(int z, int x, int y, [FromQuery] Params parameters)
Run Code Online (Sandbox Code Playgroud)

这让我大摇大摆地看到了这样的观点:

在此输入图像描述

我使用列表是因为它是一个标志,我希望能够选择多个元素。问题从这里开始。当我选择多个元素时,会创建链接,如下所示:

https://localhost:44311?Meteo=1&Meteo=2&Meteo=4&... …

c# swagger swagger-ui .net-core openapi

7
推荐指数
1
解决办法
1976
查看次数

标签 统计

.net-core ×1

c# ×1

openapi ×1

swagger ×1

swagger-ui ×1