-
-
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
Provide ability to restrict declared(params) to local endpoint #530
Conversation
To keep a positive spirit,... okay, to keep things consistent with other options, I'd like that option to be a positive one. Instead of |
Quite understand the desire for consistency. How about:
Thinking being that 'parent' is more descriptive than 'containing'
Thoughts? |
Are there any other kinds of namespaces? Otherwise maybe just |
The only potential confusion is with class MyAPI < Grape::API
params do
requires :id, type: String
end
namespace ':id' do
params do
requires :name, type: String
end
get do
# ** CALL FROM HERE **
declared(params)....
end
params do
requires :age, type: Integer
end
namespace ':age' do
# ...
end
end
end Hence 'parent' captures every namespace that contains the current endpoint. |
That makes sense. I'll take a PR with whichever. |
Ok, I've updated the commit to use Let me know if there's any further clarifications I can make |
@dblock - any update on this? |
This looks good. Can you amend with a CHANGELOG entry, please? Thx. |
All done |
expect(json[:declared_params].keys).to match_array [:foo, :bar, :id] | ||
end | ||
|
||
it 'should not include params defined in the parent namespace with include_parent_namespaces: false' do |
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.
Change the text from "should not include" to "does not include".
See my minor comment in spec, and please rebase this. |
All done (again!) |
Merged via 3a55dc7 (slight change in the CHANGELOG wording). |
Awesome. Thanks |
#503 (which has been pulled) changes the default behaviour of
declared(params)
to return all params from the current endpoint and containing namespaces.This PR provides the ability to restrict that to the local endpoint (effectively the previous default behaviour) via an option:
declared(params, restrict_local: true)
This is particularly useful for endpoints which create/update resources.
I think the current default (i.e. with #503 pulled) is correct. i.e. one should have to specify
restrict_local
to only consider params defined on the local/current endpoint, hence this PR. Arguably the ability to restrict should have been included in #503.Thoughts?
I can updated the
CHANGELOG
if we are comfortable.