DEV Community

Dmitry Daw
Dmitry Daw

Posted on • Edited on

3 3

Swagger/OpenAPI and Rails array param

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.

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more