Skip to content

Cannot get Array of Hash working #617

Open
@ahmeij

Description

@ahmeij

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions