grape-swagger icon indicating copy to clipboard operation
grape-swagger copied to clipboard

Cannot get Array of Hash working

Open ahmeij opened this issue 6 years ago • 25 comments

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.

ahmeij avatar Jul 04 '17 13:07 ahmeij

Did you ever get it solved?

michaelwnyc avatar Jul 25 '17 21:07 michaelwnyc

No unfortunately not :(

ahmeij avatar Jul 25 '17 22:07 ahmeij

Sounds like a bug, cause if I run a curl command, it works without any issues.

michaelwnyc avatar Jul 26 '17 00:07 michaelwnyc

I have the same issue, Array of Hashes is not properly shown in the UI

seguidor777 avatar Dec 12 '17 04:12 seguidor777

Please address +1, Have a similar issue after my frontend developer pointed out he could now see the array params.

TheAbyss avatar Dec 27 '17 08:12 TheAbyss

Please contribute @TheAbyss.

dblock avatar Dec 27 '17 15:12 dblock

+1

QETHAN avatar Jan 02 '18 06:01 QETHAN

+1

stephancom avatar Mar 12 '18 20:03 stephancom

+1, this is quite a big issue.

MiralDesai avatar Mar 19 '18 10:03 MiralDesai

+1

VoTaiTri avatar Mar 23 '18 04:03 VoTaiTri

+1

EmCousin avatar Mar 27 '18 15:03 EmCousin

+1

Dima12345 avatar Apr 13 '18 13:04 Dima12345

+1

mfbmina avatar Apr 26 '18 12:04 mfbmina

+1

FUT avatar Aug 01 '18 04:08 FUT

Please add this feature. Any workaround on this.

rabendrasharma avatar Oct 10 '18 12:10 rabendrasharma

Please add this feature @rabendrasharma.

dblock avatar Oct 10 '18 13:10 dblock

+1

QxOxOxQ avatar Nov 09 '18 09:11 QxOxOxQ

+1

mcmegavolt avatar Nov 09 '18 12:11 mcmegavolt

could the maintainer of this package speak his mind about this?

jacek213 avatar Nov 30 '18 10:11 jacek213

Speaking on behalf of the maintainers, nobody is sure why this happens, and nobody has been working on this. At the very least someone should actually dig up where the issue is, to start.

dblock avatar Nov 30 '18 14:11 dblock

I think the problem lies that the hash is eventually being passed to method coerced?(value) in the
Coercible::Coercer with value being a hash and its failing so its throwin a validation error

JeffSafier avatar Jan 16 '20 23:01 JeffSafier

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

braktar avatar Jan 17 '20 10:01 braktar

What version if grape swagger?

On Fri, Jan 17, 2020, 5:42 AM Gwénaël Rault [email protected] wrote:

Isn't it fixed with this PR ? #752 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

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ruby-grape/grape-swagger/issues/617?email_source=notifications&email_token=ADTJ6OZMERAOITHLGI35HZDQ6GDTDA5CNFSM4DRVOFTKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJHI5NI#issuecomment-575573685, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADTJ6O2A5QO6PAONXCXW543Q6GDTDANCNFSM4DRVOFTA .

JeffSafier avatar Jan 17 '20 12:01 JeffSafier

It was integrated within the version 0.34

braktar avatar Jan 17 '20 12:01 braktar

Sorry to bother you again I upgrade my grape-swagger. I am using pagination in one of my endpoints and now I'm getting nomethoderror on the method pagination I'm using grape-kaminari 0.1.9. Doesn't seem to be a more updated version

On Fri, Jan 17, 2020, 7:53 AM Gwénaël Rault [email protected] wrote:

It was integrated within the version 0.34

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ruby-grape/grape-swagger/issues/617?email_source=notifications&email_token=ADTJ6OZEV7UY55J5WQP6MH3Q6GS5XA5CNFSM4DRVOFTKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJHS2RA#issuecomment-575614276, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADTJ6O3OI2UAQSOLSZ4QRXLQ6GS5XANCNFSM4DRVOFTA .

JeffSafier avatar Jan 17 '20 18:01 JeffSafier