-
-
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
Corrected the endpoint parameter name generation. #2189
Conversation
Signed-off-by: Hermann Mayer <[email protected]>
Signed-off-by: Hermann Mayer <[email protected]>
Signed-off-by: Hermann Mayer <[email protected]>
I spend some time on the parameter renaming just inside the |
I think you're spot on, and should fix the intended behavior as you described. Your proposed solution is also quite simple. Happy to review on green! |
Okay, great. I merged my renaming solution into this branch :)
This fails on master, too. expected NoMethodError with "undefined method |
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.
This is excellent work. thank you.
I have some nits. Plus this changes behavior that I believe we need to document in UPGRADING, please?
Signed-off-by: Hermann Mayer <[email protected]>
Thanks :)
I took care of the nits and added an upgrading section. I would not recommend releasing this change as a patch version because it breaks current behavior, even though it's a bug fix in the narrower sense. |
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.
Agreed on the minor bump. Let's bump the version in this PR to 1.6 as well, please. Don't forget to re-update the numbers in UPGRADING.
Signed-off-by: Hermann Mayer <[email protected]>
Did it :) |
Merged, thank you! |
What do you think about a release in the next few days? :) |
I'll get to it sooner than later unless another maintainer can beat me to it. |
ping @dblock - is there anything blocking a release? :) |
Released 1.6.0 |
- What is it good for
I've expected bad parameter documentation with grape-swagger when renaming with
as: ...
. The expected behavior is that the original parameter name is used for documentation. Let's look at this example:I want my API clients to send the
address
parameter, and in my endpoint definition I want to update the entity (AR,accepts_nested_attributes_for
enabled) by usinguser.update!(declared(params, include_missing: false))
. Sure, it's just convenient to rename the parameter for internal use, but that's how it is documented. The resulting Swagger definition looks like this:This is clearly the internal name that should not be sent nor be documented. This pull request addresses the documentation issue.
- What I did
I just added the original parameter name when a renaming was done which is then used as the parent element name. Additionally, I added a bunch of examples to get this right.
- Open questions
As you might see in the specs I encountered some cases that should behave differently. This boils down to the ability to bypass parameter validation for renamed scalar parameters when the client knows/guesses the internal name. The renaming is implemented right now as a validator which just adds the renamed parameter name into the params hash. When we then use the
declared(params, include_missing: false)
method in order to get only the declared and validated parameters we can be tricked.I was wondering why the renaming is not just part of the declared method implementation. This would prevent validation bypassing, while also allows us to ignore parameters we do not expect. So we could ensure the following scenarios:
Is there something I'm missing here? I would like to address this too if the issue is reasonable.
- A picture of a cute animal (not mandatory but encouraged)