Skip to content
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(core): middleware does not apply to a controller that has versioning #10835

Closed
wants to merge 2 commits into from

Conversation

pnkp
Copy link

@pnkp pnkp commented Jan 9, 2023

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

Issue Number: 10847
However, the middleware didn't apply to controllers which contain versioning at the class level (version property inside @Controller decorator)

What is the new behavior?

Passing a controller that has class-level versioning or global versioning is enough to apply middleware on it.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@pnkp pnkp force-pushed the fix/controller_middleware_versioning branch from 4516157 to 5fc41a9 Compare January 11, 2023 11:22
@pnkp pnkp force-pushed the fix/controller_middleware_versioning branch 3 times, most recently from 76cc416 to 6670ba2 Compare February 1, 2023 10:31
@pnkp pnkp changed the title fix(core): middleware doesn't work with global and controller version fix(core): middleware does not apply to a controller that has versioning Feb 1, 2023
@pnkp pnkp force-pushed the fix/controller_middleware_versioning branch from 6670ba2 to 01b014b Compare February 1, 2023 10:43
@pnkp pnkp marked this pull request as ready for review February 1, 2023 10:44
@kamilmysliwiec
Copy link
Member

Can we add an integration test that confirms that this PR solves the issue?

@pnkp pnkp force-pushed the fix/controller_middleware_versioning branch from 01b014b to de41804 Compare February 1, 2023 15:35
@pnkp pnkp force-pushed the fix/controller_middleware_versioning branch from de41804 to 682db93 Compare February 1, 2023 17:48
@pnkp
Copy link
Author

pnkp commented Feb 1, 2023

Can we add an integration test that confirms that this PR solves the issue?

Done

@coveralls
Copy link

Pull Request Test Coverage Report for Build bd211e24-0917-494a-a6f1-e5fdf684b84f

  • 7 of 7 (100.0%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.003%) to 92.989%

Totals Coverage Status
Change from base Build a491a671-3dc9-4afe-b7e0-675925f5f9aa: 0.003%
Covered Lines: 6380
Relevant Lines: 6861

💛 - Coveralls

return {
path,
requestMethod,
targetCallback: instanceCallback,
methodName,
version,
version: methodVersion || controllerVersion || globalVersion,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIR this may cause some unexpected side-effects.

RouterExplorer#applyPathsToRouterProxy assumes that "version" attribute represents the method-level version https://github.com/nestjs/nest/pull/10835/files#diff-652791ce58d92c15826b2be408ac4b6b0b1c7269664536c3d2e89b9e6f49699fR144 while now it equals to "method"/"controller"/"global"-level.

Ideally, to avoid regressions, we should make sure not to update the "scanForPaths" method (leave it as is) :(

@kamilmysliwiec
Copy link
Member

#11785

@frankdavidcorona
Copy link

Hi contributors,

Currently, I'm facing this issue in my application, I'm currently running with these packages versions:

"@nestjs/common": "9.4.3",
"@nestjs/core": "9.4.3",

The solution has been published to any latest version of NestJS?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants