如何以多种多样的方式呈现多个查询字符串参数?

时间:2019-05-17 20:42:12

标签: c# swagger query-string autogen

我希望api能够接受多个查询字符串,例如:

GET /{id}?expand=property1,property2

我的api定义为:

public Task<IActionResult> GetAsync([FromRoute] string id, [FromQuery] Expandable expand)

并且将标记枚举可扩展定义为:

        [Flags]
        [JsonConverter(typeof(StringEnumConverter))]
        public enum Expandable
        {
            None = 0x0,
            Property1= 0x1,
            Property2 = 0x2,
            Property3 = 0x3
        }

参数“ expand”的摇动生成为

          {
            "name": "$expand",
            "in": "query",
            "description": "",
            "required": true,
            "type": "string",
            "default": "None",
            "enum": [
              "none",
              "property1",
              "property2",
              "property3"
            ]
          },

但是使用这种摇摇欲坠,自动生成的客户端会接收一个字符串,我不确定应该如何显示摇摇欲坠,以便自动生成的客户端也将接收Flag Enum?

1 个答案:

答案 0 :(得分:0)

您应该将expand参数Expandable[]设置为What does the [Flags] Enum Attribute mean in C#?的标志也被错误地声明