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

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

circular dependency has been detected with swagger plugin #2936

Nicolasvegam opened this issue Apr 30, 2024 · 2 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants