DEV Community


Swagger/OpenAPI and Rails array param

haukot profile image Дмитрий Давыдов Updated on ・1 min read

Ruby On Rails automatically parses query params as array if they are given in format expand[].

Like so

def update
  expand_array = params[:expand]
Enter fullscreen mode Exit fullscreen mode

But how can we write a Swagger(or OpenAPI) documentation for that param?

In this way:

- name: expand[]
  in: query
  type: array
    type: string # our items type
  collectionFormat: multi
Enter fullscreen mode Exit fullscreen mode

collectionFormat: multi is needed so param can exist in a query multiple times, like expand[]=one&expand[]=two, and brackets can be added just to the param name.

Discussion (0)

Editor guide