1

I want to specify a query parameter called fields that can be sent as a string list with multiple possible values in my OpenAPI 3 specification.

i.e., all of these are valid for my purposes: fields=name fields=title,abstract fields=name,title,abstract

I was going to use the enum type (as below), but it occurs to me this is wrong, as this means only one of the given values should be used.

        "fields": {
            "name": "fields",
            "in": "query",
            "description": "The data fields to be returned from the response.",
            "required": false,
            "schema": {
                "type": "string",
                "enum": [
                    "name",
                    "title",
                    "abstract"
                ]
            }
        },

How do I specify a list of possible valid options? Do I have to use the pattern field and a regex? Or is there a better way?

GIS-Jonathan
  • 4,347
  • 11
  • 31
  • 45
  • @Helen - Thanks, I didn't see that when looking. It's not tagged with OpenAPI. (is now). That said, the OpenAPI spec says that enum is from the JSON schema spec, which explicitly says `equal to one of the elements` - http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.1.2 - which is why I don't believe enum is the solution. – GIS-Jonathan Dec 14 '18 at 17:02
  • The solution is an _array_ of enum. A query param with comma-separated values = array. – Helen Dec 14 '18 at 17:04
  • @Helen - Ah yes, that worked nicely. Very non-obvious though (and counter to the docs!). Thanks! – GIS-Jonathan Dec 14 '18 at 17:07

0 Answers0