-
Notifications
You must be signed in to change notification settings - Fork 393
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
Params fixes and features #289
Params fixes and features #289
Conversation
As we introduce breaking changes, I would also propose renaming misleading @pleerock Can I do this also in this PR? |
I agree! I wanted to bring this to attention as well! Green light from me. We can revert it later if @pleerock says otherwise. |
@NoNameProvided done in dd4f710 😉 |
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 typo + a minor change. Logic is LGTM so I approve. We can merge after pushing that two change.
src/ActionParameterHandler.ts
Outdated
if (value === null || value === undefined) | ||
return value; | ||
|
||
switch (param.targetName) { | ||
// if param value is an object and param type match, normalize its string properties | ||
if (typeof value === "object" && ["queries", "headers", "path-params", "cookies"].indexOf(param.type) !== -1) { |
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.
.some
is easier to read than .indexOf
so please ["queries", "headers", "path-params", "cookies"].indexOf(param.type) !== -1
=> ["queries", "headers", "path-params", "cookies"].some(type => type == param.type)
src/ActionParameterHandler.ts
Outdated
} | ||
}); | ||
} | ||
// if value is a string, normalize it to demand type |
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.
demand
=> demanded
@NoNameProvided done in d7fe496. We should merge it to new major release branch to collect all pending breaking changes and to not block hot fixes. |
Ok, so how about having a master what HEAD's always at the latest stable major release, having a develop branch what is always released as |
Yes, we would merge it to development branch, and it can be released as Master would be then stable, all hotfix/bugfix land here (and merged to development from master), new breaking changes features to the development. When we group together all breaking changes, we can merge it to master and release as 0.8.0 stable. |
@NoNameProvided Please take a look at the project board: |
no. I understood you both want to make it consistent with other decorator names, but I don't find that its necessary to do so, if choice is between make it consistent and call "@PathParam" or make it inconsistent but call it "@param" then second choice absolutely wins because of its simplicity and everyone addiction. Everyone use .params (including express, angular, etc.) for router params and its already a accepted standard. Also "PathParam" sounds odd and "path" does not tell me anything meaningful (path - associations with filesystem, not a route, better name would be a "@RouteParam", but Im not agree with it either. Sorry, my bad for late respond here, but please be careful next time before merging such serious changes. |
if (value === "") return undefined; | ||
return +value; | ||
if (value === "") { | ||
throw new ParamNormalizationError(value, parameterName, parameterType); |
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.
in ParamNormalizationError
I don't like Normalization
word. It does not tell user so much, user may think - what is "normalization?". Normalization is more implementation-specific, what is going on in this code. I think it will be better user experience if we replace Normalization with at least Validation
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.
Normalization is a "process that makes something more normal or regular". However the better name would be transforming, because we transform string to numbers or boolean, however I don't know if it wouldn't collide with the error that "class-transformer" throws (if any?).
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.
Normalization is a "process that makes something more normal or regular".
right, thats why I called this method "normalize". But its routing-controllers internals, we need something more user-friendly for users since they will see this message. Same with tranformation. We shall tell users "dude you have a wrong parameter" instead of "dude transormation of your parameter failed" or "dude normalization of your parameter failed".
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.
It's just an internal name. Have you checked the source code of this error?
`Given parameter ${parameterName} is invalid. Value (${JSON.stringify(value)}) cannot be parsed into ${parameterType}.`
Isn't it a user-friendly message?
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.
just internal name
no, error name is used as well.
Isn't it a user-friendly message?
yes, it is. And we can clearly admin that class name is a short name of message inside it. And message inside it does not tell anything about normalization or transformation
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.
So you suggest that it should be InvalidParamError
?
Don't worry, it's only merged into
It has to be consistent and general General |
yeah I know, but anyway you did redundant job as well.
thats why Java sucks. It has too much redundancy.
if we talk about params its about
thats different. Im not talking "to name everything like in express because we are abstraction layer over express". Im talking to use
my thoughts about #291 are already there |
@pleerock I fail to see how you see simplicity in breaking a convention for one type. If there is multiple types of
Your statement just justify the PR, as a reader I need to ask what kind of param we talk about. Param can be any type you just decided to use it for route params.
Yeah |
hey, hey, not me! Its an accepted practice - just "params" are route params. "query params" are "query params". Veu, angular, react, express, koa any node.js and even some php frameworks I know use "params" as router params, and if there query params as well they are called "query params", and nobody confused. I don't know why you both are confused. @19majkel94 please revert Param decorator name. |
Frontend frameworks are not a good example, as there's no body param, cookie param, header param or session param, only "path and query"... and even this not always - react-router there's no query params parse. Should we also strip of query feature to be equal to other frameworks and libs? So there are only two solutions:
Naming inconsistency is very confusing, |
same I think about change in routing-controllers. RouteParam does not sound good. Also, why in angular2 you aren't saying about
You can't since at least
You missed third solution. Simply left as it is. I asked 3 my coworkers and they are prefer Param over RouteParam as well. |
I can't believe 😆 What is the same, redundancy? class ProductsController {
@Get("/products/:categoryId")
getProductsByCategory(
@RouteParam("categoryId") categoryId: number,
@QueryParam("limit") limit: number,
) {
// ...
}
}
Because you have only 2 (two, t-w-o) param sources, so it's not as confusing like here, where we have 6 and maybe more.
So maybe let the users decide? Will you allow them to vote or you know better what they want because you have huge experience and know better what is good and what is bad? |
actually only param and query param are very useful, others a bit specific and less common used. And yeah, even they use it they aren't confused because each of them has its own prefix.
okay lets do a democracy 😆 But we'll need enough people to vote (lets say at least 20-30 people). I'll buy as much people as I can to promote my idea 😈 . Make Naming is always subject of disputes, especially for me who is picky to naming things. |
+1 for |
yeah I know there are two votes on this already 😆 |
Ok, so how we should organize the voting? We should elaborate a mechanism that could be used also for koa support case or changes in middlewares support/api. |
I vote for |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This PR makes multiple changes:
@QueryParams()
and@Params()
missing decorators options (they are needed for validation purposes)ParamNormalizationError
, e.g. when number is expected but the invalid string (NaN) has been receivedclass-validator
Closes #234, fixes #160.
NOTE:
Due to potentially breaking changes (all tests green of course) it has to be released as major release (0.8.x). Should we create the release branch and make some git-flow on this repo?