Skip to content

fix(plugin): preserve inferred responses for enum error statuses - #4014

Merged
kamilmysliwiec merged 1 commit into
nestjs:masterfrom
GiHoon1123:fix-4009-enum-api-response
Jul 17, 2026
Merged

fix(plugin): preserve inferred responses for enum error statuses#4014
kamilmysliwiec merged 1 commit into
nestjs:masterfrom
GiHoon1123:fix-4009-enum-api-response

Conversation

@GiHoon1123

Copy link
Copy Markdown
Contributor

Fixes #4009

Problem

When @ApiResponse uses an enum status such as HttpStatus.BAD_REQUEST, the Swagger plugin does not resolve the enum value and treats it as a success response.

As a result, the automatically generated 200 response is omitted.

Fix

Pass the TypeScript TypeChecker to the status check and resolve enum members with getConstantValue().

This preserves the existing behavior for numeric statuses and ensures that:

  • enum error statuses keep the inferred success response
  • enum success statuses suppress the inferred success response

Tests

Added regression coverage for:

  • HttpStatus.BAD_REQUEST with an inferred 200 response
  • HttpStatus.CREATED suppressing the inferred 200 response

Verified with:

  • pnpm test
  • pnpm run build
  • pnpm run lint

@kamilmysliwiec
kamilmysliwiec merged commit eb80e4e into nestjs:master Jul 17, 2026
1 check passed
@kamilmysliwiec

Copy link
Copy Markdown
Member

lgtm

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.

enum-based @ApiResponse status prevents automatic success response generation

2 participants