Skip to content

Missing nested optional array transformed into hash with declared method #1847

Closed
@hyunskang

Description

@hyunskang

grape v1.1.0
ruby v2.4.4

API definition:

params do
    requires :obj, type: Hash, allow_blank: false do
    requires :id, type: Integer, allow_blank: false
    optional :arr, type: Array, allow_blank: true do
      requires :k, type: String, allow_blank: false
      requires :v, type: String, allow_blank: false
    end
  end
end
put '/results' do
  present(declared(params))
end

Request body:

{ 
    "obj": { 
        "id": 1 
    } 
}

Response body:

{
    "obj": {
        "id": 1,
        "arr": {
            "k": null,
            "v": null
        }
    }
}

When nested array is missing from the request, declared transforms it into a Hash with nil values.
I would expect it to return nil or an empty array. It looks like there was an issue opened for it, but the specs written for it do not seem to be testing the issue. #1642

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