-
Notifications
You must be signed in to change notification settings - Fork 463
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
Validation of submitted parameter keys #122
Conversation
Looks good, I will fix the travis builds and continue with reviews, Thanks for you patience! |
I'd like to support this pull request: I was just about to submit an almost identical pull request myself. We occasionally get complaints that our REST api doesn't work, when in fact the caller has misspelt an optional parameter; this pull request would solve that. (I checked: the merge conflicts are trivially resolved). |
@dprice-fiksu I will take a look and rebase this pull request |
…e api method definition if the validate_keys option is set to true for the config. If unknown params are passed in an UnknownParam exception will be raised.
@dprice-fiksu @iNecas I've updated this pull request so that it is now current with master. Travis CI shows passed. |
if Apipie.configuration.validate_key? | ||
params.reject{|k,_| [:format, :controller, :action].include?(k.to_sym) }.each_key do |param| | ||
# params allowed | ||
raise UnknownParam.new(param) unless description.params.select {|_,p| p.name == param.to_sym}.size > 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A nitpicking one:
raise UnknownParam.new(param) if description.params.select { |_,p| p.name == param.to_sym }.empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One, more serious one, is the to_sym
called on the user input: please use p.name.to_s == param.to_s
instead. (ruby 2.1.1, how much i look forward for you to be our lowest supported version https://bugs.ruby-lang.org/issues/7791)
Thanks for updating this PR. I will merge it after the |
@iNecas Thanks for the feedback. The to_sym bug is interesting. I made the changes requested. |
Thanks, merging now. |
Validation of submitted parameter keys
I'm happy to announce that the new version 0.3.0 was released, including this change. Thanks for making that happen https://github.com/Apipie/apipie-rails/blob/master/CHANGELOG.md#v030 |
Validation of all passed in parameter keys. Check each parameter key that is passed in against the api method definition if the validate_keys option is set to true for the config. If unknown params are passed in an UnknownParam exception will be raised.