-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Reject non-declared params #1609
Comments
Here's my hacky solution for the time being: module Helpers
def extra_params
@extra_params ||= begin
declared_params = declared(params, include_missing: true).to_h
params.to_h.reject { |k, v| declared_params.key?(k) }
end
end
def reject_extra_params
unless extra_params.empty?
msg = "Unrecognized parameter(s) provided: #{extra_params}"
raise Grape::Exceptions::Base.new(message: msg, status: 400)
end
end
end
class Foo < Grape::Api
helpers Helpers
post do
reject_extra_params
params
end
end |
K, thx. sry about the dup. |
No worries @dhulihan! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It would be nice if grape could reject a non-declared param. Something along the lines of:
If we specify
age
, it is rejected since because it has not been declared.The text was updated successfully, but these errors were encountered: