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)

Bump.sh

Hate writing docs? Hate undocumented APIs even more?

Bump.sh generates an always up-to-date API reference site for REST and Event-Driven Architectures.

Plug it in your CI. It fetches your OpenAPI and AsyncAPI (GraphQL pending) spec files, and even generates a diff. Gather all of your API docs in a single source of truth.

Try it for free

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay