Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

circular dependency has been detected with swagger plugin #2936

Closed
2 of 4 tasks
Nicolasvegam opened this issue Apr 30, 2024 · 5 comments
Closed
2 of 4 tasks

circular dependency has been detected with swagger plugin #2936

Nicolasvegam opened this issue Apr 30, 2024 · 5 comments

Comments

@Nicolasvegam
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

It throwed:

/Users/nicolasvega/Desktop/carvuk/carvuk-api-nest-js/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:184
            throw new Error(`A circular dependency has been detected (property key: "${key}"). Please, make sure that each side of a bidirectional relationships are using lazy resolvers ("type: () => ClassType").`);
                  ^
Error: A circular dependency has been detected (property key: "serviceCheckoutQuotes"). Please, make sure that each side of a bidirectional relationships are using lazy resolvers ("type: () => ClassType").
    at SchemaObjectFactory.createNotBuiltInTypeReference (/Users/nicolasvega/Desktop/carvuk/carvuk-api-nest-js/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:184:19)
    at SchemaObjectFactory.createSchemaMetadata (/Users/nicolasvega/Desktop/carvuk/carvuk-api-nest-js/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:294:25)
    at SchemaObjectFactory.mergePropertyWithMetadata (/Users/nicolasvega/Desktop/carvuk/carvuk-api-nest-js/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:131:21)
    at /Users/nicolasvega/Desktop/carvuk/carvuk-api-nest-js/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:82:35
    at Array.map (<anonymous>)
    at SchemaObjectFactory.extractPropertiesFromType (/Users/nicolasvega/Desktop/carvuk/carvuk-api-nest-js/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:81:52)
    at SchemaObjectFactory.exploreModelSchema (/Users/nicolasvega/Desktop/carvuk/carvuk-api-nest-js/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:103:41)
    at /Users/nicolasvega/Desktop/carvuk/carvuk-api-nest-js/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:36:36
    at Array.map (<anonymous>)
    at SchemaObjectFactory.createFromModel (/Users/nicolasvega/Desktop/carvuk/carvuk-api-nest-js/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:20:45)

The nest-cli

{
  "$schema": "https://json.schemastore.org/nest-cli",
  "collection": "@nestjs/schematics",
  "sourceRoot": "src",
  "compilerOptions": {
    "deleteOutDir": true,
    "plugins": ["@nestjs/swagger"]
  }
}

Minimum reproduction code

https://privaterepo.com

Steps to reproduce

No response

Expected behavior

Render the Swagger Docs

Package version

^7.3.1

NestJS version

^10.0.0

Node.js version

v21.7.2

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

yarn build is just fine.

@kamilmysliwiec
Copy link
Member

Please provide a minimum reproduction repository (Git repository/StackBlitz/CodeSandbox project).

@ausir0726
Copy link

ausir0726 commented May 23, 2024

@kamilmysliwiec
I also encountered the same issue when I was implementing the official example at https://docs.nestjs.com/openapi/operations#advanced-generic-apiresponse.
When using the cli-plugin and loading an example with @ApiExtraModel containing TData, it will cause a circular dependency.

The solution is to keep @ApiProperty() in the parameter of TData and not remove it.

I'm not sure if the original poster is facing the same issue, but I wanted to share my problem through this ISSUE.

here is minium reproduction
https://codesandbox.io/p/devbox/nifty-zhukovsky-k7ltzc

@LhonRafaat
Copy link

+1 one to this. I've used the swagger plugin + swc, I added my *dto.ts and *.type.ts files to dtoFileNameSuffix option. In couple of these files I have coordinates: [number, number]; which means two exactly have two elements inside the array, however Nestjs throws a circular dependency error with this format A circular dependency has been detected (property key: "coordinates").. using number[] insterad fixes it, but I do not want to have array of numbers, but exactly TWO elements which represent coordinates.

@LhonRafaat
Copy link

@kamilmysliwiec
Copy link
Member

#2849

@nestjs nestjs locked and limited conversation to collaborators Oct 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants