DEV Community

loading...

Swagger/OpenAPI and Rails array param

Dmitry Daw
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]
end
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
  items:
    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)