Petros Kalafatidis
Petros Kalafatidis

Reputation: 755

Rails grape swagger Array example value is showing as an object

I have a nested array on my rails grape api.

expose(
      :users,
      documentation: {
        type: Array,
        desc: 'The pickups and deliveries for specific tours'
      },
      using: Fleetdog::Entities::Users
    )

But when I visit the api-docs page the example value is a hash not an array.

example value
{ id: 'string',
users: {
  id: 'string',
  name: 'string'
}

Is this how grape supposed to work?

Upvotes: 1

Views: 228

Answers (1)

Oleksandr Bratashov
Oleksandr Bratashov

Reputation: 908

After exploring sources I've found option is_array and it works:

expose(:projects, documentation: { type: Fleetdog::Entities::Project,
                                   is_array: true,
                                   desc: 'Projects' }) do |query|
  Fleetdog::Entities::Project.represent(
    Queries::Projects.call(query: query)
  )
end

=>

"projects": [
    {
      //...
    }
  ]

Upvotes: 0

Related Questions