ruby-grape / grape

An opinionated framework for creating REST-like APIs in Ruby.
http://www.ruby-grape.org
MIT License
9.86k stars 1.22k forks source link

Error messages depends on previous requests #2460

Closed seriousdev-gh closed 3 weeks ago

seriousdev-gh commented 3 weeks ago

Current Behavior: Error messages contain indices of elements from the previous request.

Expected Behavior: Error messages should be idempotent; for two identical requests, I expect the same error message.

Parameters:

params do
  requires :items, type: Array do
    requires :item, type: Hash do
      requires :name, type: String
    end
  end
end

Sequence of Requests:

Request 1: {} Response: 'items is missing, items[item][name] is missing'

Request 2: {"items":[{"item":{"name":"foo"}},{"item":{"name":"foo"}},{}]} Response: 'items[2][item] is missing, items[2][item][name] is missing'

Request 3: {} Response: 'items is missing, items[2][item][name] is missing'

The response to the last request should be the same as the response to the first request.

This issue is reproducible in version 1.7.1 and in the main branch.

ericproulx commented 3 weeks ago

I could reproduce in within 1.5.3. That's an old one. Thank you for pointing out and the specs

ericproulx commented 3 weeks ago

@seriousdev-gh found a way to fix it