Circular dependency with generated swagger metadata
Is there an existing issue for this?
- [X] I have searched the existing issues
Current behavior
Hi,
I'm trying to use the generate metadata function of the cli and getting an error when using an object type. There seems to be several historical issues showing the same thing:
https://github.com/nestjs/swagger/issues/1442 https://github.com/nestjs/swagger/issues/502
The metadata generates fine, however when starting the app I get:
A circular dependency has been detected (property key: \"auditLogs\"). Please, make sure that each side of a bidirectional relationships are using lazy resolvers (\"type: () => ClassType\").","stack":"Error: A circular dependency has been detected (property key: \"auditLogs\"). Please, make sure that each side of a bidirectional relationships are using lazy resolvers (\"type: () => ClassType\").
This is my super simple dto:
export abstract class GetUserAuditLogResponse {
public abstract user: string
public abstract clusters: string[]
public abstract auditLogs: { username: string }[]
}
Minimum reproduction code
Example in comments above
Steps to reproduce
No response
Expected behavior
It to handle the array of objects
Package version
7.3.0
NestJS version
10.3.3
Node.js version
20
In which operating systems have you tested?
- [X] macOS
- [ ] Windows
- [ ] Linux
Other
No response
This could be user error, as i'm new to this... but moving { username: string } into it's own class def "fixes" it, eg:
export abstract class AuditLogItem {
public abstract username: string
}
export abstract class GetUserAuditLogResponse {
public abstract user: string
public abstract clusters: string[]
public abstract auditLogs: AuditLogItem[]
}
Was experiencing the same thing on another project. After a lot of trial and error I found that my typeorm package had been updated to 0.3.20, on a hunch I rolled it back to the previous version we were using (0.3.17) which worked. I then worked my way back up and was able to install 0.3.19 without this issue, but as soon as I installed 0.3.20 it failed.
Did a little more searching and eventually found that it seems this has been logged against typeorm here https://github.com/typeorm/typeorm/issues/10671
Not sure if it's the same issue or different, but adding in my meanderings anyways.
Was experiencing the same thing on another project. After a lot of trial and error I found that my
typeormpackage had been updated to0.3.20, on a hunch I rolled it back to the previous version we were using (0.3.17) which worked. I then worked my way back up and was able to install0.3.19without this issue, but as soon as I installed 0.3.20 it failed.Did a little more searching and eventually found that it seems this has been logged against typeorm here typeorm/typeorm#10671
Not sure if it's the same issue or different, but adding in my meanderings anyways.
The same to me, Rollbacked typeORM to 0.3.19. it works fine
Possible duplicate of https://github.com/nestjs/swagger/issues/2811
I can confirm that hard-coding typeORM to 0.3.19 fixes the issue.