Skip to content

fix(plugin): skip auto-generated response decorator when Api*Response already present#3803

Merged
kamilmysliwiec merged 1 commit intonestjs:masterfrom
maruthang:fix/issue-1639-api-found-response-200
Apr 9, 2026
Merged

fix(plugin): skip auto-generated response decorator when Api*Response already present#3803
kamilmysliwiec merged 1 commit intonestjs:masterfrom
maruthang:fix/issue-1639-api-found-response-200

Conversation

@maruthang
Copy link
Copy Markdown
Contributor

Summary

Fixes #1639

Bug: @ApiFoundResponse (and other @Api*Response decorators) were being ignored by the plugin, which always appended a default ApiResponse decorator with status 200/201, overriding the explicit response decorator.

Root Cause: addDecoratorToNode in controller-class.visitor.ts unconditionally appended an auto-generated ApiResponse decorator regardless of whether the method already had an explicit @Api*Response decorator.

Fix: Added a check — if any existing decorator name matches ApiResponse exactly or matches the Api*Response pattern, the auto-generated default is skipped entirely.

Changes

  • lib/plugin/visitors/controller-class.visitor.ts: Added hasExplicitApiResponseDecorator check before creating the auto-generated response decorator; only appends it when no explicit @Api*Response is 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 @ApiFoundResponse to serve as regression test input.
  • test/plugin/controller-class-visitor.spec.ts: New regression test that verifies no extra 200 response is added when @ApiFoundResponse is already present.

Testing

  • Added regression test in test/plugin/controller-class-visitor.spec.ts that verifies no auto-generated 200 response is injected when @ApiFoundResponse is already present on a method.
  • All existing tests pass (159 passing).

@kamilmysliwiec kamilmysliwiec merged commit 1f7fc4f into nestjs:master Apr 9, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding @ApiFoundResponse on a dynamic redirect method still renders a 200 response code in the OpenAPI contract

2 participants