grape-swagger: Cannot get Array of Hash working

Thanks for building this great bridge between swagger and grape.

I have spent a good bit of time trying to get the following to work, I have even created a minor rails test environment to see if the complicated setup is the cause but I can reproduce it with only a few lines of code.

I’d like to create an order with multiple order lines.

require 'grape-swagger'

module Twitter
  class API < Grape::API
    format :json
    prefix :api

    resource :orders do
      desc 'Create an order'
      params do
        optional :order_type
        optional :order_lines, type: Array do
          optional :product
          optional :quantity, type: Integer
        end
      end
      post do
        params
      end
    end

    add_swagger_documentation
  end
end

This gives me the following swagger-ui result

screen shot 2017-07-04 at 15 28 49

I was really hoping it would allow for these nested order-lines to work. However checking the curl line the posted output is not as expected:

I’d expect it to post order_lines[0][product]='cheese'&order_lines[0][quantity]=1

Also I think the UI looks funky, but that might be just swagger?

I’m really at a loss here if this is a grape-swagger, grape or swagger-ui issue, I am hoping you guys know what is wrong with my example.

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 10
  • Comments: 25 (5 by maintainers)

Most upvoted comments

Isn’t it fixed with this PR ? https://github.com/ruby-grape/grape-swagger/pull/752

With the condition to put ‘documentation: { param_type: ‘body’ }’ in the definition of a top level object

Please add this feature @rabendrasharma.