Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kadotami opened this issue Apr 23, 2020 · 1 comment
Labels

Comments

@kadotami
Copy link
Contributor

kadotami commented Apr 23, 2020

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

@dblock
Copy link
Member

dblock commented Apr 23, 2020

I want to say it's a bug. Try PRing this as a spec + fix?

@dblock dblock added the bug? label Apr 23, 2020
kadotami added a commit to kadotami/grape that referenced this issue Apr 27, 2020
kadotami added a commit to kadotami/grape that referenced this issue Apr 27, 2020
kadotami added a commit to kadotami/grape that referenced this issue Apr 27, 2020
kadotami added a commit to kadotami/grape that referenced this issue Apr 27, 2020
kadotami added a commit to kadotami/grape that referenced this issue Apr 27, 2020
kadotami added a commit to kadotami/grape that referenced this issue Apr 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants