swagger icon indicating copy to clipboard operation
swagger copied to clipboard

Circular dependency with generated swagger metadata

Open Stono opened this issue 1 year ago • 5 comments

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

Stono avatar Feb 19 '24 19:02 Stono

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[]
}

Stono avatar Feb 19 '24 19:02 Stono

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.

cjam avatar Feb 29 '24 14:02 cjam

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 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

lacuong2009 avatar Mar 06 '24 08:03 lacuong2009

Possible duplicate of https://github.com/nestjs/swagger/issues/2811

OSA413 avatar Mar 15 '24 09:03 OSA413

I can confirm that hard-coding typeORM to 0.3.19 fixes the issue.

Gavin152 avatar Mar 26 '24 09:03 Gavin152