-
Notifications
You must be signed in to change notification settings - Fork 284
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
Fix #1549 - Support bodyParam attribute without form parameter name too map the whole body to a single parameter #1676
Conversation
…name to map the whole body to a single parameter
This will not be necessary anymore if vibe-d/vibe.d#1676 gets pulled
Any news? |
This may go a bit too far. The library may not be declared stable, but is already used in production all over the place, so silent breaking changes like these are usually a no-go. Generally, I think that keeping things orthogonal here may be a good idea. For example, in the web frontend the equivalent rule would be very surprising and generally undesirable (form with only a single input field). |
Apart from the open questions, the implementation looks good and ready to merge! |
web/vibe/web/common.d
Outdated
@@ -463,11 +463,14 @@ package struct WebParamAttribute { | |||
string field; | |||
} | |||
|
|||
package(vibe.web) enum bodyParamWholeName = "bodyParamWhole"; |
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.
What about using an empty string here and asserting in the two-argument @bodyParam
overload that the field name is always non-empty? That would eliminate any possibility for name clashes. I'd also tend to encapsulate the "whole body" logic into WebParamAttribute
(e.g. WebParamAttribute.isAllInOne
or similar, which performs the name comparison) - thinking about it, it may also make sense to extend this to query string parameters later on.
examples/rest/source/app.d
Outdated
@@ -352,6 +352,9 @@ unittest | |||
* This is to be consistent with the way D 'out' and 'ref' works. | |||
* However, it makes no sense to have 'ref' or 'out' parameters on | |||
* body or query parameter, so those are treated as error at compile time. | |||
* | |||
* To serialize the entire Json body into one parameter, simply name the | |||
* parameter "foo" |
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.
The "foo" was a surprise here, was that left over from an earlier approach?
Hm, I can't really adjust to the new review feature. I guess I'll just stick to normal comments. |
…heck for wholeBody
I am not sure how I would be able to access the
I get your point and I removed the default rule to serialize the entire body into an parameter if only parameter is provided, s.t. this isn't blocking this PR. auto postA(FooType1 obj);
auto postB(FooType2 obj);
auto postC(FooType3 obj);
.... Maybe we can use a special name like it's currently done for |
Right, I didn't think of that. But looking at it, the cleanest way to pass that information seems to be to create a new
I was thinking about using a default name, too, but the "id" feature is rather questionable today when the |
Suggestions implemented in #1723. |
As discussed in #1549 and #1422:
Moreover if
@bodyParam
annotation is providedPOST
@bodyParam
parameterthen the entire Json body is serialized into this parameter. This might be a breaking change, but imho it's a sane default setting as most APIs want to serialize the entire request body and vibe.d hasn't reached stable yet.