-
Notifications
You must be signed in to change notification settings - Fork 534
swagger plugin cause circular dependency when having a field of optional and nullable enum #3519
Copy link
Copy link
Closed
Labels
Description
Is there an existing issue for this?
- I have searched the existing issues
Current behavior
When using @nestjs/swagger plugin to create a DTO, if the field is an optional nullable enum, the error [below] occurs
Error: A circular dependency has been detected (property key: "status"). Please, make sure that each side of a bidirectional relationships are using lazy resolvers ("type: () => ClassType").
From the repo, we see that statusOne and statusTwo works perfectly fine. But if we introduce statusThree, the one with optional and nullable, it cause the swagger to crash (circular dependency error)
export class CreateTaskDto {
statusOne?: Status;
statusTwo: Status | null;
statusThree?: Status | null; // This cause circular dependency error when opening http://localhost:3000/api (swagger)
@ApiProperty({ enum: Status, nullable: true })
statusFour?: Status | null; // This works because @ApiProperty will override the swagger plugin
}Minimum reproduction code
https://github.com/boompikachu/nestjs-swagger-plugin-repro
Steps to reproduce
pnpm installpnpm start:dev- open http://localhost:3000/api
comment out the statusThree?: Status | null to fix the error
Expected behavior
To not cause circular dependency
Package version
11.2.0
NestJS version
11.1.4
Node.js version
24
In which operating systems have you tested?
- macOS
- Windows
- Linux
Other
in
| export class NullableDto { |
Reactions are currently unavailable