Search code examples
c#swaggerquery-string

How should mulitiple query string parameters be presented in swaggers?


I want the api to be able to accept multiple query strings, for example:

GET /{id}?expand=property1,property2

I have the api defined as:

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

And Flag Enum Epandable defined as:

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

And the swagger for parameter "expand" generated as

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

But with this swagger, the auto-gen client takes in a string, I am not sure how the swagger should be presented so the auto-generated client would also take in a Flag Enum?


Solution

  • you should make expand parameter Expandable[] also your flag is declared incorrectly What does the [Flags] Enum Attribute mean in C#?