Skip to content

fix(core): discover classes by each of their discovery decorators - #18235

Merged
kamilmysliwiec merged 1 commit into
nestjs:masterfrom
OmBhandwaldar:fix/discovery-multiple-decorators
Oct 22, 2026
Merged

kamilmysliwiec merged 1 commit into
nestjs:masterfrom
OmBhandwaldar:fix/discovery-multiple-decorators

Conversation

@OmBhandwaldar

Copy link
Copy Markdown
Contributor

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: N/A

DiscoverableMetaHostCollection links each class to a single metadata key (discoverable-meta-host-collection.ts#L38). When a class has two decorators created with DiscoveryService.createDecorator(), the one applied last replaces the other, and getProviders({ metadataKey }) and getControllers({ metadataKey }) don't return the class for the other decorator. getMetadataByDecorator() still finds its metadata.

With the repro on 12.2.0:

ScheduledJob providers: ["CleanupService"], controllers: ["AdminController"]
Audited      providers: ["ReportService"], controllers: []

Same on 10.4.15 and 11.1.6.

What is the new behavior?

A class keeps every key and is registered under each of them. With the repro, both decorators return ["CleanupService","ReportService"] and ["AdminController"].

Tests: the unit test that expected the second key to replace the first now expects both keys. New tests for inspectProvider() and in discovery-service.spec.ts (class, factory, value and alias providers, and a controller) fail without the change.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

DiscoverableMetaHostCollection.metaHostLinks now maps a class to a Set of keys instead of a single key.

A class with two decorators created by DiscoveryService.createDecorator()
was only discovered by the one applied last. Keep every key per class.
@kamilmysliwiec
kamilmysliwiec merged commit e065e23 into nestjs:master Oct 22, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants