Skip to content

declared method returns unexpected value for nested optional empty array and empty hash #2042

Closed
@kadotami

Description

@kadotami

version 1.3.2

API definition

params do
    requires :id, type: Integer
    optional :hash, type: Hash do
      requires :name, type: String
    end
    requires :arr_parent, type: Hash do
      requires :id, type: Integer
      optional :arr, type: Array do
        requires :k, type: String
        requires :v, type: String
      end
    end
  end
end
put '/results' do
  declared_params = declared(params)
end

Request body:

{ 
    "id": 1,
    "arr_parent": {
        "id": 1 
    }
}

real declared_params:

{
    "id": 1,
    "hash": {
        "name": nil
    },
    "arr_parent": {
        "id": 1,
        "arr": {
            "k": nil,
            "v": nil
        }
    }
}

expected declared_params:

{
    "id": 1,
    "hash": {} or nil
    "arr_parent": {
        "id": 1,
        "arr": []
    }
}

is this bugs? or specification?

declared_param_is_array? method in lib/grape/dsl/inside_route.rb doesn't seem to work correctly for nested array.

maybe relate #1847

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