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" error when using object properties #1442

Closed
mamacdon-surveymonkey opened this issue Jul 12, 2021 · 1 comment
Closed

Comments

@mamacdon-surveymonkey
Copy link

I'm submitting a...

Seems to be a regression of issue #502. Works in 4.8.2, fails in 5.0.0


[x] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Nest crashes with this error:

(node:9740) UnhandledPromiseRejectionWarning: Error: A circular dependency has been detected (property key: "is_migrated"). Please, make sure that each side of a bidirectional relationships are using lazy resolvers ("type: () => ClassType").
    at SchemaObjectFactory.createNotBuiltInTypeReference (/Users/mmacdonald/Desktop/repro/myapp/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:204:19)
    at SchemaObjectFactory.mergePropertyWithMetadata (/Users/mmacdonald/Desktop/repro/myapp/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:141:25)
    at /Users/mmacdonald/Desktop/repro/myapp/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:270:43
    at Array.forEach (<anonymous>)
    at SchemaObjectFactory.createFromObjectLiteral (/Users/mmacdonald/Desktop/repro/myapp/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:254:24)
    at SchemaObjectFactory.mergePropertyWithMetadata (/Users/mmacdonald/Desktop/repro/myapp/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:120:25)
    at /Users/mmacdonald/Desktop/repro/myapp/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:79:35
    at Array.map (<anonymous>)
    at SchemaObjectFactory.extractPropertiesFromType (/Users/mmacdonald/Desktop/repro/myapp/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:78:52)
    at SchemaObjectFactory.exploreModelSchema (/Users/mmacdonald/Desktop/repro/myapp/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:92:41)

If I downgrade to @nestjs/swagger@^4.8.2, the error goes away and Swagger works again.

Expected behavior

Expected it to work as it did in v4.8.2

Minimal reproduction of the problem with instructions

Repo is here, the important files are the DTO:

// user.dto.ts

export class UserDto {
  readonly user_id: string;

  readonly metadata: {
    readonly is_migrated: boolean;
  };
}

and the controller:

// users.controller.ts
@Controller()
@ApiTags('users')
export class UsersController {
  constructor(private readonly service: UserService) {}

  @Get()
  @HttpCode(200)
  async getUser(): Promise<UserDto> {
    return this.service.getUser();
  }
}

What is the motivation / use case for changing the behavior?

Allow object properties to work in DTO classes again.

Environment


[Nest Platform Information]
platform-express version : 8.0.0
swagger version          : 5.0.0
common version           : 8.0.0
core version             : 8.0.0

[System Information]
OS Version     : macOS Catalina
NodeJS Version : v14.15.3
NPM Version    : 6.14.5 

[Nest CLI]
Nest CLI Version : 8.0.2 
@kamilmysliwiec
Copy link
Member

Thanks for reporting! Fixed in 5.0.1

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

No branches or pull requests

2 participants