fix(plugin): skip auto-generated response decorator when Api*Response already present#3803
Merged
kamilmysliwiec merged 1 commit intonestjs:masterfrom Apr 9, 2026
Conversation
… already present Closes nestjs#1639
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1639
Bug:
@ApiFoundResponse(and other@Api*Responsedecorators) were being ignored by the plugin, which always appended a defaultApiResponsedecorator with status 200/201, overriding the explicit response decorator.Root Cause:
addDecoratorToNodeincontroller-class.visitor.tsunconditionally appended an auto-generatedApiResponsedecorator regardless of whether the method already had an explicit@Api*Responsedecorator.Fix: Added a check — if any existing decorator name matches
ApiResponseexactly or matches theApi*Responsepattern, the auto-generated default is skipped entirely.Changes
lib/plugin/visitors/controller-class.visitor.ts: AddedhasExplicitApiResponseDecoratorcheck before creating the auto-generated response decorator; only appends it when no explicit@Api*Responseis present.test/plugin/fixtures/app.controller.ts: Updated existing snapshot fixture to reflect the corrected output.test/plugin/fixtures/app.controller-api-response.ts: New fixture with a method decorated with@ApiFoundResponseto serve as regression test input.test/plugin/controller-class-visitor.spec.ts: New regression test that verifies no extra200response is added when@ApiFoundResponseis already present.Testing
test/plugin/controller-class-visitor.spec.tsthat verifies no auto-generated 200 response is injected when@ApiFoundResponseis already present on a method.