-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
feature(core): allow Array in request mapping decorator #1385
feature(core): allow Array in request mapping decorator #1385
Conversation
Pull Request Test Coverage Report for Build 1330
💛 - Coveralls |
Pull Request Test Coverage Report for Build 1371
💛 - Coveralls |
); | ||
const paths = []; | ||
scannedPaths.forEach(p => { | ||
while (p.pathAlternatives.length) { |
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.
Cannot we add simple flattening logic (flatMap)? For example, using .reduce()
method with a pure function passed as a callback which returns flatten array?
Thanks @elyesbenabdelkader for your PR. I left a few comments 🙂 |
pathAlternatives = pathAlternatives.slice(1); | ||
} else { | ||
path = this.validateRoutePath(routePath); | ||
} |
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.
We should treat path
as an array by default - in the worst case, it would contain a single element. Hence, we wouldn't have to hold two variables (and consequently, pass them as parameters to another method).
@@ -23,6 +23,7 @@ import { RouterProxy, RouterProxyCallback } from './router-proxy'; | |||
|
|||
export interface RoutePathProperties { | |||
path: string; | |||
pathAlternatives: string[]; |
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.
Is it required? See below.
Treating path as an array would introduce a lot of changes all over the packages. That's why I tried to preserve the same RoutePathProperties structure and simply use pathAlternatives as a mean to do so. Hence when you call scanForPaths you get an array of RoutePathProperties where path is a string (the default expected behavior). |
I fully understand. However, I believe that it would be worth from the code quality perspective to merge these parameters anyway (even if it requires more code changes). |
This feature was requested in the issue nestjs#1343. When routing, besides using a single string, you can now use an array of strings in the Post, Get, ... decorators.
c7d06f7
to
ea700d8
Compare
LGTM. Thanks! |
This thread 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 feature was requested in the issue #1343. When routing, besides using a single string, you can
now use an array of strings in the Post, Get, ... decorators.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #1343
What is the new behavior?
When routing, besides using a single string, you can now use an array of strings in the Post, Get, ... decorators.
Does this PR introduce a breaking change?
Other information