ruby-grape / ruby-grape/grape-swagger

Cannot get Array of Hash working

Open
#617 25 comments 11 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
1.1k
Forks
479
Avg merge
2d 14h
Merged PRs (30d)
6

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Ruby Grape API example from the issue and inspect the generated Swagger UI and curl request. Compare the actual nested order_lines serialization with the expected array-of-hash parameters, then determine whether the behavior belongs to grape-swagger, Grape, or swagger-ui. Done means the nested parameters are represented and submitted as expected, with a regression test if the responsible project supports one.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api, documentation
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.