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

Validation of submitted parameter keys #122

Merged
merged 2 commits into from
Nov 19, 2014
Merged

Conversation

dfharmon
Copy link
Contributor

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.

@iNecas
Copy link
Member

iNecas commented Jun 10, 2013

Looks good, I will fix the travis builds and continue with reviews, Thanks for you patience!

@dprice-fiksu
Copy link
Contributor

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).

@dfharmon
Copy link
Contributor Author

@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.
@dfharmon
Copy link
Contributor Author

@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
Copy link
Member

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?

Copy link
Member

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)

@iNecas
Copy link
Member

iNecas commented Nov 18, 2014

Thanks for updating this PR. I will merge it after the to_sym issue is solved.

@dfharmon
Copy link
Contributor Author

@iNecas Thanks for the feedback. The to_sym bug is interesting. I made the changes requested.

@iNecas
Copy link
Member

iNecas commented Nov 19, 2014

Thanks, merging now.

iNecas added a commit that referenced this pull request Nov 19, 2014
Validation of submitted parameter keys
@iNecas iNecas merged commit dc2f109 into Apipie:master Nov 19, 2014
@iNecas
Copy link
Member

iNecas commented Jan 7, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants