OpenAPI-Specification icon indicating copy to clipboard operation
OpenAPI-Specification copied to clipboard

Allow multi-dimensional arrays as query parameters

Open nsossonko opened this issue 10 years ago • 6 comments

Essentially, objects should be allowed at the query parameter level because it is perfectly legal to have a multi-dimensional array in a query parameter. Eg:

?q[first][]=First&q[last][]=Last

The spec already supports arrays with no keys, but not this format.

Thanks.

nsossonko avatar May 06 '16 18:05 nsossonko

Do you have a proposal on how this could look in an API definition? Do you want to allow arbitrary keys (to be chosen by the caller), just keys which are predefined in the API definition, or both? Should all such entries have the same value type, or different ones for each key?

ePaul avatar May 06 '16 20:05 ePaul

I would think this is like being able to use complex (or object based) parameters. This output is what you see generally in jquery and what PHP uses (I am assuming others do as well). I can here looking for a solution as well to describe an API that uses calls with object based variables.

could this look like:

parameters:
  q:
    type:'object'
    in: query
    properties:
       firstname:
         type: array
         items:
           type: string

starfishmod avatar May 07 '16 02:05 starfishmod

IMHO the spec is not correct in the way it deals with this type of content. It's currently possible to define a spec that does not make sense but will pass validation. For example, if my path consumes "application/json" and "application/x-www-form-urlencoded" (or "multipart/form-data") I won't be able to properly define that in my parameters because the "application/json" needs to be defined in a "body" parameter and the form types need to be defined in a "formData" parameter, but only one of those two is allowed in any given path. That makes my spec wrong but valid.

Realistically speaking, there's no problem with this type of API. formData should not be a separate type of parameter, it should be the body parameter and follow the schema of the ref'ed object just like any other content type. This same rule should apply anywhere form content is used (so in query parameters too).

nsossonko avatar May 09 '16 12:05 nsossonko

FYI complex parameter types will be in the next spec version. Note here:

https://github.com/OAI/OpenAPI-Specification/blob/OpenAPI.next/versions/3.0.md#parameterObject

The schema property now exists for all parameter types.

fehguy avatar May 09 '16 13:05 fehguy

@fehguy awesome thanks!

nsossonko avatar May 09 '16 13:05 nsossonko

Closing as supported in 3.0 draft, and therefore will be in next version

fehguy avatar Feb 01 '17 20:02 fehguy