Skip to content

Hash > Hash > Array[Integer] isn't properly reflected in the Data Type column of the UI #74

Open
@Crystark

Description

@Crystark

Hi,

Considering the following resource, It seems to generate an improper swagger Data Type Example Value:

module Test
  module V1
    class Ping < Grape::API
      resource :ping do
        desc "Are you alive!", tags: ['tools']
        params do
          requires :test, type: Hash, documentation: { param_type: 'body' } do
            requires :hash, type: Hash do
              requires :int_array, type: Array[Integer]
            end
          end
        end
        post do
          'pong'
        end
      end
    end
  end
end

This shows the following:

{
  "test": [
    {
      "hash": [
        {
          "int_array": 0
        }
      ]
    }
  ]
}

However I would expect:

{
  "test": {
    "hash": {
      "int_array": [0]
    }
  }
}

The model is also wrong:

postControlPing {
  test (Array[inline_model_11])
}
inline_model_11 {
  hash (Array[Inline Model 1], optional)
}
Inline Model 1 {
  int_array (integer)
}

it should be:

postControlPing {
  test (inline_model_11)
}
inline_model_11 {
  hash (Inline Model 1, optional)
}
Inline Model 1 {
  int_array (Array[integer])
}

It seems like the array breaks it and is set on every parent member instead of the element iteself.

As a quick fix i'm using:

        params do
          requires :test, type: Hash, documentation: { param_type: 'body' } do
            requires :hash, type: Hash do
              requires :int_array, type: Object, documentation: { type: 'Array[Integer]' }
            end
          end
        end

This prints out:

{
  "test": {
    "hash": {}
  }
}

and

postControlPing {
  test (inline_model_11)
}
inline_model_11 {
  hash (Inline Model 1, optional)
}
Inline Model 1 {
  int_array (Array[Integer])
}

The example isn't perfect but i can fix that with a note in the description of the endpoint.
Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions